Search in sources :

Example 6 with Vertex

use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.

the class OSQLFunctionShortestPath method walkLeft.

protected List<ORID> walkLeft(final OSQLFunctionShortestPath.OShortestPathContext ctx) {
    ArrayDeque<OrientVertex> nextLevelQueue = new ArrayDeque<OrientVertex>();
    while (!ctx.queueLeft.isEmpty()) {
        ctx.current = ctx.queueLeft.poll();
        Iterable<Vertex> neighbors;
        if (ctx.edgeType == null) {
            neighbors = ctx.current.getVertices(ctx.directionLeft);
        } else {
            neighbors = ctx.current.getVertices(ctx.directionLeft, ctx.edgeTypeParam);
        }
        for (Vertex neighbor : neighbors) {
            final OrientVertex v = (OrientVertex) neighbor;
            final ORID neighborIdentity = v.getIdentity();
            if (ctx.rightVisited.contains(neighborIdentity)) {
                ctx.previouses.put(neighborIdentity, ctx.current.getIdentity());
                return computePath(ctx.previouses, ctx.nexts, neighborIdentity);
            }
            if (!ctx.leftVisited.contains(neighborIdentity)) {
                ctx.previouses.put(neighborIdentity, ctx.current.getIdentity());
                nextLevelQueue.offer(v);
                ctx.leftVisited.add(neighborIdentity);
            }
        }
    }
    ctx.queueLeft = nextLevelQueue;
    return null;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ORID(com.orientechnologies.orient.core.id.ORID) ArrayDeque(java.util.ArrayDeque)

Example 7 with Vertex

use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.

the class OSQLFunctionShortestPath method walkRight.

protected List<ORID> walkRight(final OSQLFunctionShortestPath.OShortestPathContext ctx) {
    final ArrayDeque<OrientVertex> nextLevelQueue = new ArrayDeque<OrientVertex>();
    while (!ctx.queueRight.isEmpty()) {
        ctx.currentRight = ctx.queueRight.poll();
        Iterable<Vertex> neighbors;
        if (ctx.edgeType == null) {
            neighbors = ctx.currentRight.getVertices(ctx.directionRight);
        } else {
            neighbors = ctx.currentRight.getVertices(ctx.directionRight, ctx.edgeTypeParam);
        }
        for (Vertex neighbor : neighbors) {
            final OrientVertex v = (OrientVertex) neighbor;
            final ORID neighborIdentity = v.getIdentity();
            if (ctx.leftVisited.contains(neighborIdentity)) {
                ctx.nexts.put(neighborIdentity, ctx.currentRight.getIdentity());
                return computePath(ctx.previouses, ctx.nexts, neighborIdentity);
            }
            if (!ctx.rightVisited.contains(neighborIdentity)) {
                ctx.nexts.put(neighborIdentity, ctx.currentRight.getIdentity());
                nextLevelQueue.offer(v);
                ctx.rightVisited.add(neighborIdentity);
            }
        }
    }
    ctx.queueRight = nextLevelQueue;
    return null;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ORID(com.orientechnologies.orient.core.id.ORID) ArrayDeque(java.util.ArrayDeque)

Example 8 with Vertex

use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.

the class OSQLFunctionHeuristicPathFinderAbstract method getNeighbors.

protected Set<OrientVertex> getNeighbors(final OrientVertex node) {
    context.incrementVariable("getNeighbors");
    final Set<OrientVertex> neighbors = new HashSet<OrientVertex>();
    if (node != null) {
        for (Vertex v : node.getVertices(paramDirection, paramEdgeTypeNames)) {
            final OrientVertex ov = (OrientVertex) v;
            if (ov != null)
                neighbors.add(ov);
        }
    }
    return neighbors;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 9 with Vertex

use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.

the class TestFailOperationOnRemovedElement method testAddEdgeOnRemovedVertex.

@Test(expected = ORecordNotFoundException.class)
public void testAddEdgeOnRemovedVertex() {
    Vertex v = grap.addVertex(null);
    Vertex v1 = grap.addVertex(null);
    grap.commit();
    v.remove();
    v.addEdge("test", v1);
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) Test(org.junit.Test)

Example 10 with Vertex

use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.

the class TestFailOperationOnRemovedElement method testAddEdgeToRemovedVertex.

@Test(expected = ORecordNotFoundException.class)
public void testAddEdgeToRemovedVertex() {
    Vertex v = grap.addVertex(null);
    Vertex v1 = grap.addVertex(null);
    grap.commit();
    v1.remove();
    v.addEdge("test", v1);
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) Test(org.junit.Test)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)406 Test (org.junit.Test)119 Edge (com.tinkerpop.blueprints.Edge)111 Graph (com.tinkerpop.blueprints.Graph)85 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)84 JSONObject (org.codehaus.jettison.json.JSONObject)51 HashSet (java.util.HashSet)49 ArrayList (java.util.ArrayList)40 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)37 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)28 HashMap (java.util.HashMap)25 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)22 JSONArray (org.codehaus.jettison.json.JSONArray)20 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)19 Test (org.testng.annotations.Test)16 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)15 Map (java.util.Map)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11