From e4cbe5a51db231ffef0c1fe69ae1779e154106e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louise=20S=C3=B6derstr=C3=B6m?= Date: Wed, 4 Apr 2018 15:36:18 +0200 Subject: [PATCH] Rename exception to use it for both temporal and spatial --- .../org/neo4j/cypher/exceptionHandler.scala | 2 +- .../org/neo4j/values/StructureBuilder.java | 4 +- .../neo4j/values/storable/DateTimeValue.java | 18 +++---- .../org/neo4j/values/storable/DateValue.java | 12 ++--- .../neo4j/values/storable/DurationValue.java | 18 +++---- .../values/storable/LocalDateTimeValue.java | 11 ++-- .../neo4j/values/storable/LocalTimeValue.java | 10 ++-- .../neo4j/values/storable/TemporalValue.java | 52 +++++++++---------- .../org/neo4j/values/storable/TimeValue.java | 8 +-- ...va => InvalidValuesArgumentException.java} | 6 +-- .../values/storable/DateTimeValueTest.java | 23 ++++---- .../neo4j/values/storable/DateValueTest.java | 27 +++++----- 12 files changed, 91 insertions(+), 100 deletions(-) rename community/values/src/main/java/org/neo4j/values/utils/{InvalidTemporalArgumentException.java => InvalidValuesArgumentException.java} (81%) diff --git a/community/cypher/runtime-util/src/main/scala/org/neo4j/cypher/exceptionHandler.scala b/community/cypher/runtime-util/src/main/scala/org/neo4j/cypher/exceptionHandler.scala index 10be86a53b53c..aa50f6f20a8dc 100644 --- a/community/cypher/runtime-util/src/main/scala/org/neo4j/cypher/exceptionHandler.scala +++ b/community/cypher/runtime-util/src/main/scala/org/neo4j/cypher/exceptionHandler.scala @@ -110,7 +110,7 @@ object exceptionHandler extends MapToPublicExceptions[CypherException] { exception match { case e: UnsupportedTemporalUnitException => exceptionHandler.cypherTypeException(e.getMessage, e) - case e: InvalidTemporalArgumentException => + case e: InvalidValuesArgumentException => exceptionHandler.invalidArgumentException(e.getMessage, e) case e: TemporalArithmeticException => exceptionHandler.arithmeticException(e.getMessage, e) diff --git a/community/values/src/main/java/org/neo4j/values/StructureBuilder.java b/community/values/src/main/java/org/neo4j/values/StructureBuilder.java index 6505c37b953cd..b13eea53256ae 100644 --- a/community/values/src/main/java/org/neo4j/values/StructureBuilder.java +++ b/community/values/src/main/java/org/neo4j/values/StructureBuilder.java @@ -21,7 +21,7 @@ import java.util.Map; -import org.neo4j.values.utils.InvalidTemporalArgumentException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.virtual.MapValue; public interface StructureBuilder @@ -34,7 +34,7 @@ static T build( StructureBuilder builder, MapValue map ) { if ( map.size() == 0 ) { - throw new InvalidTemporalArgumentException( "At least one temporal unit must be specified." ); + throw new InvalidValuesArgumentException( "At least one temporal unit must be specified." ); } return build( builder, map.entrySet() ); } diff --git a/community/values/src/main/java/org/neo4j/values/storable/DateTimeValue.java b/community/values/src/main/java/org/neo4j/values/storable/DateTimeValue.java index ea3f4ed204393..087255393d584 100644 --- a/community/values/src/main/java/org/neo4j/values/storable/DateTimeValue.java +++ b/community/values/src/main/java/org/neo4j/values/storable/DateTimeValue.java @@ -47,7 +47,7 @@ import org.neo4j.values.AnyValue; import org.neo4j.values.StructureBuilder; import org.neo4j.values.ValueMapper; -import org.neo4j.values.utils.InvalidTemporalArgumentException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.TemporalParseException; import org.neo4j.values.utils.UnsupportedTemporalUnitException; import org.neo4j.values.virtual.MapValue; @@ -118,7 +118,7 @@ public static DateTimeValue ofEpoch( IntegralValue epochSecondUTC, IntegralValue long ns = safeCastIntegral( "nanosecond", nano, 0 ); if ( ns < 0 || ns >= 1000_000_000 ) { - throw new InvalidTemporalArgumentException( "Invalid nanosecond: " + ns ); + throw new InvalidValuesArgumentException( "Invalid nanosecond: " + ns ); } return new DateTimeValue( assertValidArgument( () -> ofInstant( ofEpochSecond( epochSecondUTC.longValue(), ns ), UTC ) ) ); } @@ -250,7 +250,7 @@ public DateTimeValue buildInternal() AnyValue dtField = fields.get( Field.datetime ); if ( !(dtField instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct date time from: %s", dtField ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct date time from: %s", dtField ) ); } TemporalValue dt = (TemporalValue) dtField; LocalTime timePart = dt.getTimePart( defaultZone ).toLocalTime(); @@ -265,7 +265,7 @@ else if ( selectingEpoch ) AnyValue epochField = fields.get( Field.epochSeconds ); if ( !(epochField instanceof IntegralValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct date time from: %s", epochField ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct date time from: %s", epochField ) ); } IntegralValue epochSeconds = (IntegralValue) epochField; result = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.ofEpochMilli( epochSeconds.longValue() * 1000 ), timezone() ) ); @@ -275,7 +275,7 @@ else if ( selectingEpoch ) AnyValue epochField = fields.get( Field.epochMillis ); if ( !(epochField instanceof IntegralValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct date time from: %s", epochField ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct date time from: %s", epochField ) ); } IntegralValue epochMillis = (IntegralValue) epochField; result = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.ofEpochMilli( epochMillis.longValue() ), timezone() ) ); @@ -292,7 +292,7 @@ else if ( selectingTime || selectingDate ) AnyValue timeField = fields.get( Field.time ); if ( !(timeField instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct time from: %s", timeField ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct time from: %s", timeField ) ); } TemporalValue t = (TemporalValue) timeField; time = t.getTimePart( defaultZone ).toLocalTime(); @@ -311,7 +311,7 @@ else if ( selectingTime || selectingDate ) AnyValue dateField = fields.get( Field.date ); if ( !(dateField instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct date from: %s", dateField ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct date from: %s", dateField ) ); } TemporalValue t = (TemporalValue) dateField; date = t.getDatePart(); @@ -349,7 +349,7 @@ else if ( selectingTime || selectingDate ) } catch ( DateTimeParseException e ) { - throw new InvalidTemporalArgumentException( e.getMessage(), e ); + throw new InvalidValuesArgumentException( e.getMessage(), e ); } } else @@ -602,7 +602,7 @@ private static DateTimeValue parse( Matcher matcher, Supplier defaultZon } if ( !expected.equals( offset ) ) { - throw new InvalidTemporalArgumentException( "Timezone and offset do not match: " + matcher.group() ); + throw new InvalidValuesArgumentException( "Timezone and offset do not match: " + matcher.group() ); } } } diff --git a/community/values/src/main/java/org/neo4j/values/storable/DateValue.java b/community/values/src/main/java/org/neo4j/values/storable/DateValue.java index 0c680a09c0d77..a1537bf35d266 100644 --- a/community/values/src/main/java/org/neo4j/values/storable/DateValue.java +++ b/community/values/src/main/java/org/neo4j/values/storable/DateValue.java @@ -20,7 +20,6 @@ package org.neo4j.values.storable; import java.time.Clock; -import java.time.DateTimeException; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalTime; @@ -40,8 +39,7 @@ import org.neo4j.helpers.collection.Pair; import org.neo4j.values.StructureBuilder; import org.neo4j.values.ValueMapper; -import org.neo4j.values.utils.InvalidTemporalArgumentException; -import org.neo4j.values.utils.TemporalParseException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.UnsupportedTemporalUnitException; import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.VirtualValues; @@ -449,7 +447,7 @@ private static LocalDate localWeekDate( int year, int week, int dayOfWeek ) // week 53 of years that don't have 53 weeks, so we have to guard for this: if ( week == 53 && withWeek.get( IsoFields.WEEK_BASED_YEAR ) != year ) { - throw new InvalidTemporalArgumentException( String.format( "Year %d does not contain %d weeks.", year, week ) ); + throw new InvalidValuesArgumentException( String.format( "Year %d does not contain %d weeks.", year, week ) ); } return withWeek.with( ChronoField.DAY_OF_WEEK, dayOfWeek ); } @@ -459,13 +457,13 @@ private static LocalDate localQuarterDate( int year, int quarter, int dayOfQuart // special handling for the range of Q1 and Q2, since they are shorter than Q3 and Q4 if ( quarter == 2 && dayOfQuarter == 92 ) { - throw new InvalidTemporalArgumentException( "Quarter 2 only has 91 days." ); + throw new InvalidValuesArgumentException( "Quarter 2 only has 91 days." ); } // instantiate the yearDate now, because we use it to know if it is a leap year LocalDate yearDate = LocalDate.ofYearDay( year, dayOfQuarter ); // guess on the day if ( quarter == 1 && dayOfQuarter > 90 && (!yearDate.isLeapYear() || dayOfQuarter == 92) ) { - throw new InvalidTemporalArgumentException( String.format( + throw new InvalidValuesArgumentException( String.format( "Quarter 1 of %d only has %d days.", year, yearDate.isLeapYear() ? 91 : 90 ) ); } return yearDate @@ -513,7 +511,7 @@ private LocalDate getDateOf( org.neo4j.values.AnyValue temporal ) TemporalValue v = (TemporalValue) temporal; return v.getDatePart(); } - throw new InvalidTemporalArgumentException( String.format( "Cannot construct date from: %s", temporal ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct date from: %s", temporal ) ); } @Override diff --git a/community/values/src/main/java/org/neo4j/values/storable/DurationValue.java b/community/values/src/main/java/org/neo4j/values/storable/DurationValue.java index cc212ea7afd5e..8bbddfc405afe 100644 --- a/community/values/src/main/java/org/neo4j/values/storable/DurationValue.java +++ b/community/values/src/main/java/org/neo4j/values/storable/DurationValue.java @@ -38,7 +38,7 @@ import org.neo4j.values.AnyValue; import org.neo4j.values.StructureBuilder; import org.neo4j.values.ValueMapper; -import org.neo4j.values.utils.InvalidTemporalArgumentException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.TemporalArithmeticException; import org.neo4j.values.utils.UnsupportedTemporalUnitException; import org.neo4j.values.virtual.MapValue; @@ -376,13 +376,13 @@ private static DurationValue parseDateDuration( String year, Matcher matcher, bo months = parseLong( month ); if ( months > 12 ) { - throw new InvalidTemporalArgumentException( "months is out of range: " + month ); + throw new InvalidValuesArgumentException( "months is out of range: " + month ); } months += parseLong( year ) * 12; days = parseLong( day ); if ( days > 31 ) { - throw new InvalidTemporalArgumentException( "days is out of range: " + day ); + throw new InvalidValuesArgumentException( "days is out of range: " + day ); } } if ( time ) @@ -439,15 +439,15 @@ private static DurationValue parseDuration( { if ( hours > 24 ) { - throw new InvalidTemporalArgumentException( "hours out of range: " + hours ); + throw new InvalidValuesArgumentException( "hours out of range: " + hours ); } if ( minutes > 60 ) { - throw new InvalidTemporalArgumentException( "minutes out of range: " + minutes ); + throw new InvalidValuesArgumentException( "minutes out of range: " + minutes ); } if ( seconds > 60 ) { - throw new InvalidTemporalArgumentException( "seconds out of range: " + seconds ); + throw new InvalidValuesArgumentException( "seconds out of range: " + seconds ); } } seconds += hours * 3600 + minutes * 60; @@ -506,7 +506,7 @@ static DurationValue durationBetween( Temporal from, Temporal to ) } catch ( DateTimeException e ) { - throw new InvalidTemporalArgumentException( e.getMessage(), e ); + throw new InvalidValuesArgumentException( e.getMessage(), e ); } Period period = Period.between( fromDate, toDate ); months = period.getYears() * 12L + period.getMonths(); @@ -920,7 +920,7 @@ public DurationValue mul( NumberValue number ) double factor = number.doubleValue(); return approximate( months * factor, days * factor, seconds * factor, nanos * factor ); } - throw new InvalidTemporalArgumentException( "Factor must be either integer of floating point number." ); + throw new InvalidValuesArgumentException( "Factor must be either integer of floating point number." ); } public DurationValue div( NumberValue number ) @@ -977,7 +977,7 @@ private static long assertValidUntil( Temporal from, Temporal to, TemporalUnit u } catch ( DateTimeException e ) { - throw new InvalidTemporalArgumentException( e.getMessage(), e ); + throw new InvalidValuesArgumentException( e.getMessage(), e ); } } } diff --git a/community/values/src/main/java/org/neo4j/values/storable/LocalDateTimeValue.java b/community/values/src/main/java/org/neo4j/values/storable/LocalDateTimeValue.java index 96182f755f936..1536d0e7d4ad5 100644 --- a/community/values/src/main/java/org/neo4j/values/storable/LocalDateTimeValue.java +++ b/community/values/src/main/java/org/neo4j/values/storable/LocalDateTimeValue.java @@ -32,7 +32,6 @@ import java.time.temporal.ChronoField; import java.time.temporal.IsoFields; import java.time.temporal.TemporalUnit; -import java.time.temporal.UnsupportedTemporalTypeException; import java.util.Map; import java.util.function.Supplier; import java.util.regex.Matcher; @@ -42,7 +41,7 @@ import org.neo4j.values.AnyValue; import org.neo4j.values.StructureBuilder; import org.neo4j.values.ValueMapper; -import org.neo4j.values.utils.InvalidTemporalArgumentException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.UnsupportedTemporalUnitException; import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.VirtualValues; @@ -176,7 +175,7 @@ public LocalDateTimeValue buildInternal() AnyValue dtField = fields.get( Field.datetime ); if ( !(dtField instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct local date time from: %s", dtField ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct local date time from: %s", dtField ) ); } TemporalValue dt = (TemporalValue) dtField; result = LocalDateTime.of( dt.getDatePart(), dt.getLocalTimePart() ); @@ -189,7 +188,7 @@ else if ( selectingTime || selectingDate ) AnyValue timeField = fields.get( Field.time ); if ( !(timeField instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct local time from: %s", timeField ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct local time from: %s", timeField ) ); } TemporalValue t = (TemporalValue) timeField; time = t.getLocalTimePart(); @@ -204,7 +203,7 @@ else if ( selectingTime || selectingDate ) AnyValue dateField = fields.get( Field.date ); if ( !(dateField instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct date from: %s", dateField ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct date from: %s", dateField ) ); } TemporalValue t = (TemporalValue) dateField; date = t.getDatePart(); @@ -244,7 +243,7 @@ private LocalDateTime getLocalDateTimeOf( AnyValue temporal ) LocalTime timePart = v.getLocalTimePart(); return LocalDateTime.of( datePart, timePart ); } - throw new InvalidTemporalArgumentException( String.format( "Cannot construct date from: %s", temporal ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct date from: %s", temporal ) ); } @Override diff --git a/community/values/src/main/java/org/neo4j/values/storable/LocalTimeValue.java b/community/values/src/main/java/org/neo4j/values/storable/LocalTimeValue.java index c4488c484868b..452bb9d7e693b 100644 --- a/community/values/src/main/java/org/neo4j/values/storable/LocalTimeValue.java +++ b/community/values/src/main/java/org/neo4j/values/storable/LocalTimeValue.java @@ -20,7 +20,6 @@ package org.neo4j.values.storable; import java.time.Clock; -import java.time.DateTimeException; import java.time.Instant; import java.time.LocalDate; import java.time.LocalTime; @@ -30,7 +29,6 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalUnit; -import java.time.temporal.UnsupportedTemporalTypeException; import java.util.Map; import java.util.function.Supplier; import java.util.regex.Matcher; @@ -39,14 +37,12 @@ import org.neo4j.values.AnyValue; import org.neo4j.values.StructureBuilder; import org.neo4j.values.ValueMapper; -import org.neo4j.values.utils.InvalidTemporalArgumentException; -import org.neo4j.values.utils.TemporalParseException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.UnsupportedTemporalUnitException; import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.VirtualValues; import static java.lang.Integer.parseInt; -import static java.time.ZoneOffset.UTC; import static java.util.Objects.requireNonNull; import static org.neo4j.values.storable.DateTimeValue.parseZoneName; @@ -146,7 +142,7 @@ public LocalTimeValue buildInternal() AnyValue time = fields.get( Field.time ); if ( !(time instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct local time from: %s", time ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct local time from: %s", time ) ); } result = ((TemporalValue) time).getLocalTimePart(); } @@ -166,7 +162,7 @@ protected LocalTimeValue selectTime( if ( !(time instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct local time from: %s", time ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct local time from: %s", time ) ); } TemporalValue v = (TemporalValue) time; LocalTime lt = v.getLocalTimePart(); diff --git a/community/values/src/main/java/org/neo4j/values/storable/TemporalValue.java b/community/values/src/main/java/org/neo4j/values/storable/TemporalValue.java index 11e71e8a24910..f809b14f221f5 100644 --- a/community/values/src/main/java/org/neo4j/values/storable/TemporalValue.java +++ b/community/values/src/main/java/org/neo4j/values/storable/TemporalValue.java @@ -52,7 +52,7 @@ import org.neo4j.helpers.collection.Pair; import org.neo4j.values.AnyValue; import org.neo4j.values.StructureBuilder; -import org.neo4j.values.utils.InvalidTemporalArgumentException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.TemporalArithmeticException; import org.neo4j.values.utils.TemporalParseException; import org.neo4j.values.utils.UnsupportedTemporalUnitException; @@ -178,7 +178,7 @@ public final long until( Temporal endExclusive, TemporalUnit unit ) { if ( !(endExclusive instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( "Can only compute durations between TemporalValues." ); + throw new InvalidValuesArgumentException( "Can only compute durations between TemporalValues." ); } TemporalValue from = this; TemporalValue to = (TemporalValue) endExclusive; @@ -480,7 +480,7 @@ public final Result build() { if ( state == null ) { - throw new InvalidTemporalArgumentException( "Builder state empty" ); + throw new InvalidValuesArgumentException( "Builder state empty" ); } state.checkAssignments( this.supportsDate() ); return buildInternal(); @@ -514,7 +514,7 @@ public final StructureBuilder add( String fieldName, AnyValue v Field field = Field.fields.get( fieldName.toLowerCase() ); if ( field == null ) { - throw new InvalidTemporalArgumentException( "No such field: " + fieldName ); + throw new InvalidValuesArgumentException( "No such field: " + fieldName ); } // Change state field.assign( this, value ); @@ -626,7 +626,7 @@ void assign( Builder builder, AnyValue value ) } if ( builder.timezone != null ) { - throw new InvalidTemporalArgumentException( "Cannot assign timezone twice." ); + throw new InvalidValuesArgumentException( "Cannot assign timezone twice." ); } builder.timezone = value; } @@ -826,7 +826,7 @@ void checkAssignments( boolean requiresDate ) } else { - throw new InvalidTemporalArgumentException( Field.year.name() + " must be specified" ); + throw new InvalidValuesArgumentException( Field.year.name() + " must be specified" ); } } time.checkAssignments(); @@ -897,17 +897,17 @@ DateTimeBuilder assign( Field field, AnyValue value ) { if ( field == Field.date || field == Field.time ) { - throw new InvalidTemporalArgumentException( field.name() + " cannot be selected together with datetime or epochSeconds or epochMillis." ); + throw new InvalidValuesArgumentException( field.name() + " cannot be selected together with datetime or epochSeconds or epochMillis." ); } else if ( field == Field.datetime ) { if ( epochSeconds != null ) { - throw new InvalidTemporalArgumentException( field.name() + " cannot be selected together with epochSeconds." ); + throw new InvalidValuesArgumentException( field.name() + " cannot be selected together with epochSeconds." ); } else if ( epochMillis != null ) { - throw new InvalidTemporalArgumentException( field.name() + " cannot be selected together with epochMillis." ); + throw new InvalidValuesArgumentException( field.name() + " cannot be selected together with epochMillis." ); } datetime = assignment( Field.datetime, datetime, value ); } @@ -915,11 +915,11 @@ else if ( field == Field.epochSeconds ) { if ( epochMillis != null ) { - throw new InvalidTemporalArgumentException( field.name() + " cannot be selected together with epochMillis." ); + throw new InvalidValuesArgumentException( field.name() + " cannot be selected together with epochMillis." ); } else if ( datetime != null ) { - throw new InvalidTemporalArgumentException( field.name() + " cannot be selected together with datetime." ); + throw new InvalidValuesArgumentException( field.name() + " cannot be selected together with datetime." ); } epochSeconds = assignment( Field.epochSeconds, epochSeconds, value ); } @@ -927,11 +927,11 @@ else if ( field == Field.epochMillis ) { if ( epochSeconds != null ) { - throw new InvalidTemporalArgumentException( field.name() + " cannot be selected together with epochSeconds." ); + throw new InvalidValuesArgumentException( field.name() + " cannot be selected together with epochSeconds." ); } else if ( datetime != null ) { - throw new InvalidTemporalArgumentException( field.name() + " cannot be selected together with datetime." ); + throw new InvalidValuesArgumentException( field.name() + " cannot be selected together with datetime." ); } epochMillis = assignment( Field.epochMillis, epochMillis, value ); } @@ -955,7 +955,7 @@ DateTimeBuilder assign( Field field, AnyValue value ) { if ( field == Field.datetime || field == Field.epochSeconds || field == Field.epochMillis ) { - throw new InvalidTemporalArgumentException( field.name() + " cannot be selected together with date or time." ); + throw new InvalidValuesArgumentException( field.name() + " cannot be selected together with date or time." ); } else { @@ -1081,7 +1081,7 @@ void assertFullyAssigned() { if ( date == null ) { - throw new InvalidTemporalArgumentException( Field.month.name() + " must be specified" ); + throw new InvalidValuesArgumentException( Field.month.name() + " must be specified" ); } } } @@ -1289,7 +1289,7 @@ private static AnyValue assignment( Field field, AnyValue oldValue, AnyValue new { if ( oldValue != null ) { - throw new InvalidTemporalArgumentException( "cannot re-assign " + field ); + throw new InvalidValuesArgumentException( "cannot re-assign " + field ); } return newValue; } @@ -1299,7 +1299,7 @@ static void assertDefinedInOrder( Pair... val { if ( values[0].first() == null ) { - throw new InvalidTemporalArgumentException( values[0].other() + " must be specified" ); + throw new InvalidValuesArgumentException( values[0].other() + " must be specified" ); } String firstNotAssigned = null; @@ -1315,7 +1315,7 @@ static void assertDefinedInOrder( Pair... val } else if ( firstNotAssigned != null ) { - throw new InvalidTemporalArgumentException( value.other() + " cannot be specified without " + firstNotAssigned ); + throw new InvalidValuesArgumentException( value.other() + " cannot be specified without " + firstNotAssigned ); } } } @@ -1327,7 +1327,7 @@ static void assertAllDefined( Pair... values { if ( value.first() == null ) { - throw new InvalidTemporalArgumentException( value.other() + " must be specified" ); + throw new InvalidValuesArgumentException( value.other() + " must be specified" ); } } } @@ -1353,15 +1353,15 @@ static int validNano( AnyValue millisecond, AnyValue microsecond, AnyValue nanos long ns = safeCastIntegral( "nanosecond", nanosecond, Field.nanosecond.defaultValue ); if ( ms < 0 || ms >= 1000 ) { - throw new InvalidTemporalArgumentException( "Invalid millisecond: " + ms ); + throw new InvalidValuesArgumentException( "Invalid millisecond: " + ms ); } if ( us < 0 || us >= (millisecond != null ? 1000 : 1000_000) ) { - throw new InvalidTemporalArgumentException( "Invalid microsecond: " + us ); + throw new InvalidValuesArgumentException( "Invalid microsecond: " + us ); } if ( ns < 0 || ns >= ( microsecond != null ? 1000 : millisecond != null ? 1000_000 : 1000_000_000 ) ) { - throw new InvalidTemporalArgumentException( "Invalid nanosecond: " + ns ); + throw new InvalidValuesArgumentException( "Invalid nanosecond: " + ns ); } return (int) (ms * 1000_000 + us * 1000 + ns); } @@ -1409,7 +1409,7 @@ static TEMP assertValidArgument( Supplier func ) } catch ( DateTimeException e ) { - throw new InvalidTemporalArgumentException( e.getMessage(), e ); + throw new InvalidValuesArgumentException( e.getMessage(), e ); } } @@ -1433,7 +1433,7 @@ static OFFSET assertValidZone( Supplier func ) } catch ( DateTimeParseException e ) { - throw new InvalidTemporalArgumentException( e.getMessage(), e ); + throw new InvalidValuesArgumentException( e.getMessage(), e ); } } @@ -1512,12 +1512,12 @@ public void assign( String key, String value ) } else { - throw new InvalidTemporalArgumentException( "Cannot set timezone twice" ); + throw new InvalidValuesArgumentException( "Cannot set timezone twice" ); } } else { - throw new InvalidTemporalArgumentException( "Unsupported header field: " + value ); + throw new InvalidValuesArgumentException( "Unsupported header field: " + value ); } } diff --git a/community/values/src/main/java/org/neo4j/values/storable/TimeValue.java b/community/values/src/main/java/org/neo4j/values/storable/TimeValue.java index 7433733f217d4..90cc0a767ac79 100644 --- a/community/values/src/main/java/org/neo4j/values/storable/TimeValue.java +++ b/community/values/src/main/java/org/neo4j/values/storable/TimeValue.java @@ -39,7 +39,7 @@ import org.neo4j.values.AnyValue; import org.neo4j.values.StructureBuilder; import org.neo4j.values.ValueMapper; -import org.neo4j.values.utils.InvalidTemporalArgumentException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.TemporalParseException; import org.neo4j.values.utils.UnsupportedTemporalUnitException; import org.neo4j.values.utils.TemporalUtil; @@ -197,7 +197,7 @@ public TimeValue buildInternal() AnyValue time = fields.get( Field.time ); if ( !(time instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct time from: %s", time ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct time from: %s", time ) ); } TemporalValue t = (TemporalValue) time; result = t.getTimePart( defaultZone ); @@ -236,7 +236,7 @@ protected TimeValue selectTime( { if ( !(temporal instanceof TemporalValue) ) { - throw new InvalidTemporalArgumentException( String.format( "Cannot construct time from: %s", temporal ) ); + throw new InvalidValuesArgumentException( String.format( "Cannot construct time from: %s", temporal ) ); } if ( temporal instanceof TimeValue && timezone == null ) @@ -392,7 +392,7 @@ static ZoneOffset parseOffset( String offset ) { return parseOffset( matcher ); } - throw new InvalidTemporalArgumentException( "Not a valid offset: " + offset ); + throw new InvalidValuesArgumentException( "Not a valid offset: " + offset ); } static ZoneOffset parseOffset( Matcher matcher ) diff --git a/community/values/src/main/java/org/neo4j/values/utils/InvalidTemporalArgumentException.java b/community/values/src/main/java/org/neo4j/values/utils/InvalidValuesArgumentException.java similarity index 81% rename from community/values/src/main/java/org/neo4j/values/utils/InvalidTemporalArgumentException.java rename to community/values/src/main/java/org/neo4j/values/utils/InvalidValuesArgumentException.java index 79fbc570791f4..87618df0d87be 100644 --- a/community/values/src/main/java/org/neo4j/values/utils/InvalidTemporalArgumentException.java +++ b/community/values/src/main/java/org/neo4j/values/utils/InvalidValuesArgumentException.java @@ -20,14 +20,14 @@ package org.neo4j.values.utils; -public class InvalidTemporalArgumentException extends ValuesException +public class InvalidValuesArgumentException extends ValuesException { - public InvalidTemporalArgumentException( String errorMsg ) + public InvalidValuesArgumentException( String errorMsg ) { super( errorMsg ); } - public InvalidTemporalArgumentException( String errorMsg, Throwable cause ) + public InvalidValuesArgumentException( String errorMsg, Throwable cause ) { super( errorMsg, cause ); } diff --git a/community/values/src/test/java/org/neo4j/values/storable/DateTimeValueTest.java b/community/values/src/test/java/org/neo4j/values/storable/DateTimeValueTest.java index 4ab67b9a3235a..3f5d1c3710340 100644 --- a/community/values/src/test/java/org/neo4j/values/storable/DateTimeValueTest.java +++ b/community/values/src/test/java/org/neo4j/values/storable/DateTimeValueTest.java @@ -23,7 +23,6 @@ import org.junit.Rule; import org.junit.Test; -import java.time.DateTimeException; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; @@ -31,7 +30,7 @@ import java.util.ArrayList; import java.util.List; -import org.neo4j.values.utils.InvalidTemporalArgumentException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.TemporalParseException; import org.neo4j.values.utils.UnsupportedTemporalUnitException; @@ -329,7 +328,7 @@ public void shouldRejectInvalidFieldCombinations() .add( "minute", 35 ) .add( "second", 57 ) .add( "nanosecond", 1000000000 ) - .assertThrows( InvalidTemporalArgumentException.class, "Invalid nanosecond: 1000000000" ); + .assertThrows( InvalidValuesArgumentException.class, "Invalid nanosecond: 1000000000" ); asserting( fromValues( builder( clock ) )) .add( "year", 2018 ) .add( "month", 1 ) @@ -338,7 +337,7 @@ public void shouldRejectInvalidFieldCombinations() .add( "minute", 35 ) .add( "second", 57 ) .add( "microsecond", 1000000 ) - .assertThrows( InvalidTemporalArgumentException.class, "Invalid microsecond: 1000000" ); + .assertThrows( InvalidValuesArgumentException.class, "Invalid microsecond: 1000000" ); asserting( fromValues( builder( clock ) )) .add( "year", 2018 ) .add( "month", 1 ) @@ -347,7 +346,7 @@ public void shouldRejectInvalidFieldCombinations() .add( "minute", 35 ) .add( "second", 57 ) .add( "millisecond", 1000 ) - .assertThrows( InvalidTemporalArgumentException.class, "Invalid millisecond: 1000" ); + .assertThrows( InvalidValuesArgumentException.class, "Invalid millisecond: 1000" ); asserting( fromValues( builder( clock ) )) .add( "year", 2018 ) .add( "month", 1 ) @@ -357,7 +356,7 @@ public void shouldRejectInvalidFieldCombinations() .add( "second", 57 ) .add( "millisecond", 1 ) .add( "nanosecond", 1000000 ) - .assertThrows( InvalidTemporalArgumentException.class, "Invalid nanosecond: 1000000" ); + .assertThrows( InvalidValuesArgumentException.class, "Invalid nanosecond: 1000000" ); asserting( fromValues( builder( clock ) )) .add( "year", 2018 ) .add( "month", 1 ) @@ -367,7 +366,7 @@ public void shouldRejectInvalidFieldCombinations() .add( "second", 57 ) .add( "microsecond", 1 ) .add( "nanosecond", 1000 ) - .assertThrows( InvalidTemporalArgumentException.class, "Invalid nanosecond: 1000" ); + .assertThrows( InvalidValuesArgumentException.class, "Invalid nanosecond: 1000" ); asserting( fromValues( builder( clock ) )) .add( "year", 2018 ) .add( "month", 1 ) @@ -377,7 +376,7 @@ public void shouldRejectInvalidFieldCombinations() .add( "second", 57 ) .add( "millisecond", 1 ) .add( "microsecond", 1000 ) - .assertThrows( InvalidTemporalArgumentException.class, "Invalid microsecond: 1000" ); + .assertThrows( InvalidValuesArgumentException.class, "Invalid microsecond: 1000" ); asserting( fromValues( builder( clock ) )) .add( "year", 2018 ) .add( "month", 1 ) @@ -388,7 +387,7 @@ public void shouldRejectInvalidFieldCombinations() .add( "millisecond", 1 ) .add( "microsecond", 1000 ) .add( "nanosecond", 999 ) - .assertThrows( InvalidTemporalArgumentException.class, "Invalid microsecond: 1000" ); + .assertThrows( InvalidValuesArgumentException.class, "Invalid microsecond: 1000" ); asserting( fromValues( builder( clock ) )) .add( "year", 2018 ) .add( "month", 1 ) @@ -399,16 +398,16 @@ public void shouldRejectInvalidFieldCombinations() .add( "millisecond", 1 ) .add( "microsecond", 999 ) .add( "nanosecond", 1000 ) - .assertThrows( InvalidTemporalArgumentException.class, "Invalid nanosecond: 1000" ); + .assertThrows( InvalidValuesArgumentException.class, "Invalid nanosecond: 1000" ); } @Test public void shouldRejectInvalidComponentValues() { - asserting( fromValues( builder( clock ) ) ).add( "year", 2018 ).add( "moment", 12 ).assertThrows( InvalidTemporalArgumentException.class, + asserting( fromValues( builder( clock ) ) ).add( "year", 2018 ).add( "moment", 12 ).assertThrows( InvalidValuesArgumentException.class, "No such field: moment" ); asserting( fromValues( builder( clock ) ) ).add( "year", 2018 ).add( "month", 12 ).add( "day", 5 ).add( "hour", 5 ).add( "minute", 5 ).add( "second", - 5 ).add( "picosecond", 12 ).assertThrows( InvalidTemporalArgumentException.class, "No such field: picosecond" ); + 5 ).add( "picosecond", 12 ).assertThrows( InvalidValuesArgumentException.class, "No such field: picosecond" ); } @Test diff --git a/community/values/src/test/java/org/neo4j/values/storable/DateValueTest.java b/community/values/src/test/java/org/neo4j/values/storable/DateValueTest.java index 0ba12e0412f01..fabceb0c2dab5 100644 --- a/community/values/src/test/java/org/neo4j/values/storable/DateValueTest.java +++ b/community/values/src/test/java/org/neo4j/values/storable/DateValueTest.java @@ -21,14 +21,13 @@ import org.junit.Test; -import java.time.DateTimeException; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.IsoFields; import java.util.ArrayList; import java.util.List; -import org.neo4j.values.utils.InvalidTemporalArgumentException; +import org.neo4j.values.utils.InvalidValuesArgumentException; import org.neo4j.values.utils.TemporalParseException; import static java.util.Collections.singletonList; @@ -147,7 +146,7 @@ public void shouldEnforceStrictWeekRanges() value.temporal().get( IsoFields.WEEK_OF_WEEK_BASED_YEAR ), value.temporal().get( IsoFields.WEEK_BASED_YEAR ) ) ); } - catch ( InvalidTemporalArgumentException expected ) + catch ( InvalidValuesArgumentException expected ) { assertEquals( "Year 2017 does not contain 53 weeks.", expected.getMessage() ); } @@ -158,24 +157,24 @@ public void shouldEnforceStrictWeekRanges() public void shouldEnforceStrictQuarterRanges() { assertEquals( date( 2017, 3, 31 ), quarterDate( 2017, 1, 90 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 1, 0 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 2, 0 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 3, 0 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 4, 0 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 4, 93 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 3, 93 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 2, 92 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 1, 92 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2017, 1, 91 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 1, 0 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 2, 0 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 3, 0 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 4, 0 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 4, 93 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 3, 93 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 2, 92 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 1, 92 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2017, 1, 91 ) ); assertEquals( date( 2016, 3, 31 ), quarterDate( 2016, 1, 91 ) ); - assertThrows( InvalidTemporalArgumentException.class, () -> quarterDate( 2016, 1, 92 ) ); + assertThrows( InvalidValuesArgumentException.class, () -> quarterDate( 2016, 1, 92 ) ); } @Test public void shouldNotParseInvalidDates() { assertCannotParse( "2015W54" ); // no year should have more than 53 weeks (2015 had 53 weeks) - assertThrows( InvalidTemporalArgumentException.class, () -> parse( "2017W53" ) ); // 2017 only has 52 weeks + assertThrows( InvalidValuesArgumentException.class, () -> parse( "2017W53" ) ); // 2017 only has 52 weeks } @Test