@Test public void testFilterListToMap() { final Map<String, String> map = new HashMap<String, String>(); Util.filterListToMap(map, NAME_MAPPING, LIST); assertTrue(map.size() == 2); assertEquals("Ezio", map.get("name")); assertEquals("Venice", map.get("city")); }
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; } if( destinationMap.containsKey(key) ) { throw new SuperCsvException(String.format("duplicate nameMapping '%s' at index %d", key, i)); } destinationMap.put(key, sourceList.get(i)); } }
Util { 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; } if( destinationMap.containsKey(key) ) { throw new SuperCsvException(String.format("duplicate nameMapping '%s' at index %d", key, i)); } destinationMap.put(key, sourceList.get(i)); } } }
Util { 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; } if( destinationMap.containsKey(key) ) { throw new SuperCsvException(String.format("duplicate nameMapping '%s' at index %d", key, i)); } destinationMap.put(key, sourceList.get(i)); } } private  Util(); }
Util { 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; } if( destinationMap.containsKey(key) ) { throw new SuperCsvException(String.format("duplicate nameMapping '%s' at index %d", key, i)); } destinationMap.put(key, sourceList.get(i)); } } private  Util(); static void executeCellProcessors(final List<Object> destination, final List<?> source,
		final CellProcessor[] processors, final int lineNo, final int rowNo); static void filterListToMap(final Map<String, T> destinationMap, final String[] nameMapping,
		final List<? extends T> sourceList); static List<Object> filterMapToList(final Map<String, ?> map, final String[] nameMapping); static Object[] filterMapToObjectArray(final Map<String, ?> values, final String[] nameMapping); static String[] objectArrayToStringArray(final Object[] objectArray); static String[] objectListToStringArray(final List<?> objectList); static String subtractBom(String line); }
Util { 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; } if( destinationMap.containsKey(key) ) { throw new SuperCsvException(String.format("duplicate nameMapping '%s' at index %d", key, i)); } destinationMap.put(key, sourceList.get(i)); } } private  Util(); static void executeCellProcessors(final List<Object> destination, final List<?> source,
		final CellProcessor[] processors, final int lineNo, final int rowNo); static void filterListToMap(final Map<String, T> destinationMap, final String[] nameMapping,
		final List<? extends T> sourceList); static List<Object> filterMapToList(final Map<String, ?> map, final String[] nameMapping); static Object[] filterMapToObjectArray(final Map<String, ?> values, final String[] nameMapping); static String[] objectArrayToStringArray(final Object[] objectArray); static String[] objectListToStringArray(final List<?> objectList); static String subtractBom(String line);  }