use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionLabel method getLabel.
private Object getLabel(final OrientBaseGraph graph, final OIdentifiable iCurrentRecord) {
final ODocument rec = iCurrentRecord.getRecord();
OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(rec);
if (immutableClass.isVertexType()) {
// VERTEX
final OrientVertex vertex = graph.getVertex(iCurrentRecord);
return vertex.getLabel();
} else if (immutableClass.isEdgeType()) {
// EDGE
final OrientEdge edge = graph.getEdge(iCurrentRecord);
return edge.getLabel();
} else
throw new OCommandExecutionException("Invalid record: is neither a vertex nor an edge. Found class: " + immutableClass);
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionMove method v2v.
protected Object v2v(final OrientBaseGraph graph, final OIdentifiable iRecord, final Direction iDirection, final String[] iLabels) {
final ODocument rec = iRecord.getRecord();
OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(rec);
if (immutableClass != null && immutableClass.isVertexType()) {
// VERTEX
final OrientVertex vertex = graph.getVertex(rec);
if (vertex != null)
return vertex.getVertices(iDirection, iLabels);
}
return null;
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionPathFinder method execute.
protected LinkedList<OrientVertex> execute(final OCommandContext iContext) {
context = iContext;
unSettledNodes = new HashSet<OrientVertex>();
distance = new HashMap<ORID, Float>();
predecessors = new HashMap<ORID, OrientVertex>();
distance.put(paramSourceVertex.getIdentity(), MIN);
unSettledNodes.add(paramSourceVertex);
int maxDistances = 0;
int maxSettled = 0;
int maxUnSettled = 0;
int maxPredecessors = 0;
while (continueTraversing()) {
final OrientVertex node = getMinimum(unSettledNodes);
unSettledNodes.remove(node);
findMinimalDistances(node);
if (distance.size() > maxDistances)
maxDistances = distance.size();
if (unSettledNodes.size() > maxUnSettled)
maxUnSettled = unSettledNodes.size();
if (predecessors.size() > maxPredecessors)
maxPredecessors = predecessors.size();
if (!isVariableEdgeWeight() && distance.containsKey(paramDestinationVertex.getIdentity()))
// FOUND
break;
if (!OCommandExecutorAbstract.checkInterruption(context))
break;
}
context.setVariable("maxDistances", maxDistances);
context.setVariable("maxSettled", maxSettled);
context.setVariable("maxUnSettled", maxUnSettled);
context.setVariable("maxPredecessors", maxPredecessors);
distance = null;
return getPath();
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionPathFinder method getPath.
/*
* This method returns the path from the source to the selected target and NULL if no path exists
*/
public LinkedList<OrientVertex> getPath() {
final LinkedList<OrientVertex> path = new LinkedList<OrientVertex>();
OrientVertex step = paramDestinationVertex;
// Check if a path exists
if (predecessors.get(step.getIdentity()) == null)
return null;
path.add(step);
while (predecessors.get(step.getIdentity()) != null) {
step = predecessors.get(step.getIdentity());
path.add(step);
}
// Put it into the correct order
Collections.reverse(path);
return path;
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionPathFinder method getNeighbors.
protected Set<OrientVertex> getNeighbors(final Vertex node) {
context.incrementVariable("getNeighbors");
final Set<OrientVertex> neighbors = new HashSet<OrientVertex>();
if (node != null) {
for (Vertex v : node.getVertices(paramDirection)) {
final OrientVertex ov = (OrientVertex) v;
if (ov != null && isNotSettled(ov))
neighbors.add(ov);
}
}
return neighbors;
}
Aggregations