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

com.tinkerpop.pipes.transform.PropertyMapPipe Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 2.6.0
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy