diff --git a/README.md b/README.md index b1cc8574..8b3e72a4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ ![Build Status](https://github.com/GeoLatte/geolatte-geom/workflows/Java%20CI/badge.svg) +[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/GeoLatte/geolatte-geom.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/GeoLatte/geolatte-geom/context:java) # Geolatte-geom diff --git a/geom/src/main/java/org/geolatte/geom/AbstractPositionSequence.java b/geom/src/main/java/org/geolatte/geom/AbstractPositionSequence.java index 5b1f079e..99d9e943 100644 --- a/geom/src/main/java/org/geolatte/geom/AbstractPositionSequence.java +++ b/geom/src/main/java/org/geolatte/geom/AbstractPositionSequence.java @@ -31,6 +31,8 @@ */ abstract class AbstractPositionSequence<P extends Position> implements PositionSequence<P>, CoordinateSequence, Serializable { + private static final long serialVersionUID = 6884205871950410216L; + private final PositionFactory<P> factory; public AbstractPositionSequence(PositionFactory<P> factory) { diff --git a/geom/src/main/java/org/geolatte/geom/Positions.java b/geom/src/main/java/org/geolatte/geom/Positions.java index 1c65135e..aea6984a 100644 --- a/geom/src/main/java/org/geolatte/geom/Positions.java +++ b/geom/src/main/java/org/geolatte/geom/Positions.java @@ -149,7 +149,7 @@ public static <Q extends Position, P extends Position> PositionSequence<P> copy( final Class<P> targetPosClass) { return copy(source, targetPosClass, Double.NaN); } - + //Factories public static class CanMakeP2D implements PositionFactory<C2D> { diff --git a/geom/src/main/java/org/geolatte/geom/crs/CoordinateSystem.java b/geom/src/main/java/org/geolatte/geom/crs/CoordinateSystem.java index 1ee2097f..40f0afa1 100644 --- a/geom/src/main/java/org/geolatte/geom/crs/CoordinateSystem.java +++ b/geom/src/main/java/org/geolatte/geom/crs/CoordinateSystem.java @@ -23,6 +23,7 @@ import org.geolatte.geom.Position; +import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -37,7 +38,9 @@ * @author Karel Maesen, Geovise BVBA * creation-date: 4/29/11 */ -abstract public class CoordinateSystem<P extends Position> { +abstract public class CoordinateSystem<P extends Position> implements Serializable { + + private static final long serialVersionUID = 6884205871950410216L; private final CoordinateSystemAxis[] axes; diff --git a/geom/src/main/java/org/geolatte/geom/crs/CoordinateSystemAxis.java b/geom/src/main/java/org/geolatte/geom/crs/CoordinateSystemAxis.java index fec6b415..cfad6e4c 100644 --- a/geom/src/main/java/org/geolatte/geom/crs/CoordinateSystemAxis.java +++ b/geom/src/main/java/org/geolatte/geom/crs/CoordinateSystemAxis.java @@ -21,13 +21,18 @@ package org.geolatte.geom.crs; +import java.io.Serializable; +import java.util.Objects; + /** * An axis of a <code>CoordinateSystem.</code> * * @author Karel Maesen, Geovise BVBA * creation-date: 4/29/11 */ -abstract public class CoordinateSystemAxis { +abstract public class CoordinateSystemAxis implements Serializable { + + private static final long serialVersionUID = 6884205871950410216L; private final String axisName; private final CoordinateSystemAxisDirection coordinateSystemAxisDirection; @@ -87,7 +92,7 @@ public static StraightLineAxis mkZAxis() { /** * Returns the name of this axis. * - * @return + * @return the Axis name */ public String getAxisName() { return axisName; @@ -119,10 +124,10 @@ public boolean equals(Object o) { CoordinateSystemAxis that = (CoordinateSystemAxis) o; - if (axisName != null ? !axisName.equals(that.axisName) : that.axisName != null) return false; + if (!Objects.equals(axisName, that.axisName)) return false; if (coordinateSystemAxisDirection != that.coordinateSystemAxisDirection) return false; if (normalOrder != that.normalOrder) return false; - return !(unit != null ? !unit.equals(that.unit) : that.unit != null); + return Objects.equals(unit, that.unit); } @Override diff --git a/geom/src/main/java/org/geolatte/geom/crs/CrsId.java b/geom/src/main/java/org/geolatte/geom/crs/CrsId.java index f41df53c..487ab888 100644 --- a/geom/src/main/java/org/geolatte/geom/crs/CrsId.java +++ b/geom/src/main/java/org/geolatte/geom/crs/CrsId.java @@ -1,5 +1,7 @@ package org.geolatte.geom.crs; +import java.io.Serializable; + /** * An identifier for a <code>CoordinateReferenceSystem</code> or other object referenced in a * <code>CoordinateReferenceSystem</code> definition. @@ -14,7 +16,9 @@ * * @author Karel Maesen, Geovise BVBA, 2011 */ -public class CrsId { +public class CrsId implements Serializable { + + private static final long serialVersionUID = 6884205871950410216L; final static public String DEFAULT_AUTHORITY = "EPSG"; diff --git a/geom/src/main/java/org/geolatte/geom/crs/CrsIdentifiable.java b/geom/src/main/java/org/geolatte/geom/crs/CrsIdentifiable.java index e00f33eb..60f98263 100644 --- a/geom/src/main/java/org/geolatte/geom/crs/CrsIdentifiable.java +++ b/geom/src/main/java/org/geolatte/geom/crs/CrsIdentifiable.java @@ -21,6 +21,8 @@ package org.geolatte.geom.crs; +import java.io.Serializable; + /** * Abstract base class for classes the are identified by a <code>CrsId</code> (e.g. by EPSG-code). * @@ -32,7 +34,9 @@ * @author Karel Maesen, Geovise BVBA * creation-date: 11/21/11 */ -abstract public class CrsIdentifiable { +abstract public class CrsIdentifiable implements Serializable { + + private static final long serialVersionUID = 6884205871950410216L; private final CrsId crsId; private final String name; diff --git a/geom/src/main/java/org/geolatte/geom/jts/PointSequenceCoordinateSequenceFactory.java b/geom/src/main/java/org/geolatte/geom/jts/PointSequenceCoordinateSequenceFactory.java index ec0e8b5b..d3dd05b6 100644 --- a/geom/src/main/java/org/geolatte/geom/jts/PointSequenceCoordinateSequenceFactory.java +++ b/geom/src/main/java/org/geolatte/geom/jts/PointSequenceCoordinateSequenceFactory.java @@ -42,6 +42,8 @@ */ class PointSequenceCoordinateSequenceFactory implements CoordinateSequenceFactory, Serializable { + private static final long serialVersionUID = 6884205871950410216L; + @Override public CoordinateSequence create(Coordinate[] coordinates) { CoordinateReferenceSystem<?> crs = determineCRS(coordinates); diff --git a/geom/src/test/java/org/geolatte/geom/crs/SerializableTest.java b/geom/src/test/java/org/geolatte/geom/crs/SerializableTest.java new file mode 100644 index 00000000..a31fb37b --- /dev/null +++ b/geom/src/test/java/org/geolatte/geom/crs/SerializableTest.java @@ -0,0 +1,40 @@ +package org.geolatte.geom.crs; + +import org.geolatte.geom.G3D; +import org.geolatte.geom.G3DM; +import org.junit.Test; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.Assert.assertEquals; + +public class SerializableTest { + + @Test + public void testCastToSerializable() throws IOException, ClassNotFoundException { + CoordinateReferenceSystem<G3DM> crs = CoordinateReferenceSystems.WGS84 + .addVerticalSystem(LinearUnit.METER,G3D.class) + .addLinearSystem(LinearUnit.METER, G3DM.class); + + Serializable ser = (Serializable) crs; + Path tmpDir = Paths.get("/tmp"); + File tempFile = Files.createTempFile(tmpDir, "", ".ser").toFile(); + tempFile.deleteOnExit(); + try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(tempFile))){ + out.writeObject(crs); + }; + + CoordinateReferenceSystem<G3DM> deser; + try (ObjectInputStream ins = new ObjectInputStream(new FileInputStream(tempFile))) { + deser = (CoordinateReferenceSystem<G3DM>) ins.readObject(); + } + + assertEquals(crs, deser); + + } + + +}