@Test public void nextUp2() { TimeScales.TimePeriod nextUp = TimeScales.nextUp(new TimePeriod(SECOND, 2)); assertThat(nextUp, equalTo(new TimePeriod(SECOND, 5))); }
static TimePeriod nextUp(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.MILLISECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount < 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount < 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount < 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount < 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount < 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } return new TimePeriod(GregorianCalendar.SECOND, 1); case GregorianCalendar.SECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount < 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount < 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } return new TimePeriod(GregorianCalendar.MINUTE, 1); case GregorianCalendar.MINUTE: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MINUTE , 2 ); } if ( period.amount < 5 ) { return new TimePeriod( GregorianCalendar.MINUTE , 5 ); } if ( period.amount < 10 ) { return new TimePeriod( GregorianCalendar.MINUTE , 10 ); } if ( period.amount < 15 ) { return new TimePeriod( GregorianCalendar.MINUTE , 15 ); } if ( period.amount < 30 ) { return new TimePeriod( GregorianCalendar.MINUTE , 30 ); } return new TimePeriod( HOUR_FIELD_ID, 1 ); case HOUR_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount < 3 ) { return new TimePeriod( HOUR_FIELD_ID , 3 ); } if ( period.amount < 6 ) { return new TimePeriod( HOUR_FIELD_ID , 6 ); } if ( period.amount < 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount < 24 ) { return new TimePeriod( HOUR_FIELD_ID , 24 ); } return new TimePeriod( DAY_FIELD_ID , 1 ); case DAY_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( DAY_FIELD_ID , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( DAY_FIELD_ID , 4 ); } return new TimePeriod( WEEK_FIELD_ID , 1 ); case WEEK_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } return new TimePeriod( GregorianCalendar.MONTH , 1 ); case GregorianCalendar.MONTH: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount < 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } return new TimePeriod( GregorianCalendar.YEAR , 1 ); case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); } return null; }
TimeScales { static TimePeriod nextUp(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.MILLISECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount < 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount < 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount < 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount < 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount < 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } return new TimePeriod(GregorianCalendar.SECOND, 1); case GregorianCalendar.SECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount < 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount < 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } return new TimePeriod(GregorianCalendar.MINUTE, 1); case GregorianCalendar.MINUTE: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MINUTE , 2 ); } if ( period.amount < 5 ) { return new TimePeriod( GregorianCalendar.MINUTE , 5 ); } if ( period.amount < 10 ) { return new TimePeriod( GregorianCalendar.MINUTE , 10 ); } if ( period.amount < 15 ) { return new TimePeriod( GregorianCalendar.MINUTE , 15 ); } if ( period.amount < 30 ) { return new TimePeriod( GregorianCalendar.MINUTE , 30 ); } return new TimePeriod( HOUR_FIELD_ID, 1 ); case HOUR_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount < 3 ) { return new TimePeriod( HOUR_FIELD_ID , 3 ); } if ( period.amount < 6 ) { return new TimePeriod( HOUR_FIELD_ID , 6 ); } if ( period.amount < 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount < 24 ) { return new TimePeriod( HOUR_FIELD_ID , 24 ); } return new TimePeriod( DAY_FIELD_ID , 1 ); case DAY_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( DAY_FIELD_ID , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( DAY_FIELD_ID , 4 ); } return new TimePeriod( WEEK_FIELD_ID , 1 ); case WEEK_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } return new TimePeriod( GregorianCalendar.MONTH , 1 ); case GregorianCalendar.MONTH: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount < 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } return new TimePeriod( GregorianCalendar.YEAR , 1 ); case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); } return null; } }
TimeScales { static TimePeriod nextUp(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.MILLISECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount < 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount < 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount < 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount < 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount < 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } return new TimePeriod(GregorianCalendar.SECOND, 1); case GregorianCalendar.SECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount < 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount < 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } return new TimePeriod(GregorianCalendar.MINUTE, 1); case GregorianCalendar.MINUTE: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MINUTE , 2 ); } if ( period.amount < 5 ) { return new TimePeriod( GregorianCalendar.MINUTE , 5 ); } if ( period.amount < 10 ) { return new TimePeriod( GregorianCalendar.MINUTE , 10 ); } if ( period.amount < 15 ) { return new TimePeriod( GregorianCalendar.MINUTE , 15 ); } if ( period.amount < 30 ) { return new TimePeriod( GregorianCalendar.MINUTE , 30 ); } return new TimePeriod( HOUR_FIELD_ID, 1 ); case HOUR_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount < 3 ) { return new TimePeriod( HOUR_FIELD_ID , 3 ); } if ( period.amount < 6 ) { return new TimePeriod( HOUR_FIELD_ID , 6 ); } if ( period.amount < 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount < 24 ) { return new TimePeriod( HOUR_FIELD_ID , 24 ); } return new TimePeriod( DAY_FIELD_ID , 1 ); case DAY_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( DAY_FIELD_ID , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( DAY_FIELD_ID , 4 ); } return new TimePeriod( WEEK_FIELD_ID , 1 ); case WEEK_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } return new TimePeriod( GregorianCalendar.MONTH , 1 ); case GregorianCalendar.MONTH: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount < 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } return new TimePeriod( GregorianCalendar.YEAR , 1 ); case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); } return null; }  }
TimeScales { static TimePeriod nextUp(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.MILLISECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount < 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount < 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount < 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount < 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount < 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } return new TimePeriod(GregorianCalendar.SECOND, 1); case GregorianCalendar.SECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount < 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount < 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } return new TimePeriod(GregorianCalendar.MINUTE, 1); case GregorianCalendar.MINUTE: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MINUTE , 2 ); } if ( period.amount < 5 ) { return new TimePeriod( GregorianCalendar.MINUTE , 5 ); } if ( period.amount < 10 ) { return new TimePeriod( GregorianCalendar.MINUTE , 10 ); } if ( period.amount < 15 ) { return new TimePeriod( GregorianCalendar.MINUTE , 15 ); } if ( period.amount < 30 ) { return new TimePeriod( GregorianCalendar.MINUTE , 30 ); } return new TimePeriod( HOUR_FIELD_ID, 1 ); case HOUR_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount < 3 ) { return new TimePeriod( HOUR_FIELD_ID , 3 ); } if ( period.amount < 6 ) { return new TimePeriod( HOUR_FIELD_ID , 6 ); } if ( period.amount < 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount < 24 ) { return new TimePeriod( HOUR_FIELD_ID , 24 ); } return new TimePeriod( DAY_FIELD_ID , 1 ); case DAY_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( DAY_FIELD_ID , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( DAY_FIELD_ID , 4 ); } return new TimePeriod( WEEK_FIELD_ID , 1 ); case WEEK_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } return new TimePeriod( GregorianCalendar.MONTH , 1 ); case GregorianCalendar.MONTH: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount < 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } return new TimePeriod( GregorianCalendar.YEAR , 1 ); case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); } return null; }  static TimeScale linearAbsoluteScale(); }
TimeScales { static TimePeriod nextUp(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.MILLISECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount < 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount < 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount < 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount < 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount < 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } return new TimePeriod(GregorianCalendar.SECOND, 1); case GregorianCalendar.SECOND: if (period.amount < 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount < 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount < 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount < 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount < 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } return new TimePeriod(GregorianCalendar.MINUTE, 1); case GregorianCalendar.MINUTE: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MINUTE , 2 ); } if ( period.amount < 5 ) { return new TimePeriod( GregorianCalendar.MINUTE , 5 ); } if ( period.amount < 10 ) { return new TimePeriod( GregorianCalendar.MINUTE , 10 ); } if ( period.amount < 15 ) { return new TimePeriod( GregorianCalendar.MINUTE , 15 ); } if ( period.amount < 30 ) { return new TimePeriod( GregorianCalendar.MINUTE , 30 ); } return new TimePeriod( HOUR_FIELD_ID, 1 ); case HOUR_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount < 3 ) { return new TimePeriod( HOUR_FIELD_ID , 3 ); } if ( period.amount < 6 ) { return new TimePeriod( HOUR_FIELD_ID , 6 ); } if ( period.amount < 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount < 24 ) { return new TimePeriod( HOUR_FIELD_ID , 24 ); } return new TimePeriod( DAY_FIELD_ID , 1 ); case DAY_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( DAY_FIELD_ID , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( DAY_FIELD_ID , 4 ); } return new TimePeriod( WEEK_FIELD_ID , 1 ); case WEEK_FIELD_ID: if ( period.amount < 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } return new TimePeriod( GregorianCalendar.MONTH , 1 ); case GregorianCalendar.MONTH: if ( period.amount < 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount < 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount < 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } return new TimePeriod( GregorianCalendar.YEAR , 1 ); case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); } return null; }  static TimeScale linearAbsoluteScale(); final static int HOUR_FIELD_ID; final static int FIRST_HOUR; final static int DAY_FIELD_ID; final static int FIRST_DAY; final static int WEEK_FIELD_ID; final static int FIRST_WEEK; }