Search in sources :

Example 1 with OrderedByTypeExpander

use of org.neo4j.kernel.OrderedByTypeExpander in project graphdb by neo4j-attic.

the class OldTraverserWrapper method toExpander.

private static RelationshipExpander toExpander(Object[] relationshipTypesAndDirections) {
    Stack<Object[]> entries = new Stack<Object[]>();
    for (int i = 0; i < relationshipTypesAndDirections.length; i += 2) {
        Object relType = relationshipTypesAndDirections[i];
        if (relType == null) {
            throw new IllegalArgumentException("Null relationship type at " + i);
        }
        if (!(relType instanceof RelationshipType)) {
            throw new IllegalArgumentException("Expected RelationshipType at var args pos " + i + ", found " + relType);
        }
        Object direction = relationshipTypesAndDirections[i + 1];
        if (direction == null) {
            throw new IllegalArgumentException("Null direction at " + (i + 1));
        }
        if (!(direction instanceof Direction)) {
            throw new IllegalArgumentException("Expected Direction at var args pos " + (i + 1) + ", found " + direction);
        }
        entries.push(new Object[] { relType, direction });
    }
    OrderedByTypeExpander expander = new OrderedByTypeExpander();
    while (!entries.isEmpty()) {
        Object[] entry = entries.pop();
        expander = (OrderedByTypeExpander) expander.add((RelationshipType) entry[0], (Direction) entry[1]);
    }
    return expander;
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) OrderedByTypeExpander(org.neo4j.kernel.OrderedByTypeExpander) Direction(org.neo4j.graphdb.Direction) Stack(java.util.Stack)

Example 2 with OrderedByTypeExpander

use of org.neo4j.kernel.OrderedByTypeExpander in project neo4j-mobile-android by neo4j-contrib.

the class OldTraverserWrapper method toExpander.

private static RelationshipExpander toExpander(Object[] relationshipTypesAndDirections) {
    Stack<Object[]> entries = new Stack<Object[]>();
    for (int i = 0; i < relationshipTypesAndDirections.length; i += 2) {
        Object relType = relationshipTypesAndDirections[i];
        if (relType == null) {
            throw new IllegalArgumentException("Null relationship type at " + i);
        }
        if (!(relType instanceof RelationshipType)) {
            throw new IllegalArgumentException("Expected RelationshipType at var args pos " + i + ", found " + relType);
        }
        Object direction = relationshipTypesAndDirections[i + 1];
        if (direction == null) {
            throw new IllegalArgumentException("Null direction at " + (i + 1));
        }
        if (!(direction instanceof Direction)) {
            throw new IllegalArgumentException("Expected Direction at var args pos " + (i + 1) + ", found " + direction);
        }
        entries.push(new Object[] { relType, direction });
    }
    OrderedByTypeExpander expander = new OrderedByTypeExpander();
    while (!entries.isEmpty()) {
        Object[] entry = entries.pop();
        expander = (OrderedByTypeExpander) expander.add((RelationshipType) entry[0], (Direction) entry[1]);
    }
    return expander;
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) OrderedByTypeExpander(org.neo4j.kernel.OrderedByTypeExpander) Direction(org.neo4j.graphdb.Direction) Stack(java.util.Stack)

Example 3 with OrderedByTypeExpander

use of org.neo4j.kernel.OrderedByTypeExpander in project graphdb by neo4j-attic.

the class TestOrderByTypeExpander method makeSureNodesAreTraversedInCorrectOrder.

@Test
public void makeSureNodesAreTraversedInCorrectOrder() {
    RelationshipType next = DynamicRelationshipType.withName("NEXT");
    RelationshipType firstComment = DynamicRelationshipType.withName("FIRST_COMMENT");
    RelationshipType comment = DynamicRelationshipType.withName("COMMENT");
    RelationshipExpander expander = new OrderedByTypeExpander().add(firstComment).add(comment).add(next);
    Iterator<Node> itr = Traversal.description().depthFirst().expand(expander).traverse(referenceNode()).nodes().iterator();
    assertOrder(itr, "A1", "C1", "C2", "C3", "A2", "C4", "C5", "C6", "A3", "C7", "C8", "C9");
    expander = new OrderedByTypeExpander().add(next).add(firstComment).add(comment);
    itr = Traversal.description().depthFirst().expand(expander).traverse(referenceNode()).nodes().iterator();
    assertOrder(itr, "A1", "A2", "A3", "C7", "C8", "C9", "C4", "C5", "C6", "C1", "C2", "C3");
}
Also used : Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) DynamicRelationshipType(org.neo4j.graphdb.DynamicRelationshipType) OrderedByTypeExpander(org.neo4j.kernel.OrderedByTypeExpander) RelationshipExpander(org.neo4j.graphdb.RelationshipExpander) Test(org.junit.Test)

Aggregations

RelationshipType (org.neo4j.graphdb.RelationshipType)3 OrderedByTypeExpander (org.neo4j.kernel.OrderedByTypeExpander)3 Stack (java.util.Stack)2 Direction (org.neo4j.graphdb.Direction)2 Test (org.junit.Test)1 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)1 Node (org.neo4j.graphdb.Node)1 RelationshipExpander (org.neo4j.graphdb.RelationshipExpander)1