org.unipop.structure.UniEdge Maven / Gradle / Ivy
package org.unipop.structure;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.tinkerpop.gremlin.structure.*;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.unipop.query.mutation.PropertyQuery;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class UniEdge extends UniElement implements Edge {
protected Map properties;
protected Vertex inVertex;
protected Vertex outVertex;
public UniEdge(Map keyValues, Vertex outV, Vertex inV, final UniGraph graph) {
super(keyValues, graph);
this.outVertex = outV;
this.inVertex = inV;
this.properties = new HashMap<>();
keyValues.forEach(this::addPropertyLocal);
}
@Override
protected Map getPropertiesMap() {
return properties;
}
@Override
protected String getDefaultLabel() {
return Edge.DEFAULT_LABEL;
}
@Override
protected Property createProperty(String key, Object value) {
return new UniProperty<>(this, key, value);
}
@Override
public Property property(String key, V value) {
UniProperty vertexProperty = (UniProperty) addPropertyLocal(key, value);
PropertyQuery propertyQuery = new PropertyQuery<>(this, vertexProperty, PropertyQuery.Action.Add, null);
this.graph.getControllerManager().getControllers(PropertyQuery.PropertyController.class).forEach(controller ->
controller.property(propertyQuery));
return vertexProperty;
}
@Override
public Iterator vertices(Direction direction) {
if(direction.equals(Direction.OUT)) return IteratorUtils.singletonIterator(outVertex);
if(direction.equals(Direction.IN)) return IteratorUtils.singletonIterator(inVertex);
return Arrays.asList(outVertex, inVertex).iterator();
}
@Override
public Iterator properties(String... propertyKeys) {
return propertyIterator(propertyKeys);
}
@Override
public String toString() {
return StringFactory.edgeString(this);
}
}