File tree Expand file tree Collapse file tree
main/java/org/apache/commons/csv
test/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ public Iterator<String> iterator() {
176176 * @param map The Map to populate.
177177 * @return the given map.
178178 */
179- Map <String , String > putIn (final Map < String , String > map ) {
179+ < M extends Map <String , String >> M putIn (final M map ) {
180180 for (final Entry <String , Integer > entry : mapping .entrySet ()) {
181181 map .put (entry .getKey (), values [entry .getValue ().intValue ()]);
182182 }
Original file line number Diff line number Diff line change 2626import java .util .Collections ;
2727import java .util .HashMap ;
2828import java .util .Map ;
29+ import java .util .TreeMap ;
2930import java .util .concurrent .ConcurrentHashMap ;
3031
3132import org .junit .Assert ;
@@ -133,6 +134,9 @@ public void testPutInMap() {
133134 final Map <String , String > map = new ConcurrentHashMap <String , String >();
134135 this .recordWithHeader .putIn (map );
135136 this .validateMap (map , false );
137+ // Test that we can compile with assigment to the same map as the param.
138+ final TreeMap <String , String > map2 = recordWithHeader .putIn (new TreeMap <String , String >());
139+ this .validateMap (map2 , false );
136140 }
137141
138142 @ Test
@@ -141,7 +145,7 @@ public void testRemoveAndAddColumns() throws IOException {
141145 final CSVPrinter printer = new CSVPrinter (new StringBuilder (), CSVFormat .DEFAULT );
142146 final Map <String , String > map = recordWithHeader .toMap ();
143147 map .remove ("OldColumn" );
144- map .put ("NewColumn " , "NewValue" );
148+ map .put ("ZColumn " , "NewValue" );
145149 // check:
146150 final ArrayList <String > list = new ArrayList <String >(map .values ());
147151 Collections .sort (list );
You can’t perform that action at this time.
0 commit comments