public int size() { return relationships().length; }
@Override public Iterable<Relationship> reverseRelationships() { return asReverseList( value.relationships(), DefaultValueMapper.this::mapRelationship ); }
@Override public Iterable<Relationship> relationships() { return asList( value.relationships(), DefaultValueMapper.this::mapRelationship ); }
@Override public String toString() { NodeValue[] nodes = nodes(); RelationshipValue[] relationships = relationships(); StringBuilder sb = new StringBuilder( getTypeName() + "{" ); int i = 0; for ( ; i < relationships.length; i++ ) { sb.append( nodes[i] ); sb.append( relationships[i] ); } sb.append( nodes[i] ); sb.append( '}' ); return sb.toString(); }
@Override public boolean equals( VirtualValue other ) { if ( other == null || !(other instanceof PathValue) ) { return false; } PathValue that = (PathValue) other; return size() == that.size() && Arrays.equals( nodes(), that.nodes() ) && Arrays.equals( relationships(), that.relationships() ); }
public static ListValue relationships( AnyValue in ) { if ( in instanceof PathValue ) { return VirtualValues.list( ((PathValue) in).relationships() ); } else { throw new CypherTypeException( format( "Expected %s to be a path.", in ), null ); } }
@Override public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E { writer.writePath( nodes(), relationships() ); }
@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; }
public ListValue asList() { NodeValue[] nodes = nodes(); RelationshipValue[] relationships = relationships(); int size = nodes.length + relationships.length; AnyValue[] anyValues = new AnyValue[size]; for ( int i = 0; i < size; i++ ) { if ( i % 2 == 0 ) { anyValues[i] = nodes[i / 2]; } else { anyValues[i] = relationships[i / 2]; } } return VirtualValues.list( anyValues ); }
private int index; private final NodeValue[] nodes = value.nodes(); private final RelationshipValue[] relationships = value.relationships();
@Override public int computeHash() { NodeValue[] nodes = nodes(); RelationshipValue[] relationships = relationships(); int result = nodes[0].hashCode(); for ( int i = 1; i < nodes.length; i++ ) { result += 31 * (result + relationships[i - 1].hashCode()); result += 31 * (result + nodes[i].hashCode()); } return result; }
public int size() { return relationships().length; }
@Override public Iterable<Relationship> relationships() { return asList( value.relationships(), DefaultValueMapper.this::mapRelationship ); }
@Override public Iterable<Relationship> reverseRelationships() { return asReverseList( value.relationships(), DefaultValueMapper.this::mapRelationship ); }
@Override public String toString() { NodeValue[] nodes = nodes(); RelationshipValue[] relationships = relationships(); StringBuilder sb = new StringBuilder( getTypeName() + "{" ); int i = 0; for ( ; i < relationships.length; i++ ) { sb.append( nodes[i] ); sb.append( relationships[i] ); } sb.append( nodes[i] ); sb.append( '}' ); return sb.toString(); }
@Override public boolean equals( VirtualValue other ) { if ( other == null || !(other instanceof PathValue) ) { return false; } PathValue that = (PathValue) other; return size() == that.size() && Arrays.equals( nodes(), that.nodes() ) && Arrays.equals( relationships(), that.relationships() ); }
public static ListValue relationships( AnyValue in ) { if ( in instanceof PathValue ) { return VirtualValues.list( ((PathValue) in).relationships() ); } else { throw new CypherTypeException( format( "Expected %s to be a path.", in ), null ); } }
@Override public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E { writer.writePath( nodes(), relationships() ); }
public ListValue asList() { NodeValue[] nodes = nodes(); RelationshipValue[] relationships = relationships(); int size = nodes.length + relationships.length; AnyValue[] anyValues = new AnyValue[size]; for ( int i = 0; i < size; i++ ) { if ( i % 2 == 0 ) { anyValues[i] = nodes[i / 2]; } else { anyValues[i] = relationships[i / 2]; } } return VirtualValues.list( anyValues ); }
@Override public int computeHash() { NodeValue[] nodes = nodes(); RelationshipValue[] relationships = relationships(); int result = nodes[0].hashCode(); for ( int i = 1; i < nodes.length; i++ ) { result += 31 * (result + relationships[i - 1].hashCode()); result += 31 * (result + nodes[i].hashCode()); } return result; }