-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement DataTable.toTable(List<Map<String,Object>>). Closes #433.
- Loading branch information
DFUK
authored and
DFUK
committed
Dec 5, 2012
1 parent
f83316c
commit f79d5d6
Showing
4 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
core/src/main/java/cucumber/runtime/xstream/MapWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package cucumber.runtime.xstream; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Supports Map<String, Object> as the List item | ||
*/ | ||
public class MapWriter extends CellWriter { | ||
private final List<String> columnNames; | ||
private final Map<String, Object> values = new LinkedHashMap<String, Object>(); | ||
|
||
private String key; | ||
|
||
public MapWriter(List<String> columnNames) { | ||
this.columnNames = columnNames; | ||
} | ||
|
||
@Override | ||
public List<String> getHeader() { | ||
return columnNames.isEmpty() ? new ArrayList<String>(values.keySet()) : columnNames; | ||
} | ||
|
||
@Override | ||
public List<String> getValues() { | ||
List<String> values = new ArrayList<String>(columnNames.size()); | ||
for (String columnName : getHeader()) { | ||
Object value = this.values.get(columnName); | ||
values.add(value == null ? "" : value.toString()); | ||
} | ||
return values; | ||
} | ||
|
||
@Override | ||
public void setValue(String value) { | ||
if (key == null) { | ||
key = value; | ||
} else { | ||
values.put(key, value); | ||
key = null; | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void startNode(String name) { | ||
} | ||
|
||
@Override | ||
public void addAttribute(String name, String value) { | ||
} | ||
|
||
@Override | ||
public void endNode() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters