PeriodType implements Serializable { public static PeriodType getByIndex( int index ) { index -= 1; if ( index < 0 || index > PERIOD_TYPES.size() - 1 ) { return null; } return PERIOD_TYPES.get( index ); }  static void invalidatePeriodCache(); static void setCalendarService( CalendarService calendarService ); static CalendarService getCalendarService(); static org.hisp.dhis.calendar.Calendar getCalendar(); static List<PeriodType> getAvailablePeriodTypes(); static PeriodType getPeriodTypeByName( String name ); static PeriodType getByNameIgnoreCase( String name ); static PeriodType getByIndex( int index ); static List<Period> getPeriodTypePeriods( Period period, org.hisp.dhis.calendar.Calendar calendar ); void setId( int id ); int getId(); abstract String getName(); Period createPeriod(); Period createPeriod( final Date date ); Period createPeriod( Calendar cal ); Period createPeriod( final Date date, final org.hisp.dhis.calendar.Calendar calendar ); Period toIsoPeriod( DateTimeUnit start, DateTimeUnit end ); Period toIsoPeriod( DateTimeUnit dateTimeUnit ); abstract String getIso8601Duration(); abstract Period createPeriod( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar ); abstract int getFrequencyOrder(); abstract String getSqlInterval(); abstract Date getRewindedDate( Date date, Integer rewindedPeriods ); static Calendar createCalendarInstance(); static Calendar createCalendarInstance( Date date ); static DateTimeUnit createLocalDateUnitInstance( Date date ); static DateTimeUnit createLocalDateUnitInstance( Date date, org.hisp.dhis.calendar.Calendar calendar ); static void clearTimeOfDay( Calendar calendar ); static PeriodType getPeriodTypeFromIsoString( String isoPeriod ); static Period getPeriodFromIsoString( String isoPeriod ); static List<Period> getPeriodsFromIsoStrings( List<String> isoPeriods ); int getPeriodSpan( PeriodType type ); Period createPeriod( DateInterval dateInterval ); String getIsoDate( Period period ); String getIsoDate( DateTimeUnit dateTimeUnit ); abstract String getIsoDate( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar ); Period createPeriod( String isoDate ); abstract String getIsoFormat(); final Period getNextPeriod( Period period ); Period getNextPeriod( Period period, int periods ); Period getNextPeriod( Period period, org.hisp.dhis.calendar.Calendar calendar ); final Period getPreviousPeriod( Period period ); Period getPreviousPeriod( Period period, int periods ); Period getPreviousPeriod( Period period, org.hisp.dhis.calendar.Calendar calendar ); Period getPreviousYearsPeriod( Period period, int yearCount ); Date getDateWithOffset( Date date, int offset ); boolean spansMultipleCalendarYears(); boolean equalsName( String periodTypeName ); @Override int hashCode(); @Override boolean equals( Object o ); @Override String toString(); static final List<PeriodType> PERIOD_TYPES; static final Map<String, DayOfWeek> MAP_WEEK_TYPE; }
@Test public void testGetByIndex() { assertNull( PeriodType.getByIndex( -1 ) ); PeriodType yearly = PeriodType.getByNameIgnoreCase( "Yearly" ); assertNotNull( yearly ); int yearlyIndex = PeriodType.getAvailablePeriodTypes().indexOf( yearly ) + 1; assertEquals( new YearlyPeriodType(), PeriodType.getByIndex( yearlyIndex ) ); assertNull( PeriodType.getByIndex( 999 ) ); }