relationshipIndexes.putIfAbsent( node.id(), relationshipIndexes.size() + 1 ); while ( edge.id() != id ) pack( edge.id() ); edge.type().writeTo( this ); edge.properties().writeTo( this );
@Override public void writePath( NodeValue[] nodes, RelationshipValue[] relationships ) { if ( nodes.length == 0 ) { return; } //Path guarantees that nodes.length = edges.length = 1 nodes[0].writeTo( this ); for ( int i = 0; i < relationships.length; i++ ) { relationships[i].writeTo( this ); append( ">" ); nodes[i + 1].writeTo( this ); } }
@Override public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E { writer.writeRelationship( id, startNode().id(), endNode().id(), type(), properties() ); }
public static MapValue asMapValue( AnyValue value, DbAccess access ) { if ( value instanceof MapValue ) { return (MapValue) value; } else if ( value instanceof NodeValue ) { return access.nodeAsMap( ((NodeValue) value).id() ); } else if ( value instanceof RelationshipValue ) { return access.relationshipAsMap( ((RelationshipValue) value).id() ); } else { throw cantCoerce( value, "Map" ); } }
public static TextValue type( AnyValue item ) { if ( item instanceof RelationshipValue ) { return ((RelationshipValue) item).type(); } else { throw new ParameterWrongTypeException( "Expected a Relationship, got: " + item, null ); } }
return ((RelationshipValue) object).properties().get( key );
@Override public int compareTo( VirtualValue other, Comparator<AnyValue> comparator ) { if ( other == null || !(other instanceof PathValue) ) { throw new IllegalArgumentException( "Cannot compare different virtual values" ); } PathValue otherPath = (PathValue) other; NodeValue[] nodes = nodes(); RelationshipValue[] relationships = relationships(); NodeValue[] otherNodes = otherPath.nodes(); RelationshipValue[] otherRelationships = otherPath.relationships(); int x = nodes[0].compareTo( otherNodes[0], comparator ); if ( x == 0 ) { int i = 0; int length = Math.min( relationships.length, otherRelationships.length ); while ( x == 0 && i < length ) { x = relationships[i].compareTo( otherRelationships[i], comparator ); ++i; } if ( x == 0 ) { x = Integer.compare( relationships.length, otherRelationships.length ); } } return x; }
for ( int i = 0; i < relationships.length; i++ ) relationship[i] = proxySpi.newRelationshipProxy( relationships[i].id() );
public static TextValue type( AnyValue item ) { if ( item instanceof RelationshipValue ) { return ((RelationshipValue) item).type(); } else { throw new ParameterWrongTypeException( "Expected a Relationship, got: " + item, null ); } }
return ((RelationshipValue) object).properties().get( key );
@Override public int compareTo( VirtualValue other, Comparator<AnyValue> comparator ) { if ( other == null || !(other instanceof PathValue) ) { throw new IllegalArgumentException( "Cannot compare different virtual values" ); } PathValue otherPath = (PathValue) other; NodeValue[] nodes = nodes(); RelationshipValue[] relationships = relationships(); NodeValue[] otherNodes = otherPath.nodes(); RelationshipValue[] otherRelationships = otherPath.relationships(); int x = nodes[0].compareTo( otherNodes[0], comparator ); if ( x == 0 ) { int i = 0; int length = Math.min( relationships.length, otherRelationships.length ); while ( x == 0 && i < length ) { x = relationships[i].compareTo( otherRelationships[i], comparator ); ++i; } if ( x == 0 ) { x = Integer.compare( relationships.length, otherRelationships.length ); } } return x; }
relationshipIndexes.putIfAbsent( node.id(), relationshipIndexes.size() + 1 ); while ( edge.id() != id ) pack( edge.id() ); edge.type().writeTo( this ); edge.properties().writeTo( this );
@Override public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E { writer.writeRelationship( id, startNode().id(), endNode().id(), type(), properties() ); }
for ( int i = 0; i < relationships.length; i++ ) relationship[i] = newRelationshipProxyById( relationships[i].id() );
@Test public void shouldHandleRelationships() { // Given RelationshipValue relValue = relationshipValue( 1L, nodeValue( 42L, stringArray( "L" ), EMPTY_MAP ), nodeValue( 42L, stringArray( "L" ), EMPTY_MAP ), stringValue( "R" ), EMPTY_MAP ); // When relValue.writeTo( converter ); // Then assertThat( converter.value(), equalTo( VirtualValues.relationship( 1L ) ) ); }