Fix generics issue.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1560399 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2014-01-22 16:07:23 +00:00
parent 8ba293b934
commit 2414250b69
2 changed files with 6 additions and 2 deletions

View File

@ -176,7 +176,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
* @param map The Map to populate. * @param map The Map to populate.
* @return the given map. * @return the given map.
*/ */
Map<String, String> putIn(final Map<String, String> map) { <M extends Map<String, String>> M putIn(final M map) {
for (final Entry<String, Integer> entry : mapping.entrySet()) { for (final Entry<String, Integer> entry : mapping.entrySet()) {
map.put(entry.getKey(), values[entry.getValue().intValue()]); map.put(entry.getKey(), values[entry.getValue().intValue()]);
} }

View File

@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.junit.Assert; import org.junit.Assert;
@ -133,6 +134,9 @@ public class CSVRecordTest {
final Map<String, String> map = new ConcurrentHashMap<String, String>(); final Map<String, String> map = new ConcurrentHashMap<String, String>();
this.recordWithHeader.putIn(map); this.recordWithHeader.putIn(map);
this.validateMap(map, false); this.validateMap(map, false);
// Test that we can compile with assigment to the same map as the param.
final TreeMap<String, String> map2 = recordWithHeader.putIn(new TreeMap<String, String>());
this.validateMap(map2, false);
} }
@Test @Test
@ -141,7 +145,7 @@ public class CSVRecordTest {
final CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT); final CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT);
final Map<String, String> map = recordWithHeader.toMap(); final Map<String, String> map = recordWithHeader.toMap();
map.remove("OldColumn"); map.remove("OldColumn");
map.put("NewColumn", "NewValue"); map.put("ZColumn", "NewValue");
// check: // check:
final ArrayList<String> list = new ArrayList<String>(map.values()); final ArrayList<String> list = new ArrayList<String>(map.values());
Collections.sort(list); Collections.sort(list);