Skip to content

Commit 2414250

Browse files
committed
Fix generics issue.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1560399 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8ba293b commit 2414250

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Collections;
2727
import java.util.HashMap;
2828
import java.util.Map;
29+
import java.util.TreeMap;
2930
import java.util.concurrent.ConcurrentHashMap;
3031

3132
import 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);

0 commit comments

Comments
 (0)