Skip to content

Replaced Point2D and Point3D with Point #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@

import java.util.Objects;

import org.neo4j.driver.v1.types.Point2D;
import org.neo4j.driver.v1.types.Point;

public class InternalPoint2D implements Point2D
public class InternalPoint2D implements Point
{
private final long srid;
private final int srid;
private final double x;
private final double y;

public InternalPoint2D( long srid, double x, double y )
public InternalPoint2D( int srid, double x, double y )
{
this.srid = srid;
this.x = x;
this.y = y;
}

@Override
public long srid()
public int srid()
{
return srid;
}
Expand All @@ -53,6 +53,12 @@ public double y()
return y;
}

@Override
public double z()
{
return Double.NaN;
}

@Override
public boolean equals( Object o )
{
Expand All @@ -79,7 +85,7 @@ public int hashCode()
@Override
public String toString()
{
return "Point2D{" +
return "Point{" +
"srid=" + srid +
", x=" + x +
", y=" + y +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@

import java.util.Objects;

import org.neo4j.driver.v1.types.Point3D;
import org.neo4j.driver.v1.types.Point;

public class InternalPoint3D implements Point3D
public class InternalPoint3D implements Point
{
private final long srid;
private final int srid;
private final double x;
private final double y;
private final double z;

public InternalPoint3D( long srid, double x, double y, double z )
public InternalPoint3D( int srid, double x, double y )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this constructor since we already have a distinct InternalPoint2D?

{
this( srid, x, y, Double.NaN );
}

public InternalPoint3D( int srid, double x, double y, double z )
{
this.srid = srid;
this.x = x;
Expand All @@ -38,7 +43,7 @@ public InternalPoint3D( long srid, double x, double y, double z )
}

@Override
public long srid()
public int srid()
{
return srid;
}
Expand Down Expand Up @@ -88,11 +93,11 @@ public int hashCode()
@Override
public String toString()
{
return "Point3D{" +
return "Point({" +
"srid=" + srid +
", x=" + x +
", y=" + y +
", z=" + z +
'}';
"})";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

import org.neo4j.driver.internal.InternalPoint2D;
import org.neo4j.driver.internal.InternalPoint3D;
import org.neo4j.driver.internal.packstream.PackInput;
import org.neo4j.driver.internal.packstream.PackOutput;
import org.neo4j.driver.internal.types.TypeConstructor;
import org.neo4j.driver.internal.value.InternalValue;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.types.IsoDuration;
import org.neo4j.driver.v1.types.Point2D;
import org.neo4j.driver.v1.types.Point3D;
import org.neo4j.driver.v1.types.Point;

import static java.time.ZoneOffset.UTC;
import static org.neo4j.driver.v1.Values.isoDuration;
import static org.neo4j.driver.v1.Values.point2D;
import static org.neo4j.driver.v1.Values.point3D;
import static org.neo4j.driver.v1.Values.point;
import static org.neo4j.driver.v1.Values.value;

public class PackStreamMessageFormatV2 extends PackStreamMessageFormatV1
Expand Down Expand Up @@ -117,11 +117,8 @@ void packInternalValue( InternalValue value ) throws IOException
case DURATION:
packDuration( value.asIsoDuration() );
break;
case POINT_2D:
packPoint2D( value.asPoint2D() );
break;
case POINT_3D:
packPoint3D( value.asPoint3D() );
case POINT:
packPoint( value.asPoint() );
break;
default:
super.packInternalValue( value );
Expand Down Expand Up @@ -195,15 +192,31 @@ private void packDuration( IsoDuration duration ) throws IOException
packer.pack( duration.nanoseconds() );
}

private void packPoint2D( Point2D point ) throws IOException
private void packPoint( Point point ) throws IOException
{
if ( point instanceof InternalPoint2D )
{
packPoint2D( point );
}
else if ( point instanceof InternalPoint3D )
{
packPoint3D( point );
}
else
{
throw new IOException( String.format( "Unknown type: type: %s, value: %s", point.getClass(), point.toString() ) );
}
}

private void packPoint2D ( Point point ) throws IOException
{
packer.packStructHeader( POINT_2D_STRUCT_SIZE, POINT_2D_STRUCT_TYPE );
packer.pack( point.srid() );
packer.pack( point.x() );
packer.pack( point.y() );
}

private void packPoint3D( Point3D point ) throws IOException
private void packPoint3D( Point point ) throws IOException
{
packer.packStructHeader( POINT_3D_STRUCT_SIZE, POINT_3D_STRUCT_TYPE );
packer.pack( point.srid() );
Expand Down Expand Up @@ -247,10 +260,10 @@ Value unpackStruct( long size, byte type ) throws IOException
ensureCorrectStructSize( TypeConstructor.DURATION, DURATION_TIME_STRUCT_SIZE, size );
return unpackDuration();
case POINT_2D_STRUCT_TYPE:
ensureCorrectStructSize( TypeConstructor.POINT_2D, POINT_2D_STRUCT_SIZE, size );
ensureCorrectStructSize( TypeConstructor.POINT, POINT_2D_STRUCT_SIZE, size );
return unpackPoint2D();
case POINT_3D_STRUCT_TYPE:
ensureCorrectStructSize( TypeConstructor.POINT_3D, POINT_3D_STRUCT_SIZE, size );
ensureCorrectStructSize( TypeConstructor.POINT, POINT_3D_STRUCT_SIZE, size );
return unpackPoint3D();
default:
return super.unpackStruct( size, type );
Expand Down Expand Up @@ -319,19 +332,19 @@ private Value unpackDuration() throws IOException

private Value unpackPoint2D() throws IOException
{
long srid = unpacker.unpackLong();
int srid = Math.toIntExact( unpacker.unpackLong() );
double x = unpacker.unpackDouble();
double y = unpacker.unpackDouble();
return point2D( srid, x, y );
return point( srid, x, y );
}

private Value unpackPoint3D() throws IOException
{
long srid = unpacker.unpackLong();
int srid = Math.toIntExact( unpacker.unpackLong() );
double x = unpacker.unpackDouble();
double y = unpacker.unpackDouble();
double z = unpacker.unpackDouble();
return point3D( srid, x, y, z );
return point( srid, x, y, z );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import static org.neo4j.driver.internal.types.TypeConstructor.NULL;
import static org.neo4j.driver.internal.types.TypeConstructor.NUMBER;
import static org.neo4j.driver.internal.types.TypeConstructor.PATH;
import static org.neo4j.driver.internal.types.TypeConstructor.POINT_2D;
import static org.neo4j.driver.internal.types.TypeConstructor.POINT_3D;
import static org.neo4j.driver.internal.types.TypeConstructor.POINT;
import static org.neo4j.driver.internal.types.TypeConstructor.RELATIONSHIP;
import static org.neo4j.driver.internal.types.TypeConstructor.STRING;
import static org.neo4j.driver.internal.types.TypeConstructor.TIME;
Expand All @@ -66,8 +65,7 @@ public class InternalTypeSystem implements TypeSystem
private final TypeRepresentation nodeType = constructType( NODE );
private final TypeRepresentation relationshipType = constructType( RELATIONSHIP );
private final TypeRepresentation pathType = constructType( PATH );
private final TypeRepresentation point2dType = constructType( POINT_2D );
private final TypeRepresentation point3dType = constructType( POINT_3D );
private final TypeRepresentation pointType = constructType( POINT );
private final TypeRepresentation dateType = constructType( DATE );
private final TypeRepresentation timeType = constructType( TIME );
private final TypeRepresentation localTimeType = constructType( LOCAL_TIME );
Expand Down Expand Up @@ -153,15 +151,9 @@ public Type PATH()
}

@Override
public Type POINT_2D()
public Type POINT()
{
return point2dType;
}

@Override
public Type POINT_3D()
{
return point3dType;
return pointType;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public boolean covers( Value value )
NODE,
RELATIONSHIP,
PATH,
POINT_2D,
POINT_3D,
POINT,
DATE,
TIME,
LOCAL_TIME,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
package org.neo4j.driver.internal.value;

import org.neo4j.driver.internal.types.InternalTypeSystem;
import org.neo4j.driver.v1.types.Point2D;
import org.neo4j.driver.v1.types.Point;
import org.neo4j.driver.v1.types.Type;

public class Point2DValue extends ObjectValueAdapter<Point2D>
public class PointValue extends ObjectValueAdapter<Point>
{
public Point2DValue( Point2D point )
public PointValue( Point point )
{
super( point );
}

@Override
public Point2D asPoint2D()
public Point asPoint()
{
return asObject();
}

@Override
public Type type()
{
return InternalTypeSystem.TYPE_SYSTEM.POINT_2D();
return InternalTypeSystem.TYPE_SYSTEM.POINT();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
import org.neo4j.driver.v1.types.IsoDuration;
import org.neo4j.driver.v1.types.Node;
import org.neo4j.driver.v1.types.Path;
import org.neo4j.driver.v1.types.Point2D;
import org.neo4j.driver.v1.types.Point3D;
import org.neo4j.driver.v1.types.Point;
import org.neo4j.driver.v1.types.Relationship;
import org.neo4j.driver.v1.types.Type;
import org.neo4j.driver.v1.util.Function;
Expand Down Expand Up @@ -224,15 +223,9 @@ public IsoDuration asIsoDuration()
}

@Override
public Point2D asPoint2D()
public Point asPoint()
{
throw new Uncoercible( type().name(), "Point2D" );
}

@Override
public Point3D asPoint3D()
{
throw new Uncoercible( type().name(), "Point3D" );
throw new Uncoercible( type().name(), "Point" );
}

@Override
Expand Down
13 changes: 3 additions & 10 deletions driver/src/main/java/org/neo4j/driver/v1/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
import org.neo4j.driver.v1.types.MapAccessorWithDefaultValue;
import org.neo4j.driver.v1.types.Node;
import org.neo4j.driver.v1.types.Path;
import org.neo4j.driver.v1.types.Point2D;
import org.neo4j.driver.v1.types.Point3D;
import org.neo4j.driver.v1.types.Point;
import org.neo4j.driver.v1.types.Relationship;
import org.neo4j.driver.v1.types.Type;
import org.neo4j.driver.v1.types.TypeSystem;
Expand Down Expand Up @@ -334,16 +333,10 @@ public interface Value extends MapAccessor, MapAccessorWithDefaultValue
IsoDuration asIsoDuration();

/**
* @return the value as a {@link Point2D}, if possible.
* @return the value as a {@link Point}, if possible.
* @throws Uncoercible if value types are incompatible.
*/
Point2D asPoint2D();

/**
* @return the value as a {@link Point3D}, if possible.
* @throws Uncoercible if value types are incompatible.
*/
Point3D asPoint3D();
Point asPoint();

@Override
boolean equals( Object other );
Expand Down
Loading