@Override public Iterable<Node> nodes() { return asList( value.nodes(), DefaultValueMapper.this::mapNode ); }
@Override public Iterable<Node> reverseNodes() { return asReverseList( value.nodes(), DefaultValueMapper.this::mapNode ); }
@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(); }
public static ListValue nodes( AnyValue in ) { if ( in instanceof PathValue ) { return VirtualValues.list( ((PathValue) in).nodes() ); } else { throw new CypherTypeException( format( "Expected %s to be a path.", in ), null ); } }
public static List<NodeValue> nodes( PathValue path ) { return Arrays.asList( path.nodes() ); }
@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 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; }
@Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( obj instanceof CoreAPIPath ) { return value.equals( ((CoreAPIPath) obj).value ); } else if ( obj instanceof Path ) { Path other = (Path) obj; if ( value.nodes()[0].id() != other.startNode().getId() ) { return false; } return iteratorsEqual( this.relationships().iterator(), other.relationships().iterator() ); } else { return false; } }
@Override public Iterable<Node> reverseNodes() { return asReverseList( value.nodes(), DefaultValueMapper.this::mapNode ); }
@Override public Iterable<Node> nodes() { return asList( value.nodes(), DefaultValueMapper.this::mapNode ); }
@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(); }
public static ListValue nodes( AnyValue in ) { if ( in instanceof PathValue ) { return VirtualValues.list( ((PathValue) in).nodes() ); } 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 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; }
@Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( obj instanceof CoreAPIPath ) { return value.equals( ((CoreAPIPath) obj).value ); } else if ( obj instanceof Path ) { Path other = (Path) obj; if ( value.nodes()[0].id() != other.startNode().getId() ) { return false; } return iteratorsEqual( this.relationships().iterator(), other.relationships().iterator() ); } else { return false; } }