@Test public void nextDown3() { TimeScales.TimePeriod period = TimeScales.nextDown(new TimePeriod(SECOND, 5)); assertThat(period, equalTo(new TimePeriod(SECOND, 2))); }
static TimePeriod nextDown(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); case GregorianCalendar.MONTH: if ( period.amount > 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( GregorianCalendar.MONTH , 1 ); } return new TimePeriod( WEEK_FIELD_ID , 2 ); case WEEK_FIELD_ID: if ( period.amount > 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( WEEK_FIELD_ID , 1 ); } return new TimePeriod( DAY_FIELD_ID , 3 ); case DAY_FIELD_ID: if ( period.amount > 3 ) { return new TimePeriod( DAY_FIELD_ID , 3 ); } if ( period.amount > 1 ) { return new TimePeriod( DAY_FIELD_ID , 1 ); } return new TimePeriod( HOUR_FIELD_ID , 12 ); case HOUR_FIELD_ID: if ( period.amount > 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount > 8 ) { return new TimePeriod( HOUR_FIELD_ID , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( HOUR_FIELD_ID , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( HOUR_FIELD_ID , 1 ); } return new TimePeriod( GregorianCalendar.MINUTE , 30 ); case GregorianCalendar.MINUTE: return new TimePeriod(GregorianCalendar.SECOND, 30); case GregorianCalendar.SECOND: if (period.amount > 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } if (period.amount > 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.SECOND, 1); } return new TimePeriod(GregorianCalendar.MILLISECOND, 500); case GregorianCalendar.MILLISECOND: if (period.amount > 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } if (period.amount > 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount > 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount > 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount > 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.MILLISECOND, 1); } } return new TimePeriod( GregorianCalendar.MILLISECOND , 1 ); }
TimeScales { static TimePeriod nextDown(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); case GregorianCalendar.MONTH: if ( period.amount > 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( GregorianCalendar.MONTH , 1 ); } return new TimePeriod( WEEK_FIELD_ID , 2 ); case WEEK_FIELD_ID: if ( period.amount > 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( WEEK_FIELD_ID , 1 ); } return new TimePeriod( DAY_FIELD_ID , 3 ); case DAY_FIELD_ID: if ( period.amount > 3 ) { return new TimePeriod( DAY_FIELD_ID , 3 ); } if ( period.amount > 1 ) { return new TimePeriod( DAY_FIELD_ID , 1 ); } return new TimePeriod( HOUR_FIELD_ID , 12 ); case HOUR_FIELD_ID: if ( period.amount > 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount > 8 ) { return new TimePeriod( HOUR_FIELD_ID , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( HOUR_FIELD_ID , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( HOUR_FIELD_ID , 1 ); } return new TimePeriod( GregorianCalendar.MINUTE , 30 ); case GregorianCalendar.MINUTE: return new TimePeriod(GregorianCalendar.SECOND, 30); case GregorianCalendar.SECOND: if (period.amount > 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } if (period.amount > 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.SECOND, 1); } return new TimePeriod(GregorianCalendar.MILLISECOND, 500); case GregorianCalendar.MILLISECOND: if (period.amount > 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } if (period.amount > 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount > 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount > 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount > 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.MILLISECOND, 1); } } return new TimePeriod( GregorianCalendar.MILLISECOND , 1 ); } }
TimeScales { static TimePeriod nextDown(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); case GregorianCalendar.MONTH: if ( period.amount > 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( GregorianCalendar.MONTH , 1 ); } return new TimePeriod( WEEK_FIELD_ID , 2 ); case WEEK_FIELD_ID: if ( period.amount > 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( WEEK_FIELD_ID , 1 ); } return new TimePeriod( DAY_FIELD_ID , 3 ); case DAY_FIELD_ID: if ( period.amount > 3 ) { return new TimePeriod( DAY_FIELD_ID , 3 ); } if ( period.amount > 1 ) { return new TimePeriod( DAY_FIELD_ID , 1 ); } return new TimePeriod( HOUR_FIELD_ID , 12 ); case HOUR_FIELD_ID: if ( period.amount > 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount > 8 ) { return new TimePeriod( HOUR_FIELD_ID , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( HOUR_FIELD_ID , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( HOUR_FIELD_ID , 1 ); } return new TimePeriod( GregorianCalendar.MINUTE , 30 ); case GregorianCalendar.MINUTE: return new TimePeriod(GregorianCalendar.SECOND, 30); case GregorianCalendar.SECOND: if (period.amount > 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } if (period.amount > 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.SECOND, 1); } return new TimePeriod(GregorianCalendar.MILLISECOND, 500); case GregorianCalendar.MILLISECOND: if (period.amount > 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } if (period.amount > 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount > 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount > 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount > 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.MILLISECOND, 1); } } return new TimePeriod( GregorianCalendar.MILLISECOND , 1 ); }  }
TimeScales { static TimePeriod nextDown(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); case GregorianCalendar.MONTH: if ( period.amount > 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( GregorianCalendar.MONTH , 1 ); } return new TimePeriod( WEEK_FIELD_ID , 2 ); case WEEK_FIELD_ID: if ( period.amount > 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( WEEK_FIELD_ID , 1 ); } return new TimePeriod( DAY_FIELD_ID , 3 ); case DAY_FIELD_ID: if ( period.amount > 3 ) { return new TimePeriod( DAY_FIELD_ID , 3 ); } if ( period.amount > 1 ) { return new TimePeriod( DAY_FIELD_ID , 1 ); } return new TimePeriod( HOUR_FIELD_ID , 12 ); case HOUR_FIELD_ID: if ( period.amount > 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount > 8 ) { return new TimePeriod( HOUR_FIELD_ID , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( HOUR_FIELD_ID , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( HOUR_FIELD_ID , 1 ); } return new TimePeriod( GregorianCalendar.MINUTE , 30 ); case GregorianCalendar.MINUTE: return new TimePeriod(GregorianCalendar.SECOND, 30); case GregorianCalendar.SECOND: if (period.amount > 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } if (period.amount > 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.SECOND, 1); } return new TimePeriod(GregorianCalendar.MILLISECOND, 500); case GregorianCalendar.MILLISECOND: if (period.amount > 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } if (period.amount > 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount > 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount > 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount > 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.MILLISECOND, 1); } } return new TimePeriod( GregorianCalendar.MILLISECOND , 1 ); }  static TimeScale linearAbsoluteScale(); }
TimeScales { static TimePeriod nextDown(TimePeriod period) { switch(period.fieldId) { case GregorianCalendar.YEAR: return new TimePeriod( GregorianCalendar.YEAR , period.amount/4+1 ); case GregorianCalendar.MONTH: if ( period.amount > 8 ) { return new TimePeriod( GregorianCalendar.MONTH , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( GregorianCalendar.MONTH , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( GregorianCalendar.MONTH , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( GregorianCalendar.MONTH , 1 ); } return new TimePeriod( WEEK_FIELD_ID , 2 ); case WEEK_FIELD_ID: if ( period.amount > 2 ) { return new TimePeriod( WEEK_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( WEEK_FIELD_ID , 1 ); } return new TimePeriod( DAY_FIELD_ID , 3 ); case DAY_FIELD_ID: if ( period.amount > 3 ) { return new TimePeriod( DAY_FIELD_ID , 3 ); } if ( period.amount > 1 ) { return new TimePeriod( DAY_FIELD_ID , 1 ); } return new TimePeriod( HOUR_FIELD_ID , 12 ); case HOUR_FIELD_ID: if ( period.amount > 12 ) { return new TimePeriod( HOUR_FIELD_ID , 12 ); } if ( period.amount > 8 ) { return new TimePeriod( HOUR_FIELD_ID , 8 ); } if ( period.amount > 4 ) { return new TimePeriod( HOUR_FIELD_ID , 4 ); } if ( period.amount > 2 ) { return new TimePeriod( HOUR_FIELD_ID , 2 ); } if ( period.amount > 1 ) { return new TimePeriod( HOUR_FIELD_ID , 1 ); } return new TimePeriod( GregorianCalendar.MINUTE , 30 ); case GregorianCalendar.MINUTE: return new TimePeriod(GregorianCalendar.SECOND, 30); case GregorianCalendar.SECOND: if (period.amount > 30) { return new TimePeriod(GregorianCalendar.SECOND, 30); } if (period.amount > 15) { return new TimePeriod(GregorianCalendar.SECOND, 15); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.SECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.SECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.SECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.SECOND, 1); } return new TimePeriod(GregorianCalendar.MILLISECOND, 500); case GregorianCalendar.MILLISECOND: if (period.amount > 500) { return new TimePeriod(GregorianCalendar.MILLISECOND, 500); } if (period.amount > 200) { return new TimePeriod(GregorianCalendar.MILLISECOND, 200); } if (period.amount > 100) { return new TimePeriod(GregorianCalendar.MILLISECOND, 100); } if (period.amount > 50) { return new TimePeriod(GregorianCalendar.MILLISECOND, 50); } if (period.amount > 20) { return new TimePeriod(GregorianCalendar.MILLISECOND, 20); } if (period.amount > 10) { return new TimePeriod(GregorianCalendar.MILLISECOND, 10); } if (period.amount > 5) { return new TimePeriod(GregorianCalendar.MILLISECOND, 5); } if (period.amount > 2) { return new TimePeriod(GregorianCalendar.MILLISECOND, 2); } if (period.amount > 1) { return new TimePeriod(GregorianCalendar.MILLISECOND, 1); } } return new TimePeriod( GregorianCalendar.MILLISECOND , 1 ); }  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; }