Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-7936: Implement serialization/deserialization for all objects except GeoComplexPolygon and composites.

Karl Wrightfd11646af2da
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/BasePlanetObject.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/BasePlanetObject.java
index 86ec61ff469..bb2cc31b607 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/BasePlanetObject.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/BasePlanetObject.java
@@ -25,7 +25,7 @@ import java.io.IOException;
*
* @lucene.internal
*/
-public abstract class BasePlanetObject implements PlanetObject, SerializableObject {
+public abstract class BasePlanetObject implements PlanetObject {
/** This is the planet model embedded in all objects derived from this
* class. */
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java
index 75fecc8498d..7e4ef28c8d1 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java
@@ -21,6 +21,9 @@ import java.util.BitSet;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
/**
* GeoConcavePolygon objects are generic building blocks of more complex structures.
@@ -302,6 +305,26 @@ class GeoConcavePolygon extends GeoBasePolygon {
return index;
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoConcavePolygon(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ super(planetModel);
+ this.points = java.util.Arrays.asList(SerializableObject.readPointArray(planetModel, inputStream));
+ this.holes = java.util.Arrays.asList(SerializableObject.readPolygonArray(planetModel, inputStream));
+ this.isInternalEdges = SerializableObject.readBitSet(inputStream);
+ done(this.isInternalEdges.get(points.size()-1));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writePointArray(outputStream, points);
+ SerializableObject.writePolygonArray(outputStream, holes);
+ SerializableObject.writeBitSet(outputStream, isInternalEdges);
+ }
+
@Override
public boolean isWithin(final double x, final double y, final double z) {
if (!localIsWithin(x, y, z)) {
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
index bf75e3b4971..9711d81b957 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
@@ -21,6 +21,9 @@ import java.util.BitSet;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
/**
* GeoConvexPolygon objects are generic building blocks of more complex structures.
@@ -298,6 +301,26 @@ class GeoConvexPolygon extends GeoBasePolygon {
return index;
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoConvexPolygon(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ super(planetModel);
+ this.points = java.util.Arrays.asList(SerializableObject.readPointArray(planetModel, inputStream));
+ this.holes = java.util.Arrays.asList(SerializableObject.readPolygonArray(planetModel, inputStream));
+ this.isInternalEdges = SerializableObject.readBitSet(inputStream);
+ done(this.isInternalEdges.get(points.size()-1));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writePointArray(outputStream, points);
+ SerializableObject.writePolygonArray(outputStream, holes);
+ SerializableObject.writeBitSet(outputStream, isInternalEdges);
+ }
+
@Override
public boolean isWithin(final double x, final double y, final double z) {
if (!localIsWithin(x, y, z)) {
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateHorizontalLine.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateHorizontalLine.java
index 95181802210..9be5b37fe54 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateHorizontalLine.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateHorizontalLine.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Degenerate bounding box limited on two sides (left lon, right lon).
* The left-right maximum extent for this shape is PI; for anything larger, use
@@ -108,6 +112,22 @@ class GeoDegenerateHorizontalLine extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{centerPoint};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoDegenerateHorizontalLine(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, latitude);
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
double newTopLat = latitude + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateLatitudeZone.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateLatitudeZone.java
index fc6b234a295..aa8798121bd 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateLatitudeZone.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateLatitudeZone.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* This GeoBBox represents an area rectangle of one specific latitude with
* no longitude bounds.
@@ -52,6 +56,20 @@ class GeoDegenerateLatitudeZone extends GeoBaseBBox {
edgePoints = new GeoPoint[]{interiorPoint};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoDegenerateLatitudeZone(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, latitude);
+ }
+
@Override
public GeoBBox expand(final double angle) {
double newTopLat = latitude + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateLongitudeSlice.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateLongitudeSlice.java
index e610ff485e5..0d303358c48 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateLongitudeSlice.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateLongitudeSlice.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Degenerate longitude slice.
*
@@ -57,6 +61,20 @@ class GeoDegenerateLongitudeSlice extends GeoBaseBBox {
this.planePoints = new GeoPoint[]{planetModel.NORTH_POLE, planetModel.SOUTH_POLE};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoDegenerateLongitudeSlice(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, longitude);
+ }
+
@Override
public GeoBBox expand(final double angle) {
// Figuring out when we escalate to a special case requires some prefiguring
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateVerticalLine.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateVerticalLine.java
index c8acf78555f..22c0928d106 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateVerticalLine.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegenerateVerticalLine.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Degenerate bounding box limited on two sides (top lat, bottom lat).
*
@@ -97,6 +101,22 @@ public class GeoDegenerateVerticalLine extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{centerPoint};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoDegenerateVerticalLine(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, topLat);
+ SerializableObject.writeDouble(outputStream, bottomLat);
+ SerializableObject.writeDouble(outputStream, longitude);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoLatitudeZone.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoLatitudeZone.java
index 716efb509f3..8db77ed1af2 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoLatitudeZone.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoLatitudeZone.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* This GeoBBox represents an area rectangle limited only in latitude.
*
@@ -77,6 +81,21 @@ class GeoLatitudeZone extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{topBoundaryPoint, bottomBoundaryPoint};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoLatitudeZone(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, topLat);
+ SerializableObject.writeDouble(outputStream, bottomLat);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoLongitudeSlice.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoLongitudeSlice.java
index fc21a2186f5..404bf8c5581 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoLongitudeSlice.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoLongitudeSlice.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box limited on left and right.
* The left-right maximum extent for this shape is PI; for anything larger, use
@@ -81,6 +85,21 @@ class GeoLongitudeSlice extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{planetModel.NORTH_POLE};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoLongitudeSlice(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
// Figuring out when we escalate to a special case requires some prefiguring
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoNorthLatitudeZone.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoNorthLatitudeZone.java
index 7c3ea96b756..43711266083 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoNorthLatitudeZone.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoNorthLatitudeZone.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* This GeoBBox represents an area rectangle limited only in south latitude.
*
@@ -59,6 +63,20 @@ class GeoNorthLatitudeZone extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{bottomBoundaryPoint};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoNorthLatitudeZone(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, bottomLat);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = Math.PI * 0.5;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoNorthRectangle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoNorthRectangle.java
index 2a1b7c58573..1dac9293649 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoNorthRectangle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoNorthRectangle.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box limited on three sides (bottom lat, left lon, right lon), including
* the north pole.
@@ -116,6 +120,22 @@ class GeoNorthRectangle extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{planetModel.NORTH_POLE};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoNorthRectangle(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, bottomLat);
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = Math.PI * 0.5;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoRectangle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoRectangle.java
index faf29528a20..7e982143876 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoRectangle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoRectangle.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box limited on four sides (top lat, bottom lat, left lon, right lon).
* The left-right maximum extent for this shape is PI; for anything larger, use
@@ -142,6 +146,23 @@ class GeoRectangle extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{ULHC};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoRectangle(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, topLat);
+ SerializableObject.writeDouble(outputStream, bottomLat);
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoSouthLatitudeZone.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoSouthLatitudeZone.java
index acb7cb0fbaf..4b6a549b05a 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoSouthLatitudeZone.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoSouthLatitudeZone.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* This GeoBBox represents an area rectangle limited only in north latitude.
*
@@ -59,6 +63,20 @@ class GeoSouthLatitudeZone extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{topBoundaryPoint};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoSouthLatitudeZone(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, topLat);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoSouthRectangle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoSouthRectangle.java
index f75fc8c7783..a23b9277741 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoSouthRectangle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoSouthRectangle.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box limited on three sides (top lat, left lon, right lon). The
* other corner is the south pole.
@@ -121,6 +125,22 @@ class GeoSouthRectangle extends GeoBaseBBox {
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoSouthRectangle(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, topLat);
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardCircle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardCircle.java
index ec83edf10b2..acba9f50053 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardCircle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardCircle.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Circular area with a center and radius.
*
@@ -91,6 +95,25 @@ class GeoStandardCircle extends GeoBaseCircle {
}
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoStandardCircle(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, center.getLatitude());
+ SerializableObject.writeDouble(outputStream, center.getLongitude());
+ SerializableObject.writeDouble(outputStream, cutoffAngle);
+ }
+
@Override
public double getRadius() {
return cutoffAngle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java
index b3b6594dbf2..c30414c7a26 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -63,7 +67,7 @@ class GeoStandardPath extends GeoBasePath {
Collections.addAll(points, pathPoints);
done();
}
-
+
/** Piece-wise constructor. Use in conjunction with addPoint() and done().
*@param planetModel is the planet model.
*@param maxCutoffAngle is the width of the path, measured as an angle.
@@ -193,6 +197,23 @@ class GeoStandardPath extends GeoBasePath {
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoStandardPath(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readPointArray(planetModel, inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, cutoffAngle);
+ SerializableObject.writePointArray(outputStream, points);
+ }
+
@Override
protected double distance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
// Algorithm:
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideDegenerateHorizontalLine.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideDegenerateHorizontalLine.java
index 90d35eef976..b22ce0f40a1 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideDegenerateHorizontalLine.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideDegenerateHorizontalLine.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Degenerate bounding box wider than PI and limited on two sides (left lon, right lon).
*
@@ -114,6 +118,22 @@ class GeoWideDegenerateHorizontalLine extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{centerPoint};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoWideDegenerateHorizontalLine(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, latitude);
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = latitude + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideLongitudeSlice.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideLongitudeSlice.java
index e15c27518c8..adf03d889ee 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideLongitudeSlice.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideLongitudeSlice.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box wider than PI but limited on left and right sides (
* left lon, right lon).
@@ -91,6 +95,21 @@ class GeoWideLongitudeSlice extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{planetModel.NORTH_POLE};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoWideLongitudeSlice(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
// Figuring out when we escalate to a special case requires some prefiguring
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideNorthRectangle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideNorthRectangle.java
index 5672003b9a5..7d0ccad11b6 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideNorthRectangle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideNorthRectangle.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box wider than PI but limited on three sides (
* bottom lat, left lon, right lon).
@@ -64,6 +68,10 @@ class GeoWideNorthRectangle extends GeoBaseBBox {
/**
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
* Horizontal angle must be greater than or equal to PI.
+ * @param planetModel is the planet model.
+ * @param bottomLat is the bottom latitude.
+ * @param leftLon is the left longitude.
+ * @param rightLon is the right longitude.
*/
public GeoWideNorthRectangle(final PlanetModel planetModel, final double bottomLat, final double leftLon, double rightLon) {
super(planetModel);
@@ -121,6 +129,22 @@ class GeoWideNorthRectangle extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{planetModel.NORTH_POLE};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoWideNorthRectangle(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, bottomLat);
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = Math.PI * 0.5;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideRectangle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideRectangle.java
index 43b9bc74624..b200e0cade8 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideRectangle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideRectangle.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box wider than PI but limited on four sides (top lat,
* bottom lat, left lon, right lon).
@@ -74,6 +78,11 @@ class GeoWideRectangle extends GeoBaseBBox {
/**
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
* Horizontal angle must be greater than or equal to PI.
+ * @param planetModel is the planet model.
+ * @param topLat is the top latitude.
+ * @param bottomLat is the bottom latitude.
+ * @param leftLon is the left longitude.
+ * @param rightLon is the right longitude.
*/
public GeoWideRectangle(final PlanetModel planetModel, final double topLat, final double bottomLat, final double leftLon, double rightLon) {
super(planetModel);
@@ -143,6 +152,23 @@ class GeoWideRectangle extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{ULHC};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoWideRectangle(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, topLat);
+ SerializableObject.writeDouble(outputStream, bottomLat);
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideSouthRectangle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideSouthRectangle.java
index ea60322f78b..eca4f6284c6 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideSouthRectangle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideSouthRectangle.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box wider than PI but limited on three sides (top lat,
* left lon, right lon).
@@ -64,6 +68,10 @@ class GeoWideSouthRectangle extends GeoBaseBBox {
/**
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
* Horizontal angle must be greater than or equal to PI.
+ * @param planetModel is the planet model.
+ * @param topLat is the top latitude.
+ * @param leftLon is the left longitude.
+ * @param rightLon is the right longitude.
*/
public GeoWideSouthRectangle(final PlanetModel planetModel, final double topLat, final double leftLon, double rightLon) {
super(planetModel);
@@ -122,6 +130,22 @@ class GeoWideSouthRectangle extends GeoBaseBBox {
this.edgePoints = new GeoPoint[]{planetModel.SOUTH_POLE};
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public GeoWideSouthRectangle(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel, SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream), SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, topLat);
+ SerializableObject.writeDouble(outputStream, leftLon);
+ SerializableObject.writeDouble(outputStream, rightLon);
+ }
+
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWorld.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWorld.java
index ebe11dbb1eb..641f09d10af 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWorld.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWorld.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* Bounding box including the entire world.
*
@@ -35,6 +39,19 @@ class GeoWorld extends GeoBaseBBox {
originPoint = new GeoPoint(planetModel.ab, 1.0, 0.0, 0.0);
}
+ /** Constructor.
+ *@param planetModel is the planet model.
+ *@param inputStream is the input stream.
+ */
+ public GeoWorld(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel);
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ // Nothing needed
+ }
+
@Override
public GeoBBox expand(final double angle) {
return this;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetObject.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetObject.java
index 836bf4ceba2..a0c175af68f 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetObject.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetObject.java
@@ -22,7 +22,7 @@ package org.apache.lucene.spatial3d.geom;
*
* @lucene.experimental
*/
-public interface PlanetObject {
+public interface PlanetObject extends SerializableObject {
/** Returns the {@link PlanetModel} provided when this shape was created. */
PlanetModel getPlanetModel();
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 618ebafcbd8..9479cf2170b 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
@@ -23,6 +23,8 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.BitSet;
/**
* Indicates that a geo3d object can be serialized and deserialized.
@@ -56,28 +58,40 @@ public interface SerializableObject {
try {
// Look for the class
final Class<?> clazz = Class.forName(className);
+ return readObject(planetModel, inputStream, clazz);
+ } catch (ClassNotFoundException e) {
+ throw new IOException("Can't find class "+className+" for deserialization: "+e.getMessage(), e);
+ }
+ }
+
+ /** Instantiate a serializable object from a stream.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ * @param clazz is the class to instantiate.
+ */
+ static SerializableObject readObject(final PlanetModel planetModel, final InputStream inputStream, final Class<?> clazz) throws IOException {
+ try {
// Look for the right constructor
final Constructor<?> c = clazz.getDeclaredConstructor(PlanetModel.class, InputStream.class);
// Invoke it
final Object object = c.newInstance(planetModel, inputStream);
// check whether caste will work
if (!(object instanceof SerializableObject)) {
- throw new IOException("Object "+className+" does not implement SerializableObject");
+ throw new IOException("Object "+clazz.getName()+" does not implement SerializableObject");
}
return (SerializableObject)object;
- } catch (ClassNotFoundException e) {
- throw new IOException("Can't find class "+className+" for deserialization: "+e.getMessage(), e);
} catch (InstantiationException e) {
- throw new IOException("Instantiation exception for class "+className+": "+e.getMessage(), e);
+ throw new IOException("Instantiation exception for class "+clazz.getName()+": "+e.getMessage(), e);
} catch (IllegalAccessException e) {
- throw new IOException("Illegal access creating class "+className+": "+e.getMessage(), e);
+ throw new IOException("Illegal access creating class "+clazz.getName()+": "+e.getMessage(), e);
} catch (NoSuchMethodException e) {
- throw new IOException("No such method exception for class "+className+": "+e.getMessage(), e);
+ throw new IOException("No such method exception for class "+clazz.getName()+": "+e.getMessage(), e);
} catch (InvocationTargetException e) {
- throw new IOException("Exception instantiating class "+className+": "+e.getMessage(), e);
+ throw new IOException("Exception instantiating class "+clazz.getName()+": "+e.getMessage(), e);
}
- }
+ }
+
/** Read an object from a stream (for objects that do not need a PlanetModel).
* @param inputStream is the input stream.
* @return the deserialized object.
@@ -88,36 +102,45 @@ public interface SerializableObject {
try {
// Look for the class
final Class<?> clazz = Class.forName(className);
+ return readObject(inputStream, clazz);
+ } catch (ClassNotFoundException e) {
+ throw new IOException("Can't find class "+className+" for deserialization: "+e.getMessage(), e);
+ }
+ }
+
+ /** Instantiate a serializable object from a stream without a planet model.
+ * @param inputStream is the input stream.
+ * @param clazz is the class to instantiate.
+ */
+ static SerializableObject readObject(final InputStream inputStream, final Class<?> clazz) throws IOException {
+ try {
// Look for the right constructor
final Constructor<?> c = clazz.getDeclaredConstructor(InputStream.class);
// Invoke it
final Object object = c.newInstance(inputStream);
// check whether caste will work
if (!(object instanceof SerializableObject)) {
- throw new IOException("Object "+className+" does not implement SerializableObject");
+ throw new IOException("Object "+clazz.getName()+" does not implement SerializableObject");
}
return (SerializableObject)object;
- } catch (ClassNotFoundException e) {
- throw new IOException("Can't find class "+className+" for deserialization: "+e.getMessage(), e);
} catch (InstantiationException e) {
- throw new IOException("Instantiation exception for class "+className+": "+e.getMessage(), e);
+ throw new IOException("Instantiation exception for class "+clazz.getName()+": "+e.getMessage(), e);
} catch (IllegalAccessException e) {
- throw new IOException("Illegal access creating class "+className+": "+e.getMessage(), e);
+ throw new IOException("Illegal access creating class "+clazz.getName()+": "+e.getMessage(), e);
} catch (NoSuchMethodException e) {
- throw new IOException("No such method exception for class "+className+": "+e.getMessage(), e);
+ throw new IOException("No such method exception for class "+clazz.getName()+": "+e.getMessage(), e);
} catch (InvocationTargetException e) {
- throw new IOException("Exception instantiating class "+className+": "+e.getMessage(), e);
+ throw new IOException("Exception instantiating class "+clazz.getName()+": "+e.getMessage(), e);
}
+
}
-
+
/** Write a string to a stream.
* @param outputStream is the output stream.
* @param value is the string to write.
*/
static void writeString(final OutputStream outputStream, final String value) throws IOException {
- final byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
- writeInt(outputStream, bytes.length);
- outputStream.write(bytes);
+ writeByteArray(outputStream, value.getBytes(StandardCharsets.UTF_8));
}
/** Read a string from a stream.
@@ -125,6 +148,162 @@ public interface SerializableObject {
* @return the string that was read.
*/
static String readString(final InputStream inputStream) throws IOException {
+ return new String(readByteArray(inputStream), StandardCharsets.UTF_8);
+ }
+
+ /** Write a point array.
+ * @param outputStream is the output stream.
+ * @param values is the array of points to write.
+ */
+ static void writePointArray(final OutputStream outputStream, final GeoPoint[] values) throws IOException {
+ writeHomogeneousArray(outputStream, values);
+ }
+
+ /** Write a point array.
+ * @param outputStream is the output stream.
+ * @param values is the list of points to write.
+ */
+ static void writePointArray(final OutputStream outputStream, final List<GeoPoint> values) throws IOException {
+ writeHomogeneousArray(outputStream, values);
+ }
+
+ /** Read a point array.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ * @return the array of points that was read.
+ */
+ static GeoPoint[] readPointArray(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ return (GeoPoint[])readHomogeneousArray(planetModel, inputStream, GeoPoint.class);
+ }
+
+ /** Write a polgon array.
+ * @param outputStream is the output stream.
+ * @param values is the array of points to write.
+ */
+ static void writePolygonArray(final OutputStream outputStream, final GeoPolygon[] values) throws IOException {
+ writeHeterogeneousArray(outputStream, values);
+ }
+
+ /** Write a polygon array.
+ * @param outputStream is the output stream.
+ * @param values is the list of points to write.
+ */
+ static void writePolygonArray(final OutputStream outputStream, final List<GeoPolygon> values) throws IOException {
+ writeHeterogeneousArray(outputStream, values);
+ }
+
+ /** Read a polygon array.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ * @return the array of polygons that was read.
+ */
+ static GeoPolygon[] readPolygonArray(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ return (GeoPolygon[])readHeterogeneousArray(planetModel, inputStream);
+ }
+
+ /** Write an array.
+ * @param outputStream is the output stream,.
+ * @param values is the array.
+ */
+ static void writeHomogeneousArray(final OutputStream outputStream, final SerializableObject[] values) throws IOException {
+ writeInt(outputStream, values.length);
+ for (final SerializableObject value : values) {
+ value.write(outputStream);
+ }
+ }
+
+ /** Write an array.
+ * @param outputStream is the output stream,.
+ * @param values is the array.
+ */
+ static void writeHomogeneousArray(final OutputStream outputStream, final List<? extends SerializableObject> values) throws IOException {
+ writeInt(outputStream, values.size());
+ for (final SerializableObject value : values) {
+ value.write(outputStream);
+ }
+ }
+
+ /** Read an array.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ * @param clazz is the class of the objects to read.
+ * @return the array.
+ */
+ static SerializableObject[] readHomogeneousArray(final PlanetModel planetModel, final InputStream inputStream, final Class<?> clazz) throws IOException {
+ final int count = readInt(inputStream);
+ final SerializableObject[] rval = new SerializableObject[count];
+ for (int i = 0; i < count; i++) {
+ rval[i] = readObject(planetModel, inputStream, clazz);
+ }
+ return rval;
+ }
+
+ /** Write an array.
+ * @param outputStream is the output stream,.
+ * @param values is the array.
+ */
+ static void writeHeterogeneousArray(final OutputStream outputStream, final SerializableObject[] values) throws IOException {
+ writeInt(outputStream, values.length);
+ for (final SerializableObject value : values) {
+ writeObject(outputStream, value);
+ }
+ }
+
+ /** Write an array.
+ * @param outputStream is the output stream,.
+ * @param values is the array.
+ */
+ static void writeHeterogeneousArray(final OutputStream outputStream, final List<? extends SerializableObject> values) throws IOException {
+ writeInt(outputStream, values.size());
+ for (final SerializableObject value : values) {
+ writeObject(outputStream, value);
+ }
+ }
+
+ /** Read an array.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ * @return the array.
+ */
+ static SerializableObject[] readHeterogeneousArray(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ final int count = readInt(inputStream);
+ final SerializableObject[] rval = new SerializableObject[count];
+ for (int i = 0; i < count; i++) {
+ rval[i] = readObject(planetModel, inputStream);
+ }
+ return rval;
+ }
+
+ /** Write a bitset to a stream.
+ * @param outputStream is the output stream.
+ * @param bitSet is the bit set to write.
+ */
+ static void writeBitSet(final OutputStream outputStream, final BitSet bitSet) throws IOException {
+ writeByteArray(outputStream, bitSet.toByteArray());
+ }
+
+ /** Read a bitset from a stream.
+ * @param inputStream is the input stream.
+ * @return the bitset read from the stream.
+ */
+ static BitSet readBitSet(final InputStream inputStream) throws IOException {
+ return BitSet.valueOf(readByteArray(inputStream));
+ }
+
+ /** Write byte array.
+ * @param outputStream is the output stream.
+ * @param bytes is the byte array.
+ */
+ static void writeByteArray(final OutputStream outputStream, final byte[] bytes) throws IOException {
+ writeInt(outputStream, bytes.length);
+ outputStream.write(bytes);
+ }
+
+ /** Read byte array.
+ * @param inputStream is the input stream.
+ * @return the byte array.
+ */
+ static byte[] readByteArray(final InputStream inputStream) throws IOException {
int stringLength = readInt(inputStream);
int stringOffset = 0;
final byte[] bytes = new byte[stringLength];
@@ -136,9 +315,9 @@ public interface SerializableObject {
stringOffset += amt;
stringLength -= amt;
}
- return new String(bytes, StandardCharsets.UTF_8);
+ return bytes;
}
-
+
/** Write a double to a stream.
* @param outputStream is the output stream.
* @param value is the value to write.
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/StandardXYZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/StandardXYZSolid.java
index 0f79f2460fb..8ad21e67132 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/StandardXYZSolid.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/StandardXYZSolid.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* 3D rectangle, bounded on six sides by X,Y,Z limits
*
@@ -23,6 +27,19 @@ package org.apache.lucene.spatial3d.geom;
*/
class StandardXYZSolid extends BaseXYZSolid {
+ /** Min-X */
+ protected final double minX;
+ /** Max-X */
+ protected final double maxX;
+ /** Min-Y */
+ protected final double minY;
+ /** Max-Y */
+ protected final double maxY;
+ /** Min-Z */
+ protected final double minZ;
+ /** Max-Z */
+ protected final double maxZ;
+
/** Whole world? */
protected final boolean isWholeWorld;
/** Min-X plane */
@@ -98,6 +115,13 @@ class StandardXYZSolid extends BaseXYZSolid {
if (maxZ - minZ < Vector.MINIMUM_RESOLUTION)
throw new IllegalArgumentException("Z values in wrong order or identical");
+ this.minX = minX;
+ this.maxX = maxX;
+ this.minY = minY;
+ this.maxY = maxY;
+ this.minZ = minZ;
+ this.maxZ = maxZ;
+
final double worldMinX = planetModel.getMinimumXValue();
final double worldMaxX = planetModel.getMaximumXValue();
final double worldMinY = planetModel.getMinimumYValue();
@@ -336,6 +360,31 @@ class StandardXYZSolid extends BaseXYZSolid {
}
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public StandardXYZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, minX);
+ SerializableObject.writeDouble(outputStream, maxX);
+ SerializableObject.writeDouble(outputStream, minY);
+ SerializableObject.writeDouble(outputStream, maxY);
+ SerializableObject.writeDouble(outputStream, minZ);
+ SerializableObject.writeDouble(outputStream, maxZ);
+ }
+
@Override
protected GeoPoint[] getEdgePoints() {
return edgePoints;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYdZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYdZSolid.java
index aa4b8734977..f5b2ae6d982 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYdZSolid.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYdZSolid.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* 3D rectangle, bounded on six sides by X,Y,Z limits, degenerate in Z
*
@@ -23,6 +27,17 @@ package org.apache.lucene.spatial3d.geom;
*/
class XYdZSolid extends BaseXYZSolid {
+ /** Min-X */
+ protected final double minX;
+ /** Max-X */
+ protected final double maxX;
+ /** Min-Y */
+ protected final double minY;
+ /** Max-Y */
+ protected final double maxY;
+ /** Z */
+ protected final double Z;
+
/** Min-X plane */
protected final SidedPlane minXPlane;
/** Max-X plane */
@@ -67,6 +82,12 @@ class XYdZSolid extends BaseXYZSolid {
if (maxY - minY < Vector.MINIMUM_RESOLUTION)
throw new IllegalArgumentException("Y values in wrong order or identical");
+ this.minX = minX;
+ this.maxX = maxX;
+ this.minY = minY;
+ this.maxY = maxY;
+ this.Z = Z;
+
final double worldMinZ = planetModel.getMinimumZValue();
final double worldMaxZ = planetModel.getMaximumZValue();
@@ -125,6 +146,29 @@ class XYdZSolid extends BaseXYZSolid {
this.edgePoints = glueTogether(minXZ, maxXZ, minYZ, maxYZ, zEdges);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public XYdZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, minX);
+ SerializableObject.writeDouble(outputStream, maxX);
+ SerializableObject.writeDouble(outputStream, minY);
+ SerializableObject.writeDouble(outputStream, maxY);
+ SerializableObject.writeDouble(outputStream, Z);
+ }
+
@Override
protected GeoPoint[] getEdgePoints() {
return edgePoints;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XdYZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XdYZSolid.java
index 37f2a46631d..3c11b4b7e52 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XdYZSolid.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XdYZSolid.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* 3D rectangle, bounded on six sides by X,Y,Z limits, degenerate in Y
*
@@ -23,6 +27,17 @@ package org.apache.lucene.spatial3d.geom;
*/
class XdYZSolid extends BaseXYZSolid {
+ /** Min-X */
+ protected final double minX;
+ /** Max-X */
+ protected final double maxX;
+ /** Y */
+ protected final double Y;
+ /** Min-Z */
+ protected final double minZ;
+ /** Max-Z */
+ protected final double maxZ;
+
/** Min-X plane */
protected final SidedPlane minXPlane;
/** Max-X plane */
@@ -67,6 +82,12 @@ class XdYZSolid extends BaseXYZSolid {
if (maxZ - minZ < Vector.MINIMUM_RESOLUTION)
throw new IllegalArgumentException("Z values in wrong order or identical");
+ this.minX = minX;
+ this.maxX = maxX;
+ this.Y = Y;
+ this.minZ = minZ;
+ this.maxZ = maxZ;
+
final double worldMinY = planetModel.getMinimumYValue();
final double worldMaxY = planetModel.getMaximumYValue();
@@ -125,6 +146,29 @@ class XdYZSolid extends BaseXYZSolid {
this.edgePoints = glueTogether(minXY, maxXY, YminZ, YmaxZ, yEdges);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public XdYZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, minX);
+ SerializableObject.writeDouble(outputStream, maxX);
+ SerializableObject.writeDouble(outputStream, Y);
+ SerializableObject.writeDouble(outputStream, minZ);
+ SerializableObject.writeDouble(outputStream, maxZ);
+ }
+
@Override
protected GeoPoint[] getEdgePoints() {
return edgePoints;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XdYdZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XdYdZSolid.java
index 936c184b9eb..7f0d9d154ed 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XdYdZSolid.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XdYdZSolid.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* 3D rectangle, bounded on six sides by X,Y,Z limits, degenerate in Y and Z.
* This figure, in fact, represents either zero, one, or two points, so the
@@ -25,6 +29,15 @@ package org.apache.lucene.spatial3d.geom;
*/
class XdYdZSolid extends BaseXYZSolid {
+ /** Min-X */
+ protected final double minX;
+ /** Max-X */
+ protected final double maxX;
+ /** Y */
+ protected final double Y;
+ /** Z */
+ protected final double Z;
+
/** The points in this figure on the planet surface; also doubles for edge points */
protected final GeoPoint[] surfacePoints;
@@ -47,6 +60,11 @@ class XdYdZSolid extends BaseXYZSolid {
if (maxX - minX < Vector.MINIMUM_RESOLUTION)
throw new IllegalArgumentException("X values in wrong order or identical");
+ this.minX = minX;
+ this.maxX = maxX;
+ this.Y = Y;
+ this.Z = Z;
+
// Build the planes and intersect them.
final Plane yPlane = new Plane(yUnitVector,-Y);
final Plane zPlane = new Plane(zUnitVector,-Z);
@@ -55,6 +73,27 @@ class XdYdZSolid extends BaseXYZSolid {
surfacePoints = yPlane.findIntersections(planetModel,zPlane,minXPlane,maxXPlane);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public XdYdZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, minX);
+ SerializableObject.writeDouble(outputStream, maxX);
+ SerializableObject.writeDouble(outputStream, Y);
+ SerializableObject.writeDouble(outputStream, Z);
+ }
+
@Override
protected GeoPoint[] getEdgePoints() {
return surfacePoints;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXYZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXYZSolid.java
index 029f2154d9e..e4f5adaca4e 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXYZSolid.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXYZSolid.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* 3D rectangle, bounded on six sides by X,Y,Z limits, degenerate in X.
*
@@ -23,6 +27,17 @@ package org.apache.lucene.spatial3d.geom;
*/
class dXYZSolid extends BaseXYZSolid {
+ /** X */
+ protected final double X;
+ /** Min-Y */
+ protected final double minY;
+ /** Max-Y */
+ protected final double maxY;
+ /** Min-Z */
+ protected final double minZ;
+ /** Max-Z */
+ protected final double maxZ;
+
/** X plane */
protected final Plane xPlane;
/** Min-Y plane */
@@ -67,6 +82,12 @@ class dXYZSolid extends BaseXYZSolid {
if (maxZ - minZ < Vector.MINIMUM_RESOLUTION)
throw new IllegalArgumentException("Z values in wrong order or identical");
+ this.X = X;
+ this.minY = minY;
+ this.maxY = maxY;
+ this.minZ = minZ;
+ this.maxZ = maxZ;
+
final double worldMinX = planetModel.getMinimumXValue();
final double worldMaxX = planetModel.getMaximumXValue();
@@ -126,6 +147,29 @@ class dXYZSolid extends BaseXYZSolid {
this.edgePoints = glueTogether(XminY,XmaxY,XminZ,XmaxZ,xEdges);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public dXYZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, X);
+ SerializableObject.writeDouble(outputStream, minY);
+ SerializableObject.writeDouble(outputStream, maxY);
+ SerializableObject.writeDouble(outputStream, minZ);
+ SerializableObject.writeDouble(outputStream, maxZ);
+ }
+
@Override
protected GeoPoint[] getEdgePoints() {
return edgePoints;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXYdZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXYdZSolid.java
index a1b5e96da2a..0587bc292f9 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXYdZSolid.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXYdZSolid.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* 3D rectangle, bounded on six sides by X,Y,Z limits, degenerate in X and Z.
* This figure, in fact, represents either zero, one, or two points, so the
@@ -25,6 +29,15 @@ package org.apache.lucene.spatial3d.geom;
*/
class dXYdZSolid extends BaseXYZSolid {
+ /** X */
+ protected final double X;
+ /** Min-Y */
+ protected final double minY;
+ /** Max-Y */
+ protected final double maxY;
+ /** Z */
+ protected final double Z;
+
/** The points in this figure on the planet surface; also doubles for edge points */
protected final GeoPoint[] surfacePoints;
@@ -47,6 +60,11 @@ class dXYdZSolid extends BaseXYZSolid {
if (maxY - minY < Vector.MINIMUM_RESOLUTION)
throw new IllegalArgumentException("Y values in wrong order or identical");
+ this.X = X;
+ this.minY = minY;
+ this.maxY = maxY;
+ this.Z = Z;
+
// Build the planes and intersect them.
final Plane xPlane = new Plane(xUnitVector,-X);
final Plane zPlane = new Plane(zUnitVector,-Z);
@@ -55,6 +73,27 @@ class dXYdZSolid extends BaseXYZSolid {
surfacePoints = xPlane.findIntersections(planetModel,zPlane,minYPlane,maxYPlane);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public dXYdZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, X);
+ SerializableObject.writeDouble(outputStream, minY);
+ SerializableObject.writeDouble(outputStream, maxY);
+ SerializableObject.writeDouble(outputStream, Z);
+ }
+
@Override
protected GeoPoint[] getEdgePoints() {
return surfacePoints;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXdYZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXdYZSolid.java
index 869ddeac989..3dfa6ec6d55 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXdYZSolid.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXdYZSolid.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* 3D rectangle, bounded on six sides by X,Y,Z limits, degenerate in X and Y.
* This figure, in fact, represents either zero, one, or two points, so the
@@ -25,6 +29,15 @@ package org.apache.lucene.spatial3d.geom;
*/
class dXdYZSolid extends BaseXYZSolid {
+ /** X */
+ protected final double X;
+ /** Y */
+ protected final double Y;
+ /** Min-Z */
+ protected final double minZ;
+ /** Max-Z */
+ protected final double maxZ;
+
/** The points in this figure on the planet surface; also doubles for edge points */
protected final GeoPoint[] surfacePoints;
@@ -47,6 +60,11 @@ class dXdYZSolid extends BaseXYZSolid {
if (maxZ - minZ < Vector.MINIMUM_RESOLUTION)
throw new IllegalArgumentException("Z values in wrong order or identical");
+ this.X = X;
+ this.Y = Y;
+ this.minZ = minZ;
+ this.maxZ = maxZ;
+
// Build the planes and intersect them.
final Plane xPlane = new Plane(xUnitVector,-X);
final Plane yPlane = new Plane(yUnitVector,-Y);
@@ -55,6 +73,27 @@ class dXdYZSolid extends BaseXYZSolid {
surfacePoints = xPlane.findIntersections(planetModel,yPlane,minZPlane,maxZPlane);
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public dXdYZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, X);
+ SerializableObject.writeDouble(outputStream, Y);
+ SerializableObject.writeDouble(outputStream, minZ);
+ SerializableObject.writeDouble(outputStream, maxZ);
+ }
+
@Override
protected GeoPoint[] getEdgePoints() {
return surfacePoints;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXdYdZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXdYdZSolid.java
index b647658072b..61b2608dd0c 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXdYdZSolid.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/dXdYdZSolid.java
@@ -16,6 +16,10 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
/**
* 3D rectangle, bounded on six sides by X,Y,Z limits, degenerate in all dimensions
*
@@ -23,6 +27,13 @@ package org.apache.lucene.spatial3d.geom;
*/
class dXdYdZSolid extends BaseXYZSolid {
+ /** X */
+ protected final double X;
+ /** Y */
+ protected final double Y;
+ /** Z */
+ protected final double Z;
+
/** On surface? */
protected final boolean isOnSurface;
/** The point */
@@ -51,6 +62,11 @@ class dXdYdZSolid extends BaseXYZSolid {
final double Y,
final double Z) {
super(planetModel);
+
+ this.X = X;
+ this.Y = Y;
+ this.Z = Z;
+
isOnSurface = planetModel.pointOnSurface(X,Y,Z);
if (isOnSurface) {
thePoint = new GeoPoint(X,Y,Z);
@@ -61,6 +77,25 @@ class dXdYdZSolid extends BaseXYZSolid {
}
}
+ /**
+ * Constructor for deserialization.
+ * @param planetModel is the planet model.
+ * @param inputStream is the input stream.
+ */
+ public dXdYdZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
+ this(planetModel,
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream),
+ SerializableObject.readDouble(inputStream));
+ }
+
+ @Override
+ public void write(final OutputStream outputStream) throws IOException {
+ SerializableObject.writeDouble(outputStream, X);
+ SerializableObject.writeDouble(outputStream, Y);
+ SerializableObject.writeDouble(outputStream, Z);
+ }
+
@Override
protected GeoPoint[] getEdgePoints() {
return edgePoints;