Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Edge


        Vertex v3 = graph.getVertex(3);
        Assert.assertEquals("Node 3", v3.getProperty(LABEL));

        Iterable<Edge> out1 = v1.getEdges(Direction.OUT);
        Edge e1 = out1.iterator().next();
        Assert.assertEquals("Edge from node 1 to node 2", e1.getLabel());

        Iterable<Edge> out2 = v2.getEdges(Direction.OUT);
        Edge e2 = out2.iterator().next();
        Assert.assertEquals("Edge from node 2 to node 3", e2.getLabel());

        Iterable<Edge> out3 = v3.getEdges(Direction.OUT);
        Edge e3 = out3.iterator().next();
        Assert.assertEquals("Edge from node 3 to node 1", e3.getLabel());

    }
View Full Code Here


    @Test
    public void jsonFromElementEdgeNoPropertiesNoKeysNoTypes() throws JSONException {
        Vertex v1 = this.graph.addVertex(1);
        Vertex v2 = this.graph.addVertex(2);

        Edge e = this.graph.addEdge(3, v1, v2, "test");
        e.setProperty("weight", 0.5f);

        JSONObject json = GraphSONUtility.jsonFromElement(e, null, GraphSONMode.NORMAL);

        Assert.assertNotNull(json);
        Assert.assertTrue(json.has(GraphSONTokens._ID));
View Full Code Here

    @Test
    public void jsonFromElementEdgeCompactIdOnlyAsInclude() throws JSONException {
        Vertex v1 = this.graph.addVertex(1);
        Vertex v2 = this.graph.addVertex(2);

        Edge e = this.graph.addEdge(3, v1, v2, "test");
        e.setProperty("weight", 0.5f);

        Set<String> propertiesToInclude = new HashSet<String>() {{
            add(GraphSONTokens._ID);
        }};
View Full Code Here

    public void jsonFromElementEdgeCompactIdOnlyAsExclude() throws JSONException {
        ElementFactory factory = new GraphElementFactory(this.graph);
        Vertex v1 = this.graph.addVertex(1);
        Vertex v2 = this.graph.addVertex(2);

        Edge e = this.graph.addEdge(3, v1, v2, "test");
        e.setProperty("weight", 0.5f);
        e.setProperty("x", "y");

        Set<String> propertiesToExclude = new HashSet<String>() {{
            add(GraphSONTokens._TYPE);
            add(GraphSONTokens._LABEL);
            add(GraphSONTokens._IN_V);
View Full Code Here

    @Test
    public void jsonFromElementEdgeCompactAllKeys() throws JSONException {
        Vertex v1 = this.graph.addVertex(1);
        Vertex v2 = this.graph.addVertex(2);

        Edge e = this.graph.addEdge(3, v1, v2, "test");
        e.setProperty("weight", 0.5f);

        JSONObject json = GraphSONUtility.jsonFromElement(e, null, GraphSONMode.COMPACT);

        Assert.assertNotNull(json);
        Assert.assertTrue(json.has(GraphSONTokens._ID));
View Full Code Here

        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);
        Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.NORMAL, null);
        Edge e = GraphSONUtility.edgeFromJson(new JSONObject(new JSONTokener(edgeJson)), v1, v2, factory, GraphSONMode.NORMAL, null);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(7));

        // tinkergraph converts id to string
        Assert.assertEquals("7", e.getId());
        Assert.assertEquals(0.5d, e.getProperty("weight"));
        Assert.assertEquals("knows", e.getLabel());
        Assert.assertEquals(v1, e.getVertex(Direction.OUT));
        Assert.assertEquals(v2, e.getVertex(Direction.IN));
    }
View Full Code Here

        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v1 = GraphSONUtility.vertexFromJson(vertexJson1, factory, GraphSONMode.NORMAL, null);
        Vertex v2 = GraphSONUtility.vertexFromJson(vertexJson2, factory, GraphSONMode.NORMAL, null);
        Edge e = GraphSONUtility.edgeFromJson(edgeJson, v1, v2, factory, GraphSONMode.NORMAL, null);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(7));

        // tinkergraph converts id to string
        Assert.assertEquals("7", e.getId());
        Assert.assertEquals(0.5d, e.getProperty("weight"));
        Assert.assertEquals("knows", e.getLabel());
        Assert.assertEquals(v1, e.getVertex(Direction.OUT));
        Assert.assertEquals(v2, e.getVertex(Direction.IN));
    }
View Full Code Here

        final Vertex v2 = g.getVertex(2);
        ageIndex.put("age", v1.getProperty("age"), v1);
        ageIndex.put("age", v2.getProperty("age"), v2);

        final Index<Edge> weightIndex = g.createIndex("weight", Edge.class);
        final Edge e7 = g.getEdge(7);
        final Edge e12 = g.getEdge(12);
        weightIndex.put("weight", e7.getProperty("weight"), e7);
        weightIndex.put("weight", e12.getProperty("weight"), e12);
    }
View Full Code Here

        Set<String> ignoreWeight = new HashSet<String>();
        ignoreWeight.add("weight");
        ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(null, ignoreWeight);
        GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
        Edge e = utility.edgeFromJson(new JSONObject(new JSONTokener(edgeJson)), v1, v2);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(7));

        // tinkergraph converts id to string
        Assert.assertEquals("7", e.getId());
        Assert.assertNull(e.getProperty("weight"));
        Assert.assertEquals("knows", e.getLabel());
        Assert.assertEquals(v1, e.getVertex(Direction.OUT));
        Assert.assertEquals(v2, e.getVertex(Direction.IN));
    }
View Full Code Here

            assertTrue(ElementHelper.haveEqualProperties(v1, v2));
            assertTrue(ElementHelper.areEqual(v1, v2));
        }

        for (Edge e1 : g1.getEdges()) {
            final Edge e2 = g2.getEdge(e1.getId());

            compareVertices(e1, e2, Direction.IN);
            compareVertices(e2, e2, Direction.OUT);

            if (fileType == TinkerGraph.FileType.GML) {
                // For GML we need to iterate the properties manually to catch the
                // case where the property returned from GML is an integer
                // while the target graph property is a float.
                for (String p : e1.getPropertyKeys()) {
                    final Object v1 = e1.getProperty(p);
                    final Object v2 = e2.getProperty(p);

                    if (!v1.getClass().equals(v2.getClass())) {
                        if ((v1 instanceof Float) && (v2 instanceof Integer)) {
                            assertEquals(v1, ((Integer) v2).floatValue());
                        } else if ((v1 instanceof Integer) && (v2 instanceof Float)) {
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.