Search in sources :

Example 16 with InvalidArgumentException

use of org.neo4j.exceptions.InvalidArgumentException in project neo4j by neo4j.

the class DurationValue method parseDuration.

private static DurationValue parseDuration(int sign, long months, long days, Matcher matcher, boolean strict, String hour, String min, String sec, String sub) {
    String h = matcher.group(hour);
    String m = matcher.group(min);
    String s = matcher.group(sec);
    String n = matcher.group(sub);
    if (!strict) {
        int pos;
        if ((pos = fractionPoint(h)) >= 0) {
            if (m != null || s != null) {
                return null;
            }
            return approximate(months, days, parseFractional(h, pos) * 3600, 0);
        }
        if ((pos = fractionPoint(m)) >= 0) {
            if (s != null) {
                return null;
            }
            return approximate(months, days, parseFractional(m, pos) * 60, 0);
        }
    }
    long hours = optLong(h);
    long minutes = optLong(m);
    long seconds = optLong(s);
    if (strict) {
        if (hours > 24) {
            throw new InvalidArgumentException("hours out of range: " + hours);
        }
        if (minutes > 60) {
            throw new InvalidArgumentException("minutes out of range: " + minutes);
        }
        if (seconds > 60) {
            throw new InvalidArgumentException("seconds out of range: " + seconds);
        }
    }
    seconds += hours * 3600 + minutes * 60;
    long nanos = optLong(n);
    if (nanos != 0) {
        for (int i = n.length(); i < 9; i++) {
            nanos *= 10;
        }
        if (s.startsWith("-")) {
            nanos = -nanos;
        }
    }
    return duration(sign * months, sign * days, sign * seconds, sign * nanos);
}
Also used : InvalidArgumentException(org.neo4j.exceptions.InvalidArgumentException) NumberValue.safeCastFloatingPoint(org.neo4j.values.storable.NumberValue.safeCastFloatingPoint)

Example 17 with InvalidArgumentException

use of org.neo4j.exceptions.InvalidArgumentException 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

InvalidArgumentException (org.neo4j.exceptions.InvalidArgumentException)17 LocalDate (java.time.LocalDate)4 AnyValue (org.neo4j.values.AnyValue)4 LocalTime (java.time.LocalTime)3 ZoneId (java.time.ZoneId)3 LocalDateTime (java.time.LocalDateTime)2 ZoneOffset (java.time.ZoneOffset)2 Test (org.junit.jupiter.api.Test)2 TemporalParseException (org.neo4j.exceptions.TemporalParseException)2 UnsupportedTemporalUnitException (org.neo4j.exceptions.UnsupportedTemporalUnitException)2 NumberValue.safeCastFloatingPoint (org.neo4j.values.storable.NumberValue.safeCastFloatingPoint)2 OffsetTime (java.time.OffsetTime)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeParseException (java.time.format.DateTimeParseException)1 UnsupportedTemporalTypeException (java.time.temporal.UnsupportedTemporalTypeException)1 ZoneRulesException (java.time.zone.ZoneRulesException)1 Matcher (java.util.regex.Matcher)1 FormatException (org.neo4j.cypher.internal.security.FormatException)1 SecureHasher (org.neo4j.cypher.internal.security.SecureHasher)1 CypherTypeException (org.neo4j.exceptions.CypherTypeException)1