IdentifiableObjectUtils { public static <T extends IdentifiableObject> Map<String, T> getIdMap( List<T> objects, IdScheme idScheme ) { Map<String, T> map = new HashMap<>(); for ( T object : objects ) { String value = object.getPropertyValue( idScheme ); if ( value != null ) { map.put( value, object ); } } return map; }  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 testGetIdMap() { DataElement deA = new DataElement( "NameA" ); DataElement deB = new DataElement( "NameB" ); DataElement deC = new DataElement( "NameC" ); deA.setCode( "CodeA" ); deB.setCode( "CodeB" ); deC.setCode( "CodeC" ); deA.setUid( "A123456789A" ); deB.setUid( "A123456789B" ); deC.setUid( "A123456789C" ); List<DataElement> elements = Lists.newArrayList( deA, deB, deC ); Map<String, DataElement> map = IdentifiableObjectUtils.getIdMap( elements, IdScheme.from( IdentifiableProperty.NAME ) ); assertEquals( deA, map.get( "NameA" ) ); assertEquals( deB, map.get( "NameB" ) ); assertEquals( deC, map.get( "NameC" ) ); assertNull( map.get( "NameD" ) ); map = IdentifiableObjectUtils.getIdMap( elements, IdScheme.from( IdentifiableProperty.UID ) ); assertEquals( deA, map.get( "A123456789A" ) ); assertEquals( deB, map.get( "A123456789B" ) ); assertEquals( deC, map.get( "A123456789C" ) ); assertNull( map.get( "A123456789D" ) ); map = IdentifiableObjectUtils.getIdMap( elements, IdScheme.from( IdentifiableProperty.CODE ) ); assertEquals( deA, map.get( "CodeA" ) ); assertEquals( deB, map.get( "CodeB" ) ); assertEquals( deC, map.get( "CodeC" ) ); assertNull( map.get( "CodeD" ) ); }