All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cucumber.runtime.xstream.MapWriter Maven / Gradle / Ivy

There is a newer version: 1.2.6
Show newest version
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 columnNames;
    private final Map values = new LinkedHashMap();

    private String key;

    public MapWriter(List columnNames) {
        this.columnNames = columnNames;
    }

    @Override
    public List getHeader() {
        return columnNames.isEmpty() ? new ArrayList(values.keySet()) : columnNames;
    }

    @Override
    public List getValues() {
        List values = new ArrayList(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() {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy