Skip to content

Commit

Permalink
Privatize all the arrays!
Browse files Browse the repository at this point in the history
  • Loading branch information
sherfert committed Feb 6, 2018
1 parent 46ae543 commit dbce5f0
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 24 deletions.
Expand Up @@ -397,7 +397,7 @@ public void writeDateTime( long epochSecondUTC, int nano, int offsetSeconds ) th
@Override @Override
public void writeDateTime( long epochSecondUTC, int nano, String zoneId ) throws RuntimeException public void writeDateTime( long epochSecondUTC, int nano, String zoneId ) throws RuntimeException
{ {
writeValue( ZonedDateTime.of( LocalDate.ofEpochDay( epochSecondUTC ), LocalTime.ofNanoOfDay( nano ), ZoneId.of( zoneId ) ) ); writeValue( ZonedDateTime.ofInstant( Instant.ofEpochSecond(epochSecondUTC, nano), ZoneId.of( zoneId ) ) );
} }


private interface Writer private interface Writer
Expand Down
Expand Up @@ -26,6 +26,7 @@
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.OffsetTime; import java.time.OffsetTime;
import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
Expand Down Expand Up @@ -210,7 +211,7 @@ public void shouldHandlePoints()
} }


@Test @Test
public void shouldHandleDateTime() public void shouldHandleDateTimeWithZoneOffset()
{ {
// Given // Given
DateTimeValue dvalue = DateTimeValue.datetime( 1, 2, 3, 4, 5, 6, 7, "+00:00" ); DateTimeValue dvalue = DateTimeValue.datetime( 1, 2, 3, 4, 5, 6, 7, "+00:00" );
Expand All @@ -224,6 +225,21 @@ public void shouldHandleDateTime()
assertThat( value, equalTo( dvalue.asObjectCopy() ) ); assertThat( value, equalTo( dvalue.asObjectCopy() ) );
} }


@Test
public void shouldHandleDateTimeWithZoneId()
{
// Given
DateTimeValue dvalue = DateTimeValue.datetime( 1, 2, 3, 4, 5, 6, 7, ZoneId.of( "Europe/Stockholm" ) );

// When
dvalue.writeTo( converter );

// Then
Object value = converter.value();
assertThat( value, instanceOf( ZonedDateTime.class ) );
assertThat( value, equalTo( dvalue.asObjectCopy() ) );
}

@Test @Test
public void shouldHandleLocalDateTime() public void shouldHandleLocalDateTime()
{ {
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.cypher.internal.runtime.interpreted package org.neo4j.cypher.internal.runtime.interpreted


import java.time._ import java.time._
import java.time.temporal.TemporalAmount


import org.neo4j.cypher.internal.util.v3_4.CypherTypeException import org.neo4j.cypher.internal.util.v3_4.CypherTypeException
import org.neo4j.graphdb.spatial.Point import org.neo4j.graphdb.spatial.Point
Expand Down Expand Up @@ -140,7 +141,7 @@ object CastSupport {
case _: Point => Converter( case _: Point => Converter(
transform(new ArrayConverterWriter(classOf[Point], a => Values.pointArray(a.asInstanceOf[Array[Point]])))) transform(new ArrayConverterWriter(classOf[Point], a => Values.pointArray(a.asInstanceOf[Array[Point]]))))
case _: DurationValue => Converter( case _: DurationValue => Converter(
transform(new ArrayConverterWriter(classOf[DurationValue], a => Values.durationArray(a.asInstanceOf[Array[DurationValue]])))) transform(new ArrayConverterWriter(classOf[TemporalAmount], a => Values.durationArray(a.asInstanceOf[Array[TemporalAmount]]))))
case _: DateTimeValue => Converter( case _: DateTimeValue => Converter(
transform(new ArrayConverterWriter(classOf[ZonedDateTime], a => Values.dateTimeArray(a.asInstanceOf[Array[ZonedDateTime]])))) transform(new ArrayConverterWriter(classOf[ZonedDateTime], a => Values.dateTimeArray(a.asInstanceOf[Array[ZonedDateTime]]))))
case _: DateValue => Converter( case _: DateValue => Converter(
Expand Down
Expand Up @@ -449,7 +449,7 @@ public void writeDateTime( long epochSecondUTC, int nano, int offsetSeconds ) th
@Override @Override
public void writeDateTime( long epochSecondUTC, int nano, String zoneId ) throws RuntimeException public void writeDateTime( long epochSecondUTC, int nano, String zoneId ) throws RuntimeException
{ {
writeValue( ZonedDateTime.of( LocalDate.ofEpochDay( epochSecondUTC ), LocalTime.ofNanoOfDay( nano ), ZoneId.of( zoneId ) ) ); writeValue( ZonedDateTime.ofInstant( Instant.ofEpochSecond(epochSecondUTC, nano), ZoneId.of( zoneId ) ) );
} }


private interface Writer private interface Writer
Expand Down
Expand Up @@ -72,11 +72,7 @@ public final boolean eq( Object other )
return false; return false;
} }


if ( other instanceof SequenceValue ) return other instanceof SequenceValue && this.equals( (SequenceValue) other );
{
return this.equals( (SequenceValue) other );
}
return other instanceof Value && equals( (Value) other );
} }


@Override @Override
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class ByteArray extends IntegralArray public class ByteArray extends IntegralArray
{ {
final byte[] value; private final byte[] value;


ByteArray( byte[] value ) ByteArray( byte[] value )
{ {
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class CharArray extends TextArray public class CharArray extends TextArray
{ {
final char[] value; private final char[] value;


CharArray( char[] value ) CharArray( char[] value )
{ {
Expand Down
Expand Up @@ -26,7 +26,7 @@


public class DateArray extends TemporalArray<LocalDate, DateValue> public class DateArray extends TemporalArray<LocalDate, DateValue>
{ {
final LocalDate[] value; private final LocalDate[] value;


DateArray( LocalDate[] value ) DateArray( LocalDate[] value )
{ {
Expand Down
Expand Up @@ -26,7 +26,7 @@


public class DateTimeArray extends TemporalArray<ZonedDateTime, DateTimeValue> public class DateTimeArray extends TemporalArray<ZonedDateTime, DateTimeValue>
{ {
final ZonedDateTime[] value; private final ZonedDateTime[] value;


DateTimeArray( ZonedDateTime[] value ) DateTimeArray( ZonedDateTime[] value )
{ {
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class DoubleArray extends FloatingPointArray public class DoubleArray extends FloatingPointArray
{ {
final double[] value; private final double[] value;


DoubleArray( double[] value ) DoubleArray( double[] value )
{ {
Expand Down
Expand Up @@ -26,7 +26,7 @@


public class DurationArray extends NonPrimitiveArray<DurationValue> public class DurationArray extends NonPrimitiveArray<DurationValue>
{ {
final DurationValue[] value; private final DurationValue[] value;


DurationArray( DurationValue[] value ) DurationArray( DurationValue[] value )
{ {
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class FloatArray extends FloatingPointArray public class FloatArray extends FloatingPointArray
{ {
final float[] value; private final float[] value;


FloatArray( float[] value ) FloatArray( float[] value )
{ {
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class IntArray extends IntegralArray public class IntArray extends IntegralArray
{ {
final int[] value; private final int[] value;


IntArray( int[] value ) IntArray( int[] value )
{ {
Expand Down
Expand Up @@ -26,7 +26,7 @@


public class LocalDateTimeArray extends TemporalArray<LocalDateTime, LocalDateTimeValue> public class LocalDateTimeArray extends TemporalArray<LocalDateTime, LocalDateTimeValue>
{ {
final LocalDateTime[] value; private final LocalDateTime[] value;


LocalDateTimeArray( LocalDateTime[] value ) LocalDateTimeArray( LocalDateTime[] value )
{ {
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class LongArray extends IntegralArray public class LongArray extends IntegralArray
{ {
final long[] value; private final long[] value;


LongArray( long[] value ) LongArray( long[] value )
{ {
Expand Down
Expand Up @@ -27,7 +27,7 @@


public class PointArray extends NonPrimitiveArray<PointValue> public class PointArray extends NonPrimitiveArray<PointValue>
{ {
final PointValue[] value; private final PointValue[] value;


PointArray( PointValue[] value ) PointArray( PointValue[] value )
{ {
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class ShortArray extends IntegralArray public class ShortArray extends IntegralArray
{ {
final short[] value; private final short[] value;


ShortArray( short[] value ) ShortArray( short[] value )
{ {
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class StringArray extends TextArray public class StringArray extends TextArray
{ {
final String[] value; private final String[] value;


StringArray( String[] value ) StringArray( String[] value )
{ {
Expand Down
Expand Up @@ -26,7 +26,7 @@


public class TimeArray extends TemporalArray<OffsetTime, TimeValue> public class TimeArray extends TemporalArray<OffsetTime, TimeValue>
{ {
final OffsetTime[] value; private final OffsetTime[] value;


TimeArray( OffsetTime[] value ) TimeArray( OffsetTime[] value )
{ {
Expand Down
Expand Up @@ -118,7 +118,7 @@ public void shouldEqualItself()
} }


@Test @Test
public void shouldNotEqualSameTimeButDifferentTimezone() public void shouldNotEqualOther()
{ {
assertNotEqual( localTime( 10, 52, 5, 6 ), localTime( 10, 52, 5, 7 ) ); assertNotEqual( localTime( 10, 52, 5, 6 ), localTime( 10, 52, 5, 7 ) );
} }
Expand Down

0 comments on commit dbce5f0

Please sign in to comment.