//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFollowSpecificRelationship() public virtual void ShouldFollowSpecificRelationship() { // given using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor()) { // when - traversing from start to end read.singleNode(_start, node); assertTrue("access start node", node.Next()); node.Relationships(group); assertTrue("access relationship group", group.next()); group.Outgoing(relationship); assertTrue("access outgoing relationships", relationship.next()); // then assertEquals("source node", _start, relationship.SourceNodeReference()); assertEquals("target node", _end, relationship.TargetNodeReference()); assertEquals("node of origin", _start, relationship.OriginNodeReference()); assertEquals("neighbouring node", _end, relationship.NeighbourNodeReference()); assertEquals("relationship should have same label as group", group.Type(), relationship.Type()); assertFalse("only a single relationship", relationship.next()); group.Incoming(relationship); assertFalse("no incoming relationships", relationship.next()); group.Loops(relationship); assertFalse("no loop relationships", relationship.next()); assertFalse("only a single group", group.next()); // when - traversing from end to start read.singleNode(_end, node); assertTrue("access start node", node.Next()); node.Relationships(group); assertTrue("access relationship group", group.next()); group.Incoming(relationship); assertTrue("access incoming relationships", relationship.next()); // then assertEquals("source node", _start, relationship.SourceNodeReference()); assertEquals("target node", _end, relationship.TargetNodeReference()); assertEquals("node of origin", _end, relationship.OriginNodeReference()); assertEquals("neighbouring node", _start, relationship.NeighbourNodeReference()); assertEquals("relationship should have same label as group", group.Type(), relationship.Type()); assertFalse("only a single relationship", relationship.next()); group.Outgoing(relationship); assertFalse("no outgoing relationships", relationship.next()); group.Loops(relationship); assertFalse("no loop relationships", relationship.next()); assertFalse("only a single group", group.next()); } }
/// <summary> /// Counts the number of outgoing relationships from node where the cursor is positioned. /// <para> /// NOTE: The number of outgoing relationships also includes eventual loops. /// /// </para> /// </summary> /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param> /// <param name="cursors"> a factory for cursors </param> /// <returns> the number of outgoing - including loops - relationships from the node </returns> public static int CountOutgoing(NodeCursor nodeCursor, CursorFactory cursors) { if (nodeCursor.Dense) { using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor()) { nodeCursor.Relationships(group); int count = 0; while (group.next()) { count += group.OutgoingCount() + group.LoopCount(); } return(count); } } else { using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor()) { int count = 0; nodeCursor.AllRelationships(traversal); while (traversal.next()) { if (traversal.SourceNodeReference() == nodeCursor.NodeReference()) { count++; } } return(count); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static String computeKey(org.neo4j.internal.kernel.api.Transaction transaction, RelationshipTraversalCursor r) throws org.neo4j.internal.kernel.api.exceptions.KernelException private static string ComputeKey([email protected] transaction, RelationshipTraversalCursor r) { Direction d; if (r.SourceNodeReference() == r.TargetNodeReference()) { d = Direction.BOTH; } else if (r.SourceNodeReference() == r.OriginNodeReference()) { d = Direction.OUTGOING; } else { d = Direction.INCOMING; } return(ComputeKey(transaction.Token().relationshipTypeName(r.Type()), d)); }