-
Notifications
You must be signed in to change notification settings - Fork 0
/
Row.java
40 lines (29 loc) · 891 Bytes
/
Row.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package test.streams;
import java.util.Map;
import java.util.HashMap;
public class Row {
private Map<String, String> values;
public Row(Map<String, String> initialValues) {
values = new HashMap<>(initialValues);
}
public Row filterColumns(Iterable<String> columns){
Map<String, String> filteredCopy = new HashMap<String,String>();
for (String column : columns) {
String value = values.get(column);
if (value == null)
throw new RuntimeException("When filtering on column " + column + " no values were found in row " + values.toString());
filteredCopy.put(column, value);
}
return new Row(filteredCopy);
}
public String get(String key) {
return values.get(key);
}
public void put(String key, String value) {
values.put(key, value);
}
@Override
public String toString() {
return values.toString();
}
}