com.tinkerpop.pipes.transform.PropertyMapPipe Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipes Show documentation
Show all versions of pipes Show documentation
Pipes is a dataflow framework written in Java that enables the splitting, merging, filtering, and
transformation of data from input to output.
Computations are expressed using a combinator model and are evaluated in a memory-efficient, lazy fashion.
package com.tinkerpop.pipes.transform;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.pipes.AbstractPipe;
import java.util.HashMap;
import java.util.Map;
/**
* PropertyMapPipe emits the property map of an element.
*
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class PropertyMapPipe extends AbstractPipe> implements TransformPipe> {
private final String[] keys;
private static final String ID = "id";
private static final String LABEL = "label";
public PropertyMapPipe(final String... keys) {
this.keys = keys;
}
protected Map processNextStart() {
final S element = this.starts.next();
final Map map = new HashMap();
if (this.keys.length == 0) {
// TODO: add ID and LABEL as properties?
for (final String key : element.getPropertyKeys()) {
map.put(key, element.getProperty(key));
}
} else {
for (final String key : this.keys) {
if (key.equals(ID))
map.put(ID, element.getId());
else if (element instanceof Edge && key.equals(LABEL))
map.put(LABEL, ((Edge) element).getLabel());
else
map.put(key, element.getProperty(key));
}
}
return map;
}
}