Search in sources :

Example 1 with IntegralValue

use of org.neo4j.values.storable.IntegralValue 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);
}
Also used : InvalidArgumentException(org.neo4j.exceptions.InvalidArgumentException) NumberValue(org.neo4j.values.storable.NumberValue) CypherTypeException(org.neo4j.exceptions.CypherTypeException) IntegralValue(org.neo4j.values.storable.IntegralValue)

Aggregations

CypherTypeException (org.neo4j.exceptions.CypherTypeException)1 InvalidArgumentException (org.neo4j.exceptions.InvalidArgumentException)1 IntegralValue (org.neo4j.values.storable.IntegralValue)1 NumberValue (org.neo4j.values.storable.NumberValue)1