IdentifiableObjectUtils { public static Period getPeriodByPeriodType( Period period, PeriodType periodType, Calendar calendar ) { Assert.isTrue( periodType.getFrequencyOrder() >= period.getPeriodType().getFrequencyOrder(), "Frequency order of period type must be greater than or equal to period" ); Date date = period.getStartDate(); if ( WeeklyAbstractPeriodType.class.isAssignableFrom( period.getPeriodType().getClass() ) ) { date = new DateTime( date.getTime() ).plusDays( 3 ).toDate(); } return periodType.createPeriod( date, calendar ); }  static String join( Collection<? extends IdentifiableObject> objects ); static List<String> getUids( Collection<T> objects ); static List<String> getCodes( Collection<T> objects ); static List<Long> getIdentifiers( Collection<T> objects ); static Map<Long, T> getIdentifierMap( Collection<T> objects ); static List<String> getLocalPeriodIdentifiers( Collection<T> periods, Calendar calendar ); static String getLocalPeriodIdentifier( Period period, Calendar calendar ); static Period getPeriodByPeriodType( Period period, PeriodType periodType, Calendar calendar ); static List<T> filterNameByKey( List<T> identifiableObjects, String key,
        boolean ignoreCase ); static List<T> removeDuplicates( List<T> list ); static String getLastUpdatedTag( Collection<T> objects ); static String getLastUpdatedTag( IdentifiableObject object ); static Map<String, String> getUidNameMap( Collection<? extends IdentifiableObject> objects ); static Map<String, String> getUidPropertyMap( Collection<? extends IdentifiableObject> objects, IdentifiableProperty property ); static Map<String, T> getUidObjectMap( Collection<T> objects ); static Map<String, T> getIdMap( List<T> objects, IdScheme idScheme ); static String getDisplayName( Object object ); static String getIdentifierBasedOnIdScheme( T object, IdScheme idScheme ); static final String SEPARATOR; static final String SEPARATOR_JOIN; static final DateTimeFormatter LONG_DATE_FORMAT; static final DateTimeFormatter MEDIUM_DATE_FORMAT; static final Map<String, String> CLASS_ALIAS; }
@Test public void testGetPeriodByPeriodType() { Calendar calendar = Iso8601Calendar.getInstance(); WeeklyPeriodType weekly = new WeeklyPeriodType(); MonthlyPeriodType monthly = new MonthlyPeriodType(); QuarterlyPeriodType quarterly = new QuarterlyPeriodType(); YearlyPeriodType yearly = new YearlyPeriodType(); assertEquals( PeriodType.getPeriodFromIsoString( "2017W10" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "20170308" ), weekly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "2017W9" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "20170301" ), weekly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201702" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017W8" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201703" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017W9" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201705" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017W21" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201706" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017W22" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201708" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017W35" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201702" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017WedW8" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201703" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017WedW9" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201702" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017ThuW8" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201703" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017ThuW10" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201702" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017SatW7" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201703" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017SatW10" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201702" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017SunW7" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201703" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017SunW9" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201702" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017SunW7" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "201703" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017SunW9" ), monthly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "2017Q1" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "201703" ), quarterly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "2017Q2" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "201704" ), quarterly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "2016" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2016Q4" ), yearly, calendar ) ); assertEquals( PeriodType.getPeriodFromIsoString( "2017" ), IdentifiableObjectUtils.getPeriodByPeriodType( PeriodType.getPeriodFromIsoString( "2017Q1" ), yearly, calendar ) ); assertNull( PeriodType.getPeriodFromIsoString( "u3847847" )); }