Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ For more information on the formats supported, see [FORMATS.md](FORMATS.md).

## Dependencies

Spatial4j runs on Java -- version 1.7 or better, though is only really tested on 1.8. Otherwise, all dependencies listed in the maven [pom.xml](pom.xml) are either marked optional or are for testing. The optional dependencies are:
Spatial4j runs on Java 8 (v1.8) or better. Otherwise, all dependencies listed in the maven [pom.xml](pom.xml) are either marked optional or are for testing. The optional dependencies are:
* [JTS](https://github.com/locationtech/jts): You need JTS if you use polygons, or obviously if you use any of the classes prefixed with "Jts".
* [Noggit](https://github.com/yonik/noggit): The Noggit JSON parsing library is only needed for GeoJSON parsing (not required for writing).
* [Jackson-databind](https://github.com/FasterXML/jackson-databind): If you wish to use Spatial4j's Jackson-databind feature to read/write shapes.
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
<properties>
<!-- this magic system property is honored by many plugins: http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<!-- To check for new plugins and dependencies:
Expand Down Expand Up @@ -197,10 +199,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
<showDeprecation>false</showDeprecation><!-- for time being -->
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>

Expand Down Expand Up @@ -233,7 +234,6 @@
The checker simply passes by default and only prints a warning.
-->
<failOnUnsupportedJava>false</failOnUnsupportedJava>
<targetVersion>1.7</targetVersion>
</configuration>
</plugin>

Expand Down Expand Up @@ -334,7 +334,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8</version>
<version>3.0.0</version>
</plugin>

<plugin>
Expand All @@ -344,7 +344,6 @@
<configuration>
<linkXRef>true</linkXRef>
<minimumTokens>100</minimumTokens>
<targetJdk>1.7</targetJdk>
</configuration>
</plugin>

Expand Down Expand Up @@ -381,14 +380,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>3.2.0</version>
<configuration>
<header>Spatial4j, ${project.version}</header>
<footer>Spatial4j, ${project.version}</footer>
<doctitle>Spatial4j, ${project.version}</doctitle>
<links>
<link>http://locationtech.github.io/jts/javadoc/</link>
</links>
<doclint>all,-missing</doclint>
</configuration>
<!-- we exclude tests: -->
<reportSets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ public Shape readShapeFromWkt(String wkt) throws ParseException, InvalidShapeExc
/**
* Try to read a shape from any supported formats
*
* @param value
* @return shape or null if unable to parse any shape
* @throws InvalidShapeException
*/
@Deprecated
public Shape readShape(String value) throws InvalidShapeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public class SpatialContextFactory {

public Class<? extends ShapeFactory> shapeFactoryClass = ShapeFactoryImpl.class;
public Class<? extends BinaryCodec> binaryCodecClass = BinaryCodec.class;
public final List<Class<? extends ShapeReader>> readers = new ArrayList<Class<? extends ShapeReader>>();
public final List<Class<? extends ShapeWriter>> writers = new ArrayList<Class<? extends ShapeWriter>>();
public final List<Class<? extends ShapeReader>> readers = new ArrayList<>();
public final List<Class<? extends ShapeWriter>> writers = new ArrayList<>();
public boolean hasFormatConfig = false;

public SpatialContextFactory() {
Expand Down Expand Up @@ -99,7 +99,7 @@ public static SpatialContext makeSpatialContext(Map<String,String> args, ClassLo
instance = new SpatialContextFactory();
else {
try {
Class c = classLoader.loadClass(cname);
Class<?> c = classLoader.loadClass(cname);
instance = (SpatialContextFactory) c.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -129,6 +129,7 @@ protected void init(Map<String, String> args, ClassLoader classLoader) {
}

/** Gets {@code name} from args and populates a field by the same name with the value. */
@SuppressWarnings("unchecked")
protected void initField(String name) {
// note: java.beans API is more verbose to use correctly (?) but would arguably be better
Field field;
Expand Down Expand Up @@ -218,7 +219,7 @@ protected void initFormats() {
public SupportedFormats makeFormats(SpatialContext ctx) {
checkDefaultFormats(); // easy to override

List<ShapeReader> read = new ArrayList<ShapeReader>(readers.size());
List<ShapeReader> read = new ArrayList<>(readers.size());
for (Class<? extends ShapeReader> clazz : readers) {
try {
read.add(makeClassInstance(clazz, ctx, this));
Expand All @@ -227,7 +228,7 @@ public SupportedFormats makeFormats(SpatialContext ctx) {
}
}

List<ShapeWriter> write = new ArrayList<ShapeWriter>(writers.size());
List<ShapeWriter> write = new ArrayList<>(writers.size());
for (Class<? extends ShapeWriter> clazz : writers) {
try {
write.add(makeClassInstance(clazz, ctx, this));
Expand Down Expand Up @@ -295,14 +296,13 @@ public BinaryCodec makeBinaryCodec(SpatialContext ctx) {
return makeClassInstance(binaryCodecClass, ctx, this);
}

@SuppressWarnings("unchecked")
private <T> T makeClassInstance(Class<? extends T> clazz, Object... ctorArgs) {
try {
Constructor<?> empty = null;

//can't simply lookup constructor by arg type because might be subclass type
ctorLoop: for (Constructor<?> ctor : clazz.getConstructors()) {
Class[] parameterTypes = ctor.getParameterTypes();
Class<?>[] parameterTypes = ctor.getParameterTypes();
if (parameterTypes.length == 0) {
empty = ctor; // the empty constructor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public static double[] vectorBoxCorner(double[] center, double[] result, double
* @param startLon The starting point longitude, in radians
* @param distanceRAD The distance to travel along the bearing in radians.
* @param bearingRAD The bearing, in radians. North is a 0, moving clockwise till radians(360).
* @param ctx
* @param reuse A preallocated object to hold the results.
* @return The destination point, IN RADIANS.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void writeCircle(DataOutput dataOutput, Circle c) throws IOException {
public ShapeCollection readCollection(DataInput dataInput) throws IOException {
byte type = dataInput.readByte();
int size = dataInput.readInt();
ArrayList<Shape> shapes = new ArrayList<Shape>(size);
ArrayList<Shape> shapes = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
if (type == 0) {
shapes.add(readShape(dataInput));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected Shape readShape(JSONParser parser) throws IOException, ParseException
readUntilEvent(parser, JSONParser.OBJECT_END);
return shape;
} else if ("geometries".equals(key)) {
List<Shape> shapes = new ArrayList<Shape>();
List<Shape> shapes = new ArrayList<>();
int sub = parser.nextEvent();
while (sub != JSONParser.EOF) {
if (sub == JSONParser.OBJECT_START) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public final Shape read(Reader r) throws ParseException, IOException

if(lastShape!=null) {
if(shapes==null) {
shapes = new ArrayList<Shape>();
shapes = new ArrayList<>();
}
shapes.add(lastShape);
}
Expand Down Expand Up @@ -174,7 +174,6 @@ protected Shape readPolygon(XReader reader) throws IOException {
reader.readPoints(polyBuilder);

if(!reader.isDone() && reader.peek()==PolyshapeWriter.KEY_ARG_START) {
List<LinearRing> list = new ArrayList<LinearRing>();
while(reader.isEvent() && reader.peek()==PolyshapeWriter.KEY_ARG_START) {
reader.readKey(); // eat the event;
reader.readPoints(polyBuilder.hole()).endHole();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void write(Encoder enc, Shape shape) throws IOException {
return;
}
if (shape instanceof ShapeCollection) {
ShapeCollection v = (ShapeCollection) shape;
@SuppressWarnings("unchecked") ShapeCollection<Shape> v = (ShapeCollection<Shape>) shape;
Iterator<Shape> iter = v.iterator();
while(iter.hasNext()) {
write(enc, iter.next());
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/locationtech/spatial4j/io/ShapeReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public interface ShapeReader extends ShapeIO {
*
* @param reader -- the input. Note, it will not be closed by this function
* @return a valid Shape (never null)
* @throws IOException
* @throws ParseException
* @throws InvalidShapeException
*/
public Shape read(Reader reader) throws IOException, ParseException, InvalidShapeException;
}
1 change: 0 additions & 1 deletion src/main/java/org/locationtech/spatial4j/io/WKTReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ protected State newState(String wktString) {
* dimension and EMPTY token via
* {@link org.locationtech.spatial4j.io.WKTReader.State#nextIfEmptyAndSkipZM()}.
*
* @param state
* @param shapeType Non-Null string; could have mixed case. The first character is a letter.
* @return The shape or null if not supported / unknown.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private JtsShapeFactory getShapeFactory() {

/**
* Reads WKT from the {@code str} via JTS's {@link org.locationtech.jts.io.WKTReader}.
* @param str
*
* @param reader <pre>new WKTReader(ctx.getGeometryFactory()))</pre>
* @return Non-Null
*/
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/locationtech/spatial4j/shape/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ public interface Point extends Shape {
public double getY();

/** Convenience method that usually maps on {@link org.locationtech.spatial4j.shape.Point#getY()} */
public double getLat();
public default double getLat() {
return getY();
}

/** Convenience method that usually maps on {@link org.locationtech.spatial4j.shape.Point#getX()} */
public double getLon();
public default double getLon() {
return getX();
}

}
2 changes: 0 additions & 2 deletions src/main/java/org/locationtech/spatial4j/shape/Shape.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public interface Shape {
* rounded-corner buffer, although some shapes might buffer differently. This
* is an optional operation.
*
*
* @param distance
* @return Not null, and the returned shape should contain the current shape.
*/
Shape getBuffered(double distance, SpatialContext ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class ShapeCollection<S extends Shape> extends AbstractList<S> implements
/**
* WARNING: {@code shapes} is copied by reference.
* @param shapes Copied by reference! (make a defensive copy if caller modifies)
* @param ctx
*/
public ShapeCollection(List<S> shapes, SpatialContext ctx) {
if (!(shapes instanceof RandomAccess))
Expand Down Expand Up @@ -100,7 +99,7 @@ public boolean hasArea() {

@Override
public ShapeCollection getBuffered(double distance, SpatialContext ctx) {
List<Shape> bufColl = new ArrayList<Shape>(size());
List<Shape> bufColl = new ArrayList<>(size());
for (Shape shape : shapes) {
bufColl.add(shape.getBuffered(distance, ctx));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public interface ShapeFactory {
Point pointXY(double x, double y);

/** Construct a point of latitude, longitude coordinates */
Point pointLatLon(double latitude, double longitude);
default Point pointLatLon(double latitude, double longitude) {
return pointXY(longitude, latitude);
}

/** Construct a point of 3 dimensions. The implementation might ignore unsupported
* dimensions like 'z' or throw an error. */
Expand Down Expand Up @@ -133,7 +135,9 @@ interface PointsBuilder<T> {
/** @see ShapeFactory#pointXYZ(double, double, double) */
T pointXYZ(double x, double y, double z);
/** @see ShapeFactory#pointLatLon(double, double) */
T pointLatLon(double latitude, double longitude);
default T pointLatLon(double latitude, double longitude) {
return pointXY(longitude, latitude);
}
}

/** @see #lineString() */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class BufferedLine extends BaseShape<SpatialContext> {
* @param pA start point
* @param pB end point
* @param buf the buffer distance in degrees
* @param ctx
*/
public BufferedLine(Point pA, Point pB, double buf, SpatialContext ctx) {
super(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public BufferedLineString(List<Point> points, double buf, SpatialContext ctx) {
* org.locationtech.spatial4j.shape.Point, double)}.
* If true then the buffer for each segment
* is computed.
* @param ctx
*/
public BufferedLineString(List<Point> points, double buf, boolean expandBufForLongitudeSkew,
SpatialContext ctx) {
Expand All @@ -60,7 +59,7 @@ public BufferedLineString(List<Point> points, double buf, boolean expandBufForLo
if (points.isEmpty()) {
this.segments = ctx.makeCollection(Collections.<BufferedLine>emptyList());
} else {
List<BufferedLine> segments = new ArrayList<BufferedLine>(points.size() - 1);
List<BufferedLine> segments = new ArrayList<>(points.size() - 1);

Point prevPoint = null;
for (Point point : points) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ public Point pointXY(double x, double y) {
return new PointImpl(x, y, ctx);
}

@Override
public Point pointLatLon(double latitude, double longitude) {
verifyX(longitude);
verifyY(latitude);
return new PointImpl(longitude, latitude, ctx);
}

@Override
public Point pointXYZ(double x, double y, double z) {
return pointXY(x, y); // or throw?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ private static Geometry cutUnwrappedGeomInto360(Geometry geom) {
return geom;
assert geom.isValid() : "geom";

List<Geometry> geomList = new ArrayList<Geometry>();
List<Geometry> geomList = new ArrayList<>();
//page 0 is the standard -180 to 180 range
int startPage = (int) Math.floor((geomEnv.getMinX() + 180) / 360);
for (int page = startPage; true; page++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,6 @@ public T pointXYZ(double x, double y, double z) {
return getThis();
}

public T pointLatLon(double latitude, double longitude) {
return pointXYZ(longitude, latitude, Coordinate.NULL_ORDINATE);
}
// TODO would be be useful to add other ways of providing points? e.g. point(Coordinate)?

// TODO consider wrapping the List<Coordinate> in a custom CoordinateSequence and then (conditionally) use
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/locationtech/spatial4j/TestLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class TestLog extends TestRuleAdapter {

//TODO does this need to be threadsafe (such as via thread-local state)?
private static ArrayList<LogEntry> logStack = new ArrayList<LogEntry>();
private static ArrayList<LogEntry> logStack = new ArrayList<>();
private static final int MAX_LOGS = 1000;

public static final TestLog instance = new TestLog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void tearDown() {
}

private SpatialContext call(String... argsStr) {
Map<String,String> args = new HashMap<String,String>();
Map<String,String> args = new HashMap<>();
for (int i = 0; i < argsStr.length; i+=2) {
String key = argsStr[i];
String val = argsStr[i+1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testCircle() throws Exception {

@Test
public void testCollection() throws Exception {
ShapeCollection s = ctx.makeCollection(
ShapeCollection<Shape> s = ctx.makeCollection(
Arrays.asList(
randomShape(),
randomShape(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testToStringOnEmptyPoint() throws Exception {
@Test
public void testToStringOnEmptyShapeCollection() throws Exception {
ShapeWriter writer = ctx.getFormats().getWktWriter();
ShapeCollection<Point> emptyCollection = ctx.makeCollection(new ArrayList<Point>());
ShapeCollection<Point> emptyCollection = ctx.makeCollection(new ArrayList<>());

assertEquals("GEOMETRYCOLLECTION EMPTY", writer.toString(emptyCollection));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected BufferedLineString generateRandomShape(Point nearP) {
Rectangle nearR = randomRectangle(nearP);
int numPoints = 2 + randomInt(3);//2-5 points

ArrayList<Point> points = new ArrayList<Point>(numPoints);
ArrayList<Point> points = new ArrayList<>(numPoints);
while (points.size() < numPoints) {
points.add(randomPointIn(nearR));
}
Expand Down
Loading