Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Edge


    public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
        if (label == null)
            throw ExceptionFactory.edgeLabelCanNotBeNull();

        String idString = null;
        Edge edge;
        if (null != id) {
            idString = id.toString();
            edge = this.edges.get(idString);
            if (null != edge) {
                throw ExceptionFactory.edgeWithIdAlreadyExist(id);
            }
        } else {
            boolean done = false;
            while (!done) {
                idString = this.getNextId();
                edge = this.edges.get(idString);
                if (null == edge)
                    done = true;
            }
        }

        edge = new TinkerEdge(idString, outVertex, inVertex, label, this);
        this.edges.put(edge.getId().toString(), edge);
        final TinkerVertex out = (TinkerVertex) outVertex;
        final TinkerVertex in = (TinkerVertex) inVertex;
        out.addOutEdge(label, edge);
        in.addInEdge(label, edge);
        return edge;
View Full Code Here


        if (graph.getFeatures().supportsEdgeIteration && graph.getFeatures().supportsEdgeKeyIndex) {
            graph.createKeyIndex("place", Edge.class);
            assertEquals(graph.getIndexedKeys(Edge.class).size(), 1);
            assertTrue(graph.getIndexedKeys(Edge.class).contains("place"));

            Edge e1 = graph.addEdge(null, graph.addVertex(null), graph.addVertex(null), graphTest.convertLabel("knows"));
            e1.setProperty("name", "marko");
            e1.setProperty("place", "everywhere");
            Edge e2 = graph.addEdge(null, graph.addVertex(null), graph.addVertex(null), graphTest.convertLabel("knows"));
            e2.setProperty("name", "stephen");
            e2.setProperty("place", "everywhere");

            assertEquals(count(graph.getEdges("place", "everywhere")), 2);
            assertEquals(count(graph.getEdges("name", "marko")), 1);
            assertEquals(count(graph.getEdges("name", "stephen")), 1);
            assertEquals(graph.getEdges("name", "marko").iterator().next(), e1);
View Full Code Here

            assertEquals(count(graph.getVertices("name", "marko")), 1);
            assertEquals(graph.getVertices("name", "marko").iterator().next(), vertex);
        }

        if (graph.getFeatures().supportsEdgeKeyIndex) {
            Edge edge = graph.addEdge(null, graph.addVertex(null), graph.addVertex(null), graphTest.convertLabel("knows"));
            edge.setProperty("date", 2012);
            assertEquals(count(graph.getEdges("date", 2012)), 1);
            assertEquals(graph.getEdges("date", 2012).iterator().next(), edge);
            graph.createKeyIndex("date", Edge.class);
            assertEquals(count(graph.getEdges("date", 2012)), 1);
            assertEquals(graph.getEdges("date", 2012).iterator().next(), edge);
View Full Code Here

            assertEquals(itty.next(), a);
        }
        assertEquals(counter, 1);

        Vertex b = graph.addVertex(null);
        Edge edge = graph.addEdge(null, a, b, "knows");
        edge.setProperty("weight", 0.75);
        edgeIndex.put("weight", 0.75, edge);

        itty = graph.getIndex("edges", Edge.class).query("label", "k?ows").iterator();
        counter = 0;
        while (itty.hasNext()) {
View Full Code Here

        EdgeHelper.relabelEdge(graph, graph.getEdge(7), "1234", "use_to_know");
        assertEquals(count(graph.getVertices()), 6);
        assertEquals(count(graph.getEdges()), 6);
        int counter = 0;
        int counter2 = 0;
        Edge temp = null;
        for (Edge edge : graph.getVertex(1).getEdges(Direction.OUT)) {
            if (edge.getLabel().equals("use_to_know")) {
                counter++;
                assertEquals(edge.getId(), "1234");
                assertEquals(edge.getProperty("weight"), 0.5f);
View Full Code Here

        EdgeHelper.relabelEdges(graph, Arrays.asList(graph.getEdge(7)), "use_to_know");
        assertEquals(count(graph.getVertices()), 6);
        assertEquals(count(graph.getEdges()), 6);
        int counter = 0;
        int counter2 = 0;
        Edge temp = null;
        for (Edge edge : graph.getVertex(1).getEdges(Direction.OUT)) {
            if (edge.getLabel().equals("use_to_know")) {
                counter++;
                assertEquals(edge.getProperty("weight"), 0.5f);
                temp = edge;
View Full Code Here

        graph.setWritePartition("c");
        assertEquals(graph.getReadPartitions().size(), 2);
        assertTrue(graph.getReadPartitions().contains("a"));
        assertTrue(graph.getReadPartitions().contains("b"));
        assertEquals(graph.getWritePartition(), "c");
        Edge knows = graph.addEdge(null, marko, peter, "knows");
        Edge rawKnows = ((PartitionEdge) knows).getBaseEdge();
        assertEquals(count(graph.getVertices()), 2);
        assertEquals(count(graph.getEdges()), 0);
        graph.addReadPartition("c");
        assertEquals(count(graph.getVertices()), 2);
        assertEquals(count(graph.getEdges()), 1);
        assertEquals(knows.getPropertyKeys().size(), 0);
        assertEquals(rawKnows.getPropertyKeys().size(), 1);
        assertNull(knows.getProperty("_writeGraph"));
        assertEquals(rawKnows.getProperty("_writeGraph"), "c");
        assertEquals(((PartitionEdge) knows).getPartition(), "c");
        assertEquals(graph.getEdges().iterator().next(), knows);

        graph.removeReadPartition("a");
        graph.removeReadPartition("b");
View Full Code Here

    public void testElementClasses() throws Exception {
        Graph graph = this.generateGraph();
        Vertex v1 = graph.addVertex(null);
        Vertex v2 = graph.addVertex(null);
        Edge e = graph.addEdge(null, v1, v2, "knows");

        assertTrue(v1 instanceof IdVertex);
        assertTrue(e instanceof IdEdge);

        Iterator<Edge> outE = v1.getEdges(Direction.OUT).iterator();
        assertTrue(outE.hasNext());
        e = outE.next();
        assertTrue(e instanceof IdEdge);
        assertTrue(e.getVertex(Direction.IN) instanceof IdVertex);
        assertTrue(e.getVertex(Direction.OUT) instanceof IdVertex);

        Iterator<Vertex> vertices = graph.getVertices().iterator();
        assertTrue(vertices.hasNext());
        while (vertices.hasNext()) {
            assertTrue(vertices.next() instanceof IdVertex);
View Full Code Here

        assertEquals(36, id.length());
        assertEquals(5, id.split("-").length);

        Vertex v2 = graph.addVertex(null);
        Edge e = graph.addEdge(null, v, v2, "knows");

        id = (String) e.getId();
        assertEquals(36, id.length());
        assertEquals(5, id.split("-").length);
        graph.shutdown();
    }
View Full Code Here

        Vertex v1 = graph.getVertex(1);
        Vertex v2 = graph.getVertex(2);
        Vertex v3 = graph.getVertex(3);

        Iterable<Edge> out1 = v1.getEdges(Direction.OUT);
        Edge e1 = out1.iterator().next();
        Assert.assertEquals(v2, e1.getVertex(Direction.IN));

        Iterable<Edge> out2 = v2.getEdges(Direction.OUT);
        Edge e2 = out2.iterator().next();
        Assert.assertEquals(v3, e2.getVertex(Direction.IN));

        Iterable<Edge> out3 = v3.getEdges(Direction.OUT);
        Edge e3 = out3.iterator().next();
        Assert.assertEquals(v1, e3.getVertex(Direction.IN));

    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.Edge

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.