Search in sources :

Example 6 with Index

use of com.tinkerpop.blueprints.Index in project blueprints by tinkerpop.

the class TinkerGraphTest method compareGraphs.

private void compareGraphs(final TinkerGraph g1, final TinkerGraph g2, final TinkerGraph.FileType fileType) {
    for (Vertex v1 : g1.getVertices()) {
        final Vertex v2 = g2.getVertex(v1.getId());
        compareEdgeCounts(v1, v2, Direction.IN);
        compareEdgeCounts(v1, v2, Direction.OUT);
        compareEdgeCounts(v1, v2, Direction.BOTH);
        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) {
            // 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)) {
                        assertEquals(((Integer) v1).floatValue(), v2);
                    }
                } else {
                    assertEquals(v1, v2);
                }
            }
        } else {
            assertTrue(ElementHelper.haveEqualProperties(e1, e2));
        }
        assertTrue(ElementHelper.areEqual(e1, e2));
    }
    final Index idxAge = g2.getIndex("age", Vertex.class);
    assertEquals(g2.getVertex(1), idxAge.get("age", 29).iterator().next());
    assertEquals(g2.getVertex(2), idxAge.get("age", 27).iterator().next());
    final Index idxWeight = g2.getIndex("weight", Edge.class);
    assertEquals(g2.getEdge(7), idxWeight.get("weight", 0.5f).iterator().next());
    assertEquals(g2.getEdge(12), idxWeight.get("weight", 0.2f).iterator().next());
    final Iterator namesItty = g2.getVertices("name", "marko").iterator();
    assertEquals(g2.getVertex(1), namesItty.next());
    assertFalse(namesItty.hasNext());
    final Iterator weightItty = g2.getEdges("weight", 0.5f).iterator();
    assertEquals(g2.getEdge(7), weightItty.next());
    assertFalse(weightItty.hasNext());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Iterator(java.util.Iterator) Index(com.tinkerpop.blueprints.Index) Edge(com.tinkerpop.blueprints.Edge)

Example 7 with Index

use of com.tinkerpop.blueprints.Index in project blueprints by tinkerpop.

the class RexsterGraphTest method resetGraph.

protected void resetGraph() {
    final KeyIndexableGraph graph = (KeyIndexableGraph) this.generateGraph();
    final IndexableGraph idxGraph = (IndexableGraph) graph;
    // since we don't have graph.clear() anymore we manually reset the graph.
    Iterator<Vertex> vertexItty = graph.getVertices().iterator();
    List<Vertex> verticesToRemove = new ArrayList<Vertex>();
    while (vertexItty.hasNext()) {
        verticesToRemove.add(vertexItty.next());
    }
    for (Vertex vertexToRemove : verticesToRemove) {
        graph.removeVertex(vertexToRemove);
    }
    for (String key : graph.getIndexedKeys(Vertex.class)) {
        graph.dropKeyIndex(key, Vertex.class);
    }
    for (String key : graph.getIndexedKeys(Edge.class)) {
        graph.dropKeyIndex(key, Edge.class);
    }
    for (Index idx : idxGraph.getIndices()) {
        idxGraph.dropIndex(idx.getIndexName());
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) ArrayList(java.util.ArrayList) Index(com.tinkerpop.blueprints.Index)

Aggregations

Index (com.tinkerpop.blueprints.Index)7 Edge (com.tinkerpop.blueprints.Edge)5 Vertex (com.tinkerpop.blueprints.Vertex)5 ArrayList (java.util.ArrayList)3 Element (com.tinkerpop.blueprints.Element)1 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)1 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)1 Neo4jGraph (com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph)1 PropertyFilteredIterable (com.tinkerpop.blueprints.util.PropertyFilteredIterable)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 Test (org.junit.Test)1