org.neo4j.graphdb.Relationship.getNodes()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中org.neo4j.graphdb.Relationship.getNodes方法的一些代码示例,展示了Relationship.getNodes的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Relationship.getNodes方法的具体详情如下:
包路径:org.neo4j.graphdb.Relationship
类名称:Relationship
方法名:getNodes

Relationship.getNodes介绍

[英]Returns the two nodes that are attached to this relationship. The first element in the array will be the start node, the second element the end node.
[中]返回附加到此关系的两个节点。数组中的第一个元素是开始节点,第二个元素是结束节点。

代码示例

代码示例来源:origin: neo4j/neo4j

@PluginTarget( Relationship.class )
public Iterable<Node> methodOnRelationship( @Source Relationship rel )
{
  return Arrays.asList( rel.getNodes() );
}

代码示例来源:origin: neo4j/neo4j

private Runnable getNodesFromRelationship()
{
  return () ->
  {
    relationship.getEndNode();
    relationship.getStartNode();
    relationship.getNodes();
    relationship.getOtherNode( node );
  };
}

代码示例来源:origin: neo4j/neo4j

@PluginTarget( Relationship.class )
public Iterable<Node> methodOnRelationship( @Source Relationship rel )
{
  try ( Transaction tx = rel.getGraphDatabase().beginTx() )
  {
    List<Node> nodes = Arrays.asList( rel.getNodes() );
    tx.success();
    return nodes;
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void getOtherNodeFunctionsCorrectly()
{
  Node node = getGraphDb().createNode();
  Relationship relationship = node.createRelationshipTo( node, TEST );
  // This loop messes up the readability of the test case, but avoids duplicated
  // assertion code. Same assertions withing the transaction as after it has committed.
  for ( int i = 0; i < 2; i++ )
  {
    assertEquals( node, relationship.getOtherNode( node ) );
    assertEquals( asList( node, node ), asList( relationship.getNodes() ) );
    try
    {
      relationship.getOtherNode( getGraphDb().createNode() );
      fail( "Should throw exception if another node is passed into loop.getOtherNode" );
    }
    catch ( NotFoundException e )
    { // Good
    }
    newTransaction();
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void testDirectedRelationship1()
{
  Node node1 = getGraphDb().getNodeById( node1Id );
  Relationship rel = node1.getSingleRelationship( MyRelTypes.TEST, Direction.BOTH );
  Node[] nodes = rel.getNodes();
  assertEquals( 2, nodes.length );
  Node node2 = getGraphDb().getNodeById( node2Id );
  assertTrue( nodes[0].equals( node1 ) && nodes[1].equals( node2 ) );
  assertEquals( node1, rel.getStartNode() );
  assertEquals( node2, rel.getEndNode() );
  Relationship[] relArray = getRelationshipArray( node1.getRelationships( MyRelTypes.TEST, Direction.OUTGOING ) );
  assertEquals( 1, relArray.length );
  assertEquals( rel, relArray[0] );
  relArray = getRelationshipArray( node2.getRelationships(
    MyRelTypes.TEST, Direction.INCOMING ) );
  assertEquals( 1, relArray.length );
  assertEquals( rel, relArray[0] );
}

代码示例来源:origin: neo4j/neo4j

Relationship rel2 = node1.createRelationshipTo( node2, TEST );
Relationship rel3 = node2.createRelationshipTo( node1, TEST );
Node[] nodes = rel2.getNodes();
assertEquals( 2, nodes.length );
assertTrue( nodes[0].equals( node1 ) && nodes[1].equals( node2 ) );
nodes = rel3.getNodes();
assertEquals( 2, nodes.length );
assertTrue( nodes[0].equals( node2 ) && nodes[1].equals( node1 ) );

代码示例来源:origin: neo4j/neo4j

Node[] relNodes = rel.getNodes();
assertEquals( "A relationship should always be connected to exactly "
  + "two nodes", relNodes.length, 2 );

代码示例来源:origin: neo4j/neo4j

Node[] nodes = rel1.getNodes();
assertEquals( node1, nodes[0] );
assertEquals( node2, nodes[1] );

相关文章