DATACMNS-482 - Added serialization support for Geospatial Types.

Added Serializable marker interface to Shape to make all geospatial types serializable. Changed equals implementation in GeoResults to use equals(…) instead of reference equality.

Original pull request: #77.
This commit is contained in:
Thomas Darimont
2014-03-31 10:10:55 +02:00
committed by Oliver Gierke
parent 9bd8e4db81
commit a30068c02d
17 changed files with 126 additions and 7 deletions

View File

@@ -27,6 +27,8 @@ import org.springframework.util.Assert;
*/
public class Box implements Shape {
private static final long serialVersionUID = 8198095179084040711L;
private final Point first;
private final Point second;

View File

@@ -28,6 +28,8 @@ import org.springframework.util.Assert;
*/
public class Circle implements Shape {
private static final long serialVersionUID = 5215611530535947924L;
private final Point center;
private final Distance radius;

View File

@@ -24,6 +24,8 @@ package org.springframework.data.geo;
*/
public class CustomMetric implements Metric {
private static final long serialVersionUID = -2972074177454114228L;
private final double multiplier;
/**

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.geo;
import java.io.Serializable;
import org.springframework.util.Assert;
/**
@@ -24,7 +26,9 @@ import org.springframework.util.Assert;
* @author Thomas Darimont
* @since 1.8
*/
public class Distance {
public class Distance implements Serializable {
private static final long serialVersionUID = 2460886201934027744L;
private final double value;
private final Metric metric;

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.geo;
import java.io.Serializable;
import org.springframework.util.Assert;
/**
@@ -24,7 +26,9 @@ import org.springframework.util.Assert;
* @author Thomas Darimont
* @since 1.8
*/
public class GeoResult<T> {
public class GeoResult<T> implements Serializable {
private static final long serialVersionUID = 1637452570977581370L;
private final T content;
private final Distance distance;

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.geo;
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -30,7 +31,9 @@ import org.springframework.util.StringUtils;
* @author Thomas Darimont
* @since 1.8
*/
public class GeoResults<T> implements Iterable<GeoResult<T>> {
public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable {
private static final long serialVersionUID = 8347363491300219485L;
private final List<? extends GeoResult<T>> results;
private final Distance averageDistance;
@@ -115,7 +118,7 @@ public class GeoResults<T> implements Iterable<GeoResult<T>> {
GeoResults<?> that = (GeoResults<?>) obj;
return this.results.equals(that.results) && this.averageDistance == that.averageDistance;
return this.results.equals(that.results) && this.averageDistance.equals(that.averageDistance);
}
/*

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.geo;
import java.io.Serializable;
/**
* Interface for {@link Metric}s that can be applied to a base scale.
*
@@ -22,7 +24,7 @@ package org.springframework.data.geo;
* @author Thomas Darimont
* @since 1.8
*/
public interface Metric {
public interface Metric extends Serializable {
/**
* Returns the multiplier to calculate metrics values from a base scale.

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.geo;
import java.io.Serializable;
import java.util.Locale;
import org.springframework.data.annotation.PersistenceConstructor;
@@ -28,7 +29,9 @@ import org.springframework.util.Assert;
* @author Thomas Darimont
* @since 1.8
*/
public class Point {
public class Point implements Serializable {
private static final long serialVersionUID = 3583151228933783558L;
private final double x;
private final double y;

View File

@@ -34,6 +34,8 @@ import org.springframework.util.StringUtils;
*/
public class Polygon implements Iterable<Point>, Shape {
private static final long serialVersionUID = -2705040068154648988L;
private final List<Point> points;
/**

View File

@@ -15,10 +15,12 @@
*/
package org.springframework.data.geo;
import java.io.Serializable;
/**
* Common interface for all shapes. Allows building external representations of them.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
public interface Shape {}
public interface Shape extends Serializable {}