Skip to content

Commit

Permalink
Rename exception to use it for both temporal and spatial
Browse files Browse the repository at this point in the history
  • Loading branch information
Lojjs committed Apr 5, 2018
1 parent 5694fcd commit e4cbe5a
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 100 deletions.
Expand Up @@ -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)
Expand Down
Expand Up @@ -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<Input, Result>
Expand All @@ -34,7 +34,7 @@ static <T> T build( StructureBuilder<AnyValue,T> 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() );
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) ) );
}
Expand Down Expand Up @@ -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();
Expand All @@ -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() ) );
Expand All @@ -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() ) );
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -349,7 +349,7 @@ else if ( selectingTime || selectingDate )
}
catch ( DateTimeParseException e )
{
throw new InvalidTemporalArgumentException( e.getMessage(), e );
throw new InvalidValuesArgumentException( e.getMessage(), e );
}
}
else
Expand Down Expand Up @@ -602,7 +602,7 @@ private static DateTimeValue parse( Matcher matcher, Supplier<ZoneId> 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() );
}
}
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}
}
}
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() );
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand Down

0 comments on commit e4cbe5a

Please sign in to comment.