use of org.neo4j.exceptions.CypherTypeException in project neo4j by neo4j.
the class CypherFunctions method last.
@CalledFromGeneratedCode
public static AnyValue last(AnyValue container) {
assert container != NO_VALUE : "NO_VALUE checks need to happen outside this call";
if (container instanceof SequenceValue) {
SequenceValue sequence = (SequenceValue) container;
int length = sequence.length();
if (length == 0) {
return NO_VALUE;
}
return sequence.value(length - 1);
} else {
throw new CypherTypeException(format("Invalid input for function 'last()': Expected %s to be a list", container));
}
}
use of org.neo4j.exceptions.CypherTypeException in project neo4j by neo4j.
the class CypherFunctions method listAccess.
private static AnyValue listAccess(SequenceValue container, AnyValue index) {
NumberValue number = asNumberValue(index, () -> "Cannot access a list '" + container.toString() + "' using a non-number index, got " + index.toString());
if (!(number instanceof IntegralValue)) {
throw new CypherTypeException(format("Cannot access a list using an non-integer number index, got %s", number), null);
}
long idx = number.longValue();
if (idx > Integer.MAX_VALUE || idx < Integer.MIN_VALUE) {
throw new InvalidArgumentException(format("Cannot index a list using a value greater than %d or lesser than %d, got %d", Integer.MAX_VALUE, Integer.MIN_VALUE, idx));
}
if (idx < 0) {
idx = container.length() + idx;
}
if (idx >= container.length() || idx < 0) {
return NO_VALUE;
}
return container.value((int) idx);
}
Aggregations