public Map < ConfigID , List < T > > collectElementsById ( Map < ConfigID , List < T > > map , String defaultId , String pid ) { if ( map == null ) { map = new HashMap < ConfigID , List < T > > ( ) ; } int index = 0 ; for ( T configElement : configElements ) { String id = configElement . getId ( ) ; if ( id == null ) { if ( defaultId != null ) { id = defaultId ; } else { id = generateId ( index ++ ) ; } } // Create a new config ID based on the old one, but using the generated ID if necessary ConfigID configID = configElement . getConfigID ( ) ; configID = new ConfigID ( configID . getParent ( ) , pid , id , configID . getChildAttribute ( ) ) ; List < T > elements = map . get ( configID ) ; if ( elements == null ) { elements = new ArrayList < T > ( ) ; map . put ( configID , elements ) ; } elements . add ( configElement ) ; } return map ; }
Collects elements into Lists based on their ID . If an ID is not specified the defaultId will be used . If the defaultId is null an id will be generated .