Skip to content

Commit ad94289

Browse files
committed
data: Update addRow iteration to use Map keySet
1 parent 2f5c6b7 commit ad94289

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/com/buabook/kdb/data/KdbTable.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public void addRow(KdbDict row) throws TableSchemaMismatchException {
153153
}
154154

155155
/**
156-
* Adds a row to a table based on an {@link HashMap} representation of the row (i.e. a kdb dictionary)
156+
* Adds a row to a table based on an {@link HashMap} representation of the row (i.e. a kdb dictionary). Any list
157+
* values are converted to arrays and any enumeration values are converted to strings.
157158
* @param row The new row to add
158159
* @throws TableSchemaMismatchException If there are any missing columns from the new row
159160
*/
@@ -165,18 +166,18 @@ public void addRow(Map<String, Object> row) throws TableSchemaMismatchException
165166
if(! row.keySet().containsAll(data.keySet()))
166167
throw new TableSchemaMismatchException("Missing columns in row to add");
167168

168-
for(String key : row.keySet()) {
169-
if(! data.containsKey(key))
170-
data.put(key, new ArrayList<Object>());
169+
for(Entry<String, Object> entry : row.entrySet()) {
170+
if(! data.containsKey(entry.getKey()))
171+
data.put(entry.getKey(), new ArrayList<Object>());
171172

172-
Object rowValue = row.get(key);
173+
Object rowValue = entry.getValue();
173174

174175
if(rowValue instanceof List<?>)
175176
rowValue = ((List<?>) rowValue).toArray();
176177
else if(rowValue instanceof Enum)
177178
rowValue = ((Enum<?>) rowValue).toString();
178179

179-
data.get(key).add(rowValue);
180+
data.get(entry.getKey()).add(rowValue);
180181
}
181182

182183
this.rowCount++;

0 commit comments

Comments
 (0)