com.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex Maven / Gradle / Ivy
The newest version!
package com.tinkerpop.gremlin.tinkergraph.structure;
import com.tinkerpop.gremlin.structure.Direction;
import com.tinkerpop.gremlin.structure.Edge;
import com.tinkerpop.gremlin.structure.Element;
import com.tinkerpop.gremlin.structure.Graph;
import com.tinkerpop.gremlin.structure.Property;
import com.tinkerpop.gremlin.structure.Vertex;
import com.tinkerpop.gremlin.structure.VertexProperty;
import com.tinkerpop.gremlin.structure.util.ElementHelper;
import com.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class TinkerVertex extends TinkerElement implements Vertex, Vertex.Iterators {
protected Map> outEdges = new HashMap<>();
protected Map> inEdges = new HashMap<>();
private static final Object[] EMPTY_ARGS = new Object[0];
protected TinkerVertex(final Object id, final String label, final TinkerGraph graph) {
super(id, label, graph);
}
@Override
public VertexProperty property(final String key) {
if (removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id);
if (TinkerHelper.inComputerMode(this.graph)) {
final List list = (List) this.graph.graphView.getProperty(this, key);
if (list.size() == 0)
return VertexProperty.empty();
else if (list.size() == 1)
return list.get(0);
else
throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key);
} else {
if (this.properties.containsKey(key)) {
final List list = (List) this.properties.get(key);
if (list.size() > 1)
throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key);
else
return list.get(0);
} else
return VertexProperty.empty();
}
}
@Override
public VertexProperty property(final String key, final V value) {
return this.property(key, value, EMPTY_ARGS);
}
@Override
public VertexProperty property(final String key, final V value, final Object... keyValues) {
if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(Vertex.class, this.id);
ElementHelper.legalPropertyKeyValueArray(keyValues);
final Optional