You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kw...@apache.org on 2017/08/25 06:53:50 UTC
lucene-solr:branch_6x: LUCENE-7936: Complete the work to support
serialization and deserialization of individual Geo3D objects. This adds
support for GeoComplexPolygon and the composites.
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 15a06dfca -> abc76f7f2
LUCENE-7936: Complete the work to support serialization and deserialization of individual Geo3D objects. This adds support for GeoComplexPolygon and the composites.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/abc76f7f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/abc76f7f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/abc76f7f
Branch: refs/heads/branch_6x
Commit: abc76f7f2852d9da4a54764321c2386dfb48d8c8
Parents: 15a06df
Author: Karl Wright <Da...@gmail.com>
Authored: Fri Aug 25 02:52:11 2017 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Fri Aug 25 02:53:41 2017 -0400
----------------------------------------------------------------------
.../geom/GeoBaseCompositeAreaShape.java | 13 +++++++
.../geom/GeoBaseCompositeMembershipShape.java | 13 +++++++
.../spatial3d/geom/GeoBaseCompositeShape.java | 25 ++++++++++++
.../spatial3d/geom/GeoComplexPolygon.java | 40 ++++++++++++++++++++
.../spatial3d/geom/GeoCompositeAreaShape.java | 12 ++++++
.../spatial3d/geom/GeoCompositePolygon.java | 12 ++++++
.../spatial3d/geom/SerializableObject.java | 20 ++++++++++
7 files changed, 135 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/abc76f7f/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.java
index 164d458..986e42c 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.java
@@ -17,6 +17,9 @@
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.IOException;
+
/**
* Base class to create a composite of GeoAreaShapes
*
@@ -39,6 +42,16 @@ abstract class GeoBaseCompositeAreaShape<T extends GeoAreaShape> extends GeoBase
super(planetModel);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ * @param clazz is the class of the generic.
+ */
+ public GeoBaseCompositeAreaShape(final PlanetModel planetModel, final InputStream inputStream, final Class<T> clazz) throws IOException {
+ super(planetModel, inputStream, clazz);
+ }
+
@Override
public boolean intersects(GeoShape geoShape){
for(GeoAreaShape geoAreaShape : shapes){
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/abc76f7f/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.java
index 0f19a7c..d4eab4e 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.java
@@ -17,6 +17,9 @@
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.IOException;
+
/**
* Base class to create a composite of GeoMembershipShapes
*
@@ -33,6 +36,16 @@ abstract class GeoBaseCompositeMembershipShape<T extends GeoMembershipShape>
super(planetModel);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ * @param clazz is the class of the generic.
+ */
+ GeoBaseCompositeMembershipShape(final PlanetModel planetModel, final InputStream inputStream, final Class<T> clazz) throws IOException {
+ super(planetModel, inputStream, clazz);
+ }
+
@Override
public double computeOutsideDistance(final DistanceStyle distanceStyle, final GeoPoint point) {
return computeOutsideDistance(distanceStyle, point.x, point.y, point.z);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/abc76f7f/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.java
index 32f6e9a..734eff6 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.java
@@ -20,6 +20,9 @@ package org.apache.lucene.spatial3d.geom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
/**
* Base class to create a composite of GeoShapes.
@@ -71,6 +74,28 @@ public abstract class GeoBaseCompositeShape<T extends GeoShape> extends BasePlan
return shapes.get(index);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ * @param clazz is the class of the generic.
+ */
+ public GeoBaseCompositeShape(final PlanetModel planetModel, final InputStream inputStream, final Class<T> clazz) throws IOException {
+ this(planetModel);
+ final SerializableObject[] array = SerializableObject.readHeterogeneousArray(planetModel, inputStream);
+ for (final SerializableObject member : array) {
+ if (!(clazz.isAssignableFrom(member.getClass()))) {
+ throw new IOException("Can't deserialize composite because member has wrong type: "+member.getClass().getName());
+ }
+ addShape(clazz.cast(member));
+ }
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeHeterogeneousArray(outputStream, shapes);
+ }
+
@Override
public boolean isWithin(final Vector point) {
return isWithin(point.x, point.y, point.z);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/abc76f7f/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java
index 6bd66d4..107815d 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java
@@ -19,6 +19,9 @@ package org.apache.lucene.spatial3d.geom;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
/**
* GeoComplexPolygon objects are structures designed to handle very large numbers of edges.
@@ -37,6 +40,7 @@ class GeoComplexPolygon extends GeoBasePolygon {
private final Tree yTree;
private final Tree zTree;
+ private final List<List<GeoPoint>> pointsList;
private final boolean testPointInSet;
private final GeoPoint testPoint;
@@ -66,6 +70,7 @@ class GeoComplexPolygon extends GeoBasePolygon {
*/
public GeoComplexPolygon(final PlanetModel planetModel, final List<List<GeoPoint>> pointsList, final GeoPoint testPoint, final boolean testPointInSet) {
super(planetModel);
+ this.pointsList = pointsList; // For serialization
this.testPointInSet = testPointInSet;
this.testPoint = testPoint;
@@ -115,6 +120,41 @@ class GeoComplexPolygon extends GeoBasePolygon {
zTree = new ZTree(allEdges);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoComplexPolygon(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ readPointsList(planetModel, inputStream),
+ new GeoPoint(planetModel, inputStream),
+ SerializableObject.readBoolean(inputStream));
+ }
+
+ private static List<List<GeoPoint>> readPointsList(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ final int count = SerializableObject.readInt(inputStream);
+ final List<List<GeoPoint>> array = new ArrayList<>(count);
+ for (int i = 0; i < count; i++) {
+ array.add(java.util.Arrays.asList(SerializableObject.readPointArray(planetModel, inputStream)));
+ }
+ return array;
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ writePointsList(outputStream, pointsList);
+ testPoint.write(outputStream);
+ SerializableObject.writeBoolean(outputStream, testPointInSet);
+ }
+
+ private static void writePointsList(final OutputStream outputStream, final List<List<GeoPoint>> pointsList) throws IOException {
+ SerializableObject.writeInt(outputStream, pointsList.size());
+ for (final List<GeoPoint> points : pointsList) {
+ SerializableObject.writePointArray(outputStream, points);
+ }
+ }
+
@Override
public boolean isWithin(final double x, final double y, final double z) {
// If we're right on top of the point, we know the answer.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/abc76f7f/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.java
index 085dbb3..118144d 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.java
@@ -17,6 +17,9 @@
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.IOException;
+
/**
* GeoCompositeAreaShape is a set of GeoAreaShape's, treated as a unit.
*
@@ -31,6 +34,15 @@ public class GeoCompositeAreaShape extends GeoBaseCompositeAreaShape<GeoAreaShap
super(planetModel);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoCompositeAreaShape(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ super(planetModel, inputStream, GeoAreaShape.class);
+ }
+
@Override
public boolean equals(Object o) {
if (!(o instanceof GeoCompositeAreaShape))
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/abc76f7f/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.java
index 3e62177..f9f3a95 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.java
@@ -16,6 +16,9 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.IOException;
+
/**
* GeoCompositePolygon is a specific implementation of GeoCompositeAreaShape, which implements GeoPolygon explicitly.
*
@@ -29,6 +32,15 @@ public class GeoCompositePolygon extends GeoBaseCompositeAreaShape<GeoPolygon> i
super(planetModel);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoCompositePolygon(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ super(planetModel, inputStream, GeoPolygon.class);
+ }
+
@Override
public boolean equals(Object o) {
if (!(o instanceof GeoCompositePolygon))
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/abc76f7f/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/SerializableObject.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/SerializableObject.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/SerializableObject.java
index 9479cf2..da23cf2 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/SerializableObject.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/SerializableObject.java
@@ -376,4 +376,24 @@ public interface SerializableObject {
return l1 + l2 + l3 + l4;
}
+ /** Write a boolean to a stream.
+ * @param outputStream is the output stream.
+ * @param value is the value to write.
+ */
+ static void writeBoolean(final OutputStream outputStream, final boolean value) throws IOException {
+ outputStream.write(value?0:1);
+ }
+
+ /** Read a boolean from a stream.
+ * @param inputStream is the input stream.
+ * @return the boolean value.
+ */
+ static boolean readBoolean(final InputStream inputStream) throws IOException {
+ final int valueRead = inputStream.read();
+ if (valueRead == -1) {
+ throw new IOException("Unexpected end of input stream");
+ }
+ return (valueRead == 0)?false:true;
+ }
+
}