YearlyPeriodType extends CalendarPeriodType { @Override public List<Period> generatePeriods( DateTimeUnit dateTimeUnit ) { Calendar calendar = getCalendar(); dateTimeUnit = calendar.minusYears( dateTimeUnit, 5 ); dateTimeUnit.setDay( 1 ); dateTimeUnit.setMonth( 1 ); List<Period> periods = Lists.newArrayList(); for ( int i = 0; i < 11; ++i ) { periods.add( createPeriod( dateTimeUnit, calendar ) ); dateTimeUnit = calendar.plusYears( dateTimeUnit, 1 ); } return periods; }  @Override String getName(); @Override Period createPeriod( DateTimeUnit dateTimeUnit, Calendar calendar ); @Override int getFrequencyOrder(); @Override String getSqlInterval(); @Override DateTimeUnit getDateWithOffset( DateTimeUnit dateTimeUnit, int offset, Calendar calendar ); @Override List<Period> generatePeriods( DateTimeUnit dateTimeUnit ); @Override List<Period> generateRollingPeriods( Date date ); @Override List<Period> generateRollingPeriods( DateTimeUnit dateTimeUnit, Calendar calendar ); @Override List<Period> generateLast5Years( Date date ); @Override String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar ); @Override String getIsoFormat(); @Override String getIso8601Duration(); @Override Date getRewindedDate( Date date, Integer rewindedPeriods ); static final String NAME; static final int FREQUENCY_ORDER; static final String SQL_INTERVAL; }
@Test public void testGeneratePeriods() { testDate = new DateTime( 2009, 8, 15, 0, 0 ); List<Period> periods = periodType.generatePeriods( testDate.toDate() ); assertEquals( 11, periods.size() ); assertEquals( periodType.createPeriod( new DateTime( 2004, 1, 1, 0, 0 ).toDate() ), periods.get( 0 ) ); assertEquals( periodType.createPeriod( new DateTime( 2005, 1, 1, 0, 0 ).toDate() ), periods.get( 1 ) ); assertEquals( periodType.createPeriod( new DateTime( 2006, 1, 1, 0, 0 ).toDate() ), periods.get( 2 ) ); assertEquals( periodType.createPeriod( new DateTime( 2007, 1, 1, 0, 0 ).toDate() ), periods.get( 3 ) ); assertEquals( periodType.createPeriod( new DateTime( 2008, 1, 1, 0, 0 ).toDate() ), periods.get( 4 ) ); assertEquals( periodType.createPeriod( new DateTime( 2009, 1, 1, 0, 0 ).toDate() ), periods.get( 5 ) ); assertEquals( periodType.createPeriod( new DateTime( 2010, 1, 1, 0, 0 ).toDate() ), periods.get( 6 ) ); assertEquals( periodType.createPeriod( new DateTime( 2011, 1, 1, 0, 0 ).toDate() ), periods.get( 7 ) ); assertEquals( periodType.createPeriod( new DateTime( 2012, 1, 1, 0, 0 ).toDate() ), periods.get( 8 ) ); assertEquals( periodType.createPeriod( new DateTime( 2013, 1, 1, 0, 0 ).toDate() ), periods.get( 9 ) ); assertEquals( periodType.createPeriod( new DateTime( 2014, 1, 1, 0, 0 ).toDate() ), periods.get( 10 ) ); }