Search in sources :

Example 1 with Uniqueness

use of org.neo4j.graphdb.traversal.Uniqueness in project neo4j by neo4j.

the class TestBidirectionalTraversal method mirroredTraversalReversesInitialState.

@Test
void mirroredTraversalReversesInitialState() {
    /*
         * (a)-->(b)-->(c)-->(d)
         */
    createGraph("a TO b", "b TO c", "c TO d");
    try (Transaction transaction = getGraphDb().beginTx()) {
        BranchCollisionPolicy collisionPolicy = (evaluator, pathPredicate) -> new StandardBranchCollisionDetector(null, null) {

            @Override
            protected boolean includePath(Path path, TraversalBranch startPath, TraversalBranch endPath) {
                assertEquals(0, startPath.state());
                assertEquals(10, endPath.state());
                return true;
            }
        };
        Iterables.count(transaction.bidirectionalTraversalDescription().mirroredSides(transaction.traversalDescription().uniqueness(NODE_PATH).expand(PathExpanders.forType(to), new InitialBranchState.State<>(0, 10))).collisionPolicy(collisionPolicy).traverse(getNodeWithName(transaction, "a"), getNodeWithName(transaction, "d")));
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BranchCollisionPolicy(org.neo4j.graphdb.traversal.BranchCollisionPolicy) Traverser(org.neo4j.graphdb.traversal.Traverser) OUTGOING(org.neo4j.graphdb.Direction.OUTGOING) Iterators.count(org.neo4j.internal.helpers.collection.Iterators.count) PathExpanders(org.neo4j.graphdb.PathExpanders) Node(org.neo4j.graphdb.Node) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch) PathExpanderBuilder(org.neo4j.graphdb.PathExpanderBuilder) PathExpander(org.neo4j.graphdb.PathExpander) SideSelectorPolicies(org.neo4j.graphdb.traversal.SideSelectorPolicies) Evaluators.includeIfContainsAll(org.neo4j.graphdb.traversal.Evaluators.includeIfContainsAll) Iterables(org.neo4j.internal.helpers.collection.Iterables) Arrays.asList(java.util.Arrays.asList) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Transaction(org.neo4j.graphdb.Transaction) NODE_PATH(org.neo4j.graphdb.traversal.Uniqueness.NODE_PATH) StandardBranchCollisionDetector(org.neo4j.graphdb.impl.traversal.StandardBranchCollisionDetector) RelationshipType.withName(org.neo4j.graphdb.RelationshipType.withName) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) RELATIONSHIP_PATH(org.neo4j.graphdb.traversal.Uniqueness.RELATIONSHIP_PATH) Uniqueness(org.neo4j.graphdb.traversal.Uniqueness) Test(org.junit.jupiter.api.Test) Path(org.neo4j.graphdb.Path) InitialBranchState(org.neo4j.graphdb.traversal.InitialBranchState) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Relationship(org.neo4j.graphdb.Relationship) Evaluators(org.neo4j.graphdb.traversal.Evaluators) RelationshipType(org.neo4j.graphdb.RelationshipType) Path(org.neo4j.graphdb.Path) BranchCollisionPolicy(org.neo4j.graphdb.traversal.BranchCollisionPolicy) InitialBranchState(org.neo4j.graphdb.traversal.InitialBranchState) Transaction(org.neo4j.graphdb.Transaction) StandardBranchCollisionDetector(org.neo4j.graphdb.impl.traversal.StandardBranchCollisionDetector) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch) Test(org.junit.jupiter.api.Test)

Example 2 with Uniqueness

use of org.neo4j.graphdb.traversal.Uniqueness in project neo4j by neo4j.

the class TraversalDescriptionBuilder method describeUniqueness.

private TraversalDescription describeUniqueness(TraversalDescription result, Map<String, Object> description) {
    Object uniquenessDescription = description.get("uniqueness");
    if (uniquenessDescription != null) {
        String name = null;
        Object value = null;
        if (uniquenessDescription instanceof Map) {
            Map map = (Map) uniquenessDescription;
            name = (String) map.get("name");
            value = map.get("value");
        } else {
            name = (String) uniquenessDescription;
        }
        Uniqueness uniqueness = stringToEnum(enumifyName(name), Uniqueness.class, true);
        result = value == null ? result.uniqueness(uniqueness) : result.uniqueness(uniqueness, value);
    }
    return result;
}
Also used : Uniqueness(org.neo4j.graphdb.traversal.Uniqueness) Map(java.util.Map)

Aggregations

Uniqueness (org.neo4j.graphdb.traversal.Uniqueness)2 Arrays.asList (java.util.Arrays.asList)1 Map (java.util.Map)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Test (org.junit.jupiter.api.Test)1 OUTGOING (org.neo4j.graphdb.Direction.OUTGOING)1 Node (org.neo4j.graphdb.Node)1 Path (org.neo4j.graphdb.Path)1 PathExpander (org.neo4j.graphdb.PathExpander)1 PathExpanderBuilder (org.neo4j.graphdb.PathExpanderBuilder)1 PathExpanders (org.neo4j.graphdb.PathExpanders)1 Relationship (org.neo4j.graphdb.Relationship)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 RelationshipType.withName (org.neo4j.graphdb.RelationshipType.withName)1 Transaction (org.neo4j.graphdb.Transaction)1 StandardBranchCollisionDetector (org.neo4j.graphdb.impl.traversal.StandardBranchCollisionDetector)1 BidirectionalTraversalDescription (org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)1 BranchCollisionPolicy (org.neo4j.graphdb.traversal.BranchCollisionPolicy)1 Evaluators (org.neo4j.graphdb.traversal.Evaluators)1