public static < T > void filterListToMap ( final Map < String , T > destinationMap , final String [ ] nameMapping , final List < ? extends T > sourceList ) { if ( destinationMap == null ) { throw new NullPointerException ( "destinationMap should not be null" ) ; } else if ( nameMapping == null ) { throw new NullPointerException ( "nameMapping should not be null" ) ; } else if ( sourceList == null ) { throw new NullPointerException ( "sourceList should not be null" ) ; } else if ( nameMapping . length != sourceList . size ( ) ) { throw new SuperCsvException ( String . format ( "the nameMapping array and the sourceList should be the same size (nameMapping length = %d, sourceList size = %d)" , nameMapping . length , sourceList . size ( ) ) ) ; } destinationMap . clear ( ) ; for ( int i = 0 ; i < nameMapping . length ; i ++ ) { final String key = nameMapping [ i ] ; if ( key == null ) { continue ; // null's in the name mapping means skip column } // no duplicates allowed if ( destinationMap . containsKey ( key ) ) { throw new SuperCsvException ( String . format ( "duplicate nameMapping '%s' at index %d" , key , i ) ) ; } destinationMap . put ( key , sourceList . get ( i ) ) ; } }
Converts a List to a Map using the elements of the nameMapping array as the keys of the Map .