本文整理了Java中org.neo4j.graphdb.Relationship.getEndNodeId
方法的一些代码示例,展示了Relationship.getEndNodeId
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Relationship.getEndNodeId
方法的具体详情如下:
包路径:org.neo4j.graphdb.Relationship
类名称:Relationship
方法名:getEndNodeId
[英]Returns the id of the end node of this relationship. For a definition of how end node relates to Direction as arguments to the Node#getRelationships() in Node, see the class documentation of Relationship.
Note that this id can get reused in the future, if this relationship and the given node are deleted.
[中]返回此关系的结束节点的id。有关结束节点如何作为节点中节点#getRelationships()的参数与方向关联的定义,请参阅Relationship的类文档。
请注意,如果删除此关系和给定节点,该id将来可以被重用。
代码示例来源:origin: neo4j/neo4j
/**
* A convenience operation that, given an id of a node that is attached to this
* relationship, returns the id of the other node. For example if <code>id</code> is
* the start node id, the end node id will be returned, and vice versa.
* <p>
* This operation will throw a runtime exception if <code>id</code> is
* not the id of either of this relationship's nodes.
* <p>
* Note that this id can get reused in the future, if this relationship and the given node are deleted.
*
* @param id the id of the start or end node of this relationship
* @return the id of the other node
* @throws RuntimeException if the given node id is not the id of either the start or end
* node of this relationship.
*/
default long getOtherNodeId( long id )
{
long start = getStartNodeId();
long end = getEndNodeId();
if ( id == start )
{
return end;
}
else if ( id == end )
{
return start;
}
throw new NotFoundException( "Node[" + id + "] not connected to this relationship[" + getId() + "]" );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldIterateThroughRelationships()
{
// given
Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
Iterator<Relationship> iterator = path.relationships().iterator();
Relationship relationship;
// then
assertTrue( iterator.hasNext() );
assertThat( relationship = iterator.next(), instanceOf( Relationship.class ) );
assertEquals( 100, relationship.getId() );
assertEquals( 1, relationship.getStartNodeId() );
assertEquals( 2, relationship.getEndNodeId() );
assertTrue( iterator.hasNext() );
assertThat( relationship = iterator.next(), instanceOf( Relationship.class ) );
assertEquals( 200, relationship.getId() );
assertEquals( 3, relationship.getStartNodeId() );
assertEquals( 2, relationship.getEndNodeId() );
assertFalse( iterator.hasNext() );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldIterateThroughRelationshipsInReverse()
{
// given
Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
Iterator<Relationship> iterator = path.reverseRelationships().iterator();
Relationship relationship;
// then
assertTrue( iterator.hasNext() );
assertThat( relationship = iterator.next(), instanceOf( Relationship.class ) );
assertEquals( 200, relationship.getId() );
assertEquals( 3, relationship.getStartNodeId() );
assertEquals( 2, relationship.getEndNodeId() );
assertTrue( iterator.hasNext() );
assertThat( relationship = iterator.next(), instanceOf( Relationship.class ) );
assertEquals( 100, relationship.getId() );
assertEquals( 1, relationship.getStartNodeId() );
assertEquals( 2, relationship.getEndNodeId() );
assertFalse( iterator.hasNext() );
}
代码示例来源:origin: neo4j/neo4j
private boolean relationshipExistsByQuery( RelationshipIndex index, Node startNode, Node endNode, boolean specifyStartNode )
{
boolean found = false;
try ( Transaction tx = db.beginTx(); IndexHits<Relationship> query = index
.query( "key", QueryContext.numericRange( "key", 0, 3 ), specifyStartNode ? startNode : null, null ) )
{
for ( Relationship relationship : query )
{
if ( relationship.getStartNodeId() == startNode.getId() && relationship.getEndNodeId() == endNode.getId() )
{
found = true;
break;
}
}
tx.success();
}
return found;
}
代码示例来源:origin: org.neo4j/neo4j-graphdb-api
/**
* A convenience operation that, given an id of a node that is attached to this
* relationship, returns the id of the other node. For example if <code>id</code> is
* the start node id, the end node id will be returned, and vice versa.
* <p>
* This operation will throw a runtime exception if <code>id</code> is
* not the id of either of this relationship's nodes.
* <p>
* Note that this id can get reused in the future, if this relationship and the given node are deleted.
*
* @param id the id of the start or end node of this relationship
* @return the id of the other node
* @throws RuntimeException if the given node id is not the id of either the start or end
* node of this relationship.
*/
default long getOtherNodeId( long id )
{
long start = getStartNodeId();
long end = getEndNodeId();
if ( id == start )
{
return end;
}
else if ( id == end )
{
return start;
}
throw new NotFoundException( "Node[" + id + "] not connected to this relationship[" + getId() + "]" );
}
}
内容来源于网络,如有侵权,请联系作者删除!