Skip to content

Commit e2881f7

Browse files
authored
Merge pull request #475 from zhenlineo/1.6-point
Replaced Point2D and Point3D with Point
2 parents 093c607 + 7924138 commit e2881f7

File tree

16 files changed

+128
-246
lines changed

16 files changed

+128
-246
lines changed

driver/src/main/java/org/neo4j/driver/internal/InternalPoint2D.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@
2020

2121
import java.util.Objects;
2222

23-
import org.neo4j.driver.v1.types.Point2D;
23+
import org.neo4j.driver.v1.types.Point;
2424

25-
public class InternalPoint2D implements Point2D
25+
public class InternalPoint2D implements Point
2626
{
27-
private final long srid;
27+
private final int srid;
2828
private final double x;
2929
private final double y;
3030

31-
public InternalPoint2D( long srid, double x, double y )
31+
public InternalPoint2D( int srid, double x, double y )
3232
{
3333
this.srid = srid;
3434
this.x = x;
3535
this.y = y;
3636
}
3737

3838
@Override
39-
public long srid()
39+
public int srid()
4040
{
4141
return srid;
4242
}
@@ -53,6 +53,12 @@ public double y()
5353
return y;
5454
}
5555

56+
@Override
57+
public double z()
58+
{
59+
return Double.NaN;
60+
}
61+
5662
@Override
5763
public boolean equals( Object o )
5864
{
@@ -79,7 +85,7 @@ public int hashCode()
7985
@Override
8086
public String toString()
8187
{
82-
return "Point2D{" +
88+
return "Point{" +
8389
"srid=" + srid +
8490
", x=" + x +
8591
", y=" + y +

driver/src/main/java/org/neo4j/driver/internal/InternalPoint3D.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020

2121
import java.util.Objects;
2222

23-
import org.neo4j.driver.v1.types.Point3D;
23+
import org.neo4j.driver.v1.types.Point;
2424

25-
public class InternalPoint3D implements Point3D
25+
public class InternalPoint3D implements Point
2626
{
27-
private final long srid;
27+
private final int srid;
2828
private final double x;
2929
private final double y;
3030
private final double z;
3131

32-
public InternalPoint3D( long srid, double x, double y, double z )
32+
public InternalPoint3D( int srid, double x, double y, double z )
3333
{
3434
this.srid = srid;
3535
this.x = x;
@@ -38,7 +38,7 @@ public InternalPoint3D( long srid, double x, double y, double z )
3838
}
3939

4040
@Override
41-
public long srid()
41+
public int srid()
4242
{
4343
return srid;
4444
}
@@ -88,11 +88,11 @@ public int hashCode()
8888
@Override
8989
public String toString()
9090
{
91-
return "Point3D{" +
91+
return "Point({" +
9292
"srid=" + srid +
9393
", x=" + x +
9494
", y=" + y +
9595
", z=" + z +
96-
'}';
96+
"})";
9797
}
9898
}

driver/src/main/java/org/neo4j/driver/internal/messaging/PackStreamMessageFormatV2.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
import java.time.ZoneOffset;
2929
import java.time.ZonedDateTime;
3030

31+
import org.neo4j.driver.internal.InternalPoint2D;
32+
import org.neo4j.driver.internal.InternalPoint3D;
3133
import org.neo4j.driver.internal.packstream.PackInput;
3234
import org.neo4j.driver.internal.packstream.PackOutput;
3335
import org.neo4j.driver.internal.types.TypeConstructor;
3436
import org.neo4j.driver.internal.value.InternalValue;
3537
import org.neo4j.driver.v1.Value;
3638
import org.neo4j.driver.v1.types.IsoDuration;
37-
import org.neo4j.driver.v1.types.Point2D;
38-
import org.neo4j.driver.v1.types.Point3D;
39+
import org.neo4j.driver.v1.types.Point;
3940

4041
import static java.time.ZoneOffset.UTC;
4142
import static org.neo4j.driver.v1.Values.isoDuration;
42-
import static org.neo4j.driver.v1.Values.point2D;
43-
import static org.neo4j.driver.v1.Values.point3D;
43+
import static org.neo4j.driver.v1.Values.point;
4444
import static org.neo4j.driver.v1.Values.value;
4545

4646
public class PackStreamMessageFormatV2 extends PackStreamMessageFormatV1
@@ -117,11 +117,8 @@ void packInternalValue( InternalValue value ) throws IOException
117117
case DURATION:
118118
packDuration( value.asIsoDuration() );
119119
break;
120-
case POINT_2D:
121-
packPoint2D( value.asPoint2D() );
122-
break;
123-
case POINT_3D:
124-
packPoint3D( value.asPoint3D() );
120+
case POINT:
121+
packPoint( value.asPoint() );
125122
break;
126123
default:
127124
super.packInternalValue( value );
@@ -195,15 +192,31 @@ private void packDuration( IsoDuration duration ) throws IOException
195192
packer.pack( duration.nanoseconds() );
196193
}
197194

198-
private void packPoint2D( Point2D point ) throws IOException
195+
private void packPoint( Point point ) throws IOException
196+
{
197+
if ( point instanceof InternalPoint2D )
198+
{
199+
packPoint2D( point );
200+
}
201+
else if ( point instanceof InternalPoint3D )
202+
{
203+
packPoint3D( point );
204+
}
205+
else
206+
{
207+
throw new IOException( String.format( "Unknown type: type: %s, value: %s", point.getClass(), point.toString() ) );
208+
}
209+
}
210+
211+
private void packPoint2D ( Point point ) throws IOException
199212
{
200213
packer.packStructHeader( POINT_2D_STRUCT_SIZE, POINT_2D_STRUCT_TYPE );
201214
packer.pack( point.srid() );
202215
packer.pack( point.x() );
203216
packer.pack( point.y() );
204217
}
205218

206-
private void packPoint3D( Point3D point ) throws IOException
219+
private void packPoint3D( Point point ) throws IOException
207220
{
208221
packer.packStructHeader( POINT_3D_STRUCT_SIZE, POINT_3D_STRUCT_TYPE );
209222
packer.pack( point.srid() );
@@ -247,10 +260,10 @@ Value unpackStruct( long size, byte type ) throws IOException
247260
ensureCorrectStructSize( TypeConstructor.DURATION, DURATION_TIME_STRUCT_SIZE, size );
248261
return unpackDuration();
249262
case POINT_2D_STRUCT_TYPE:
250-
ensureCorrectStructSize( TypeConstructor.POINT_2D, POINT_2D_STRUCT_SIZE, size );
263+
ensureCorrectStructSize( TypeConstructor.POINT, POINT_2D_STRUCT_SIZE, size );
251264
return unpackPoint2D();
252265
case POINT_3D_STRUCT_TYPE:
253-
ensureCorrectStructSize( TypeConstructor.POINT_3D, POINT_3D_STRUCT_SIZE, size );
266+
ensureCorrectStructSize( TypeConstructor.POINT, POINT_3D_STRUCT_SIZE, size );
254267
return unpackPoint3D();
255268
default:
256269
return super.unpackStruct( size, type );
@@ -319,19 +332,19 @@ private Value unpackDuration() throws IOException
319332

320333
private Value unpackPoint2D() throws IOException
321334
{
322-
long srid = unpacker.unpackLong();
335+
int srid = Math.toIntExact( unpacker.unpackLong() );
323336
double x = unpacker.unpackDouble();
324337
double y = unpacker.unpackDouble();
325-
return point2D( srid, x, y );
338+
return point( srid, x, y );
326339
}
327340

328341
private Value unpackPoint3D() throws IOException
329342
{
330-
long srid = unpacker.unpackLong();
343+
int srid = Math.toIntExact( unpacker.unpackLong() );
331344
double x = unpacker.unpackDouble();
332345
double y = unpacker.unpackDouble();
333346
double z = unpacker.unpackDouble();
334-
return point3D( srid, x, y, z );
347+
return point( srid, x, y, z );
335348
}
336349
}
337350
}

driver/src/main/java/org/neo4j/driver/internal/types/InternalTypeSystem.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
import static org.neo4j.driver.internal.types.TypeConstructor.NULL;
3939
import static org.neo4j.driver.internal.types.TypeConstructor.NUMBER;
4040
import static org.neo4j.driver.internal.types.TypeConstructor.PATH;
41-
import static org.neo4j.driver.internal.types.TypeConstructor.POINT_2D;
42-
import static org.neo4j.driver.internal.types.TypeConstructor.POINT_3D;
41+
import static org.neo4j.driver.internal.types.TypeConstructor.POINT;
4342
import static org.neo4j.driver.internal.types.TypeConstructor.RELATIONSHIP;
4443
import static org.neo4j.driver.internal.types.TypeConstructor.STRING;
4544
import static org.neo4j.driver.internal.types.TypeConstructor.TIME;
@@ -66,8 +65,7 @@ public class InternalTypeSystem implements TypeSystem
6665
private final TypeRepresentation nodeType = constructType( NODE );
6766
private final TypeRepresentation relationshipType = constructType( RELATIONSHIP );
6867
private final TypeRepresentation pathType = constructType( PATH );
69-
private final TypeRepresentation point2dType = constructType( POINT_2D );
70-
private final TypeRepresentation point3dType = constructType( POINT_3D );
68+
private final TypeRepresentation pointType = constructType( POINT );
7169
private final TypeRepresentation dateType = constructType( DATE );
7270
private final TypeRepresentation timeType = constructType( TIME );
7371
private final TypeRepresentation localTimeType = constructType( LOCAL_TIME );
@@ -153,15 +151,9 @@ public Type PATH()
153151
}
154152

155153
@Override
156-
public Type POINT_2D()
154+
public Type POINT()
157155
{
158-
return point2dType;
159-
}
160-
161-
@Override
162-
public Type POINT_3D()
163-
{
164-
return point3dType;
156+
return pointType;
165157
}
166158

167159
@Override

driver/src/main/java/org/neo4j/driver/internal/types/TypeConstructor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public boolean covers( Value value )
5858
NODE,
5959
RELATIONSHIP,
6060
PATH,
61-
POINT_2D,
62-
POINT_3D,
61+
POINT,
6362
DATE,
6463
TIME,
6564
LOCAL_TIME,

driver/src/main/java/org/neo4j/driver/internal/value/Point3DValue.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

driver/src/main/java/org/neo4j/driver/internal/value/Point2DValue.java renamed to driver/src/main/java/org/neo4j/driver/internal/value/PointValue.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919
package org.neo4j.driver.internal.value;
2020

2121
import org.neo4j.driver.internal.types.InternalTypeSystem;
22-
import org.neo4j.driver.v1.types.Point2D;
22+
import org.neo4j.driver.v1.types.Point;
2323
import org.neo4j.driver.v1.types.Type;
2424

25-
public class Point2DValue extends ObjectValueAdapter<Point2D>
25+
public class PointValue extends ObjectValueAdapter<Point>
2626
{
27-
public Point2DValue( Point2D point )
27+
public PointValue( Point point )
2828
{
2929
super( point );
3030
}
3131

3232
@Override
33-
public Point2D asPoint2D()
33+
public Point asPoint()
3434
{
3535
return asObject();
3636
}
3737

3838
@Override
3939
public Type type()
4040
{
41-
return InternalTypeSystem.TYPE_SYSTEM.POINT_2D();
41+
return InternalTypeSystem.TYPE_SYSTEM.POINT();
4242
}
4343
}

driver/src/main/java/org/neo4j/driver/internal/value/ValueAdapter.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
import org.neo4j.driver.v1.types.IsoDuration;
3838
import org.neo4j.driver.v1.types.Node;
3939
import org.neo4j.driver.v1.types.Path;
40-
import org.neo4j.driver.v1.types.Point2D;
41-
import org.neo4j.driver.v1.types.Point3D;
40+
import org.neo4j.driver.v1.types.Point;
4241
import org.neo4j.driver.v1.types.Relationship;
4342
import org.neo4j.driver.v1.types.Type;
4443
import org.neo4j.driver.v1.util.Function;
@@ -224,15 +223,9 @@ public IsoDuration asIsoDuration()
224223
}
225224

226225
@Override
227-
public Point2D asPoint2D()
226+
public Point asPoint()
228227
{
229-
throw new Uncoercible( type().name(), "Point2D" );
230-
}
231-
232-
@Override
233-
public Point3D asPoint3D()
234-
{
235-
throw new Uncoercible( type().name(), "Point3D" );
228+
throw new Uncoercible( type().name(), "Point" );
236229
}
237230

238231
@Override

driver/src/main/java/org/neo4j/driver/v1/Value.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
import org.neo4j.driver.v1.types.MapAccessorWithDefaultValue;
3636
import org.neo4j.driver.v1.types.Node;
3737
import org.neo4j.driver.v1.types.Path;
38-
import org.neo4j.driver.v1.types.Point2D;
39-
import org.neo4j.driver.v1.types.Point3D;
38+
import org.neo4j.driver.v1.types.Point;
4039
import org.neo4j.driver.v1.types.Relationship;
4140
import org.neo4j.driver.v1.types.Type;
4241
import org.neo4j.driver.v1.types.TypeSystem;
@@ -334,16 +333,10 @@ public interface Value extends MapAccessor, MapAccessorWithDefaultValue
334333
IsoDuration asIsoDuration();
335334

336335
/**
337-
* @return the value as a {@link Point2D}, if possible.
336+
* @return the value as a {@link Point}, if possible.
338337
* @throws Uncoercible if value types are incompatible.
339338
*/
340-
Point2D asPoint2D();
341-
342-
/**
343-
* @return the value as a {@link Point3D}, if possible.
344-
* @throws Uncoercible if value types are incompatible.
345-
*/
346-
Point3D asPoint3D();
339+
Point asPoint();
347340

348341
@Override
349342
boolean equals( Object other );

0 commit comments

Comments
 (0)