Skip to content

Commit 5d74f96

Browse files
committed
Lang: resolve unchecked generics
And suppress deprecation warnings for now.
1 parent 1e4151b commit 5d74f96

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@
200200
<artifactId>maven-compiler-plugin</artifactId>
201201
<configuration>
202202
<optimize>true</optimize>
203-
<showDeprecation>true</showDeprecation>
203+
<showDeprecation>false</showDeprecation><!-- for time being -->
204+
<compilerArgument>-Xlint:unchecked</compilerArgument>
204205
</configuration>
205206
</plugin>
206207

src/main/java/org/locationtech/spatial4j/context/SpatialContextFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static SpatialContext makeSpatialContext(Map<String,String> args, ClassLo
9999
instance = new SpatialContextFactory();
100100
else {
101101
try {
102-
Class c = classLoader.loadClass(cname);
102+
Class<?> c = classLoader.loadClass(cname);
103103
instance = (SpatialContextFactory) c.newInstance();
104104
} catch (Exception e) {
105105
throw new RuntimeException(e);
@@ -129,6 +129,7 @@ protected void init(Map<String, String> args, ClassLoader classLoader) {
129129
}
130130

131131
/** Gets {@code name} from args and populates a field by the same name with the value. */
132+
@SuppressWarnings("unchecked")
132133
protected void initField(String name) {
133134
// note: java.beans API is more verbose to use correctly (?) but would arguably be better
134135
Field field;
@@ -295,14 +296,13 @@ public BinaryCodec makeBinaryCodec(SpatialContext ctx) {
295296
return makeClassInstance(binaryCodecClass, ctx, this);
296297
}
297298

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

303303
//can't simply lookup constructor by arg type because might be subclass type
304304
ctorLoop: for (Constructor<?> ctor : clazz.getConstructors()) {
305-
Class[] parameterTypes = ctor.getParameterTypes();
305+
Class<?>[] parameterTypes = ctor.getParameterTypes();
306306
if (parameterTypes.length == 0) {
307307
empty = ctor; // the empty constructor;
308308
}

src/main/java/org/locationtech/spatial4j/io/PolyshapeWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void write(Encoder enc, Shape shape) throws IOException {
119119
return;
120120
}
121121
if (shape instanceof ShapeCollection) {
122-
ShapeCollection v = (ShapeCollection) shape;
122+
@SuppressWarnings("unchecked") ShapeCollection<Shape> v = (ShapeCollection<Shape>) shape;
123123
Iterator<Shape> iter = v.iterator();
124124
while(iter.hasNext()) {
125125
write(enc, iter.next());

src/test/java/org/locationtech/spatial4j/io/BinaryCodecTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testCircle() throws Exception {
3737

3838
@Test
3939
public void testCollection() throws Exception {
40-
ShapeCollection s = ctx.makeCollection(
40+
ShapeCollection<Shape> s = ctx.makeCollection(
4141
Arrays.asList(
4242
randomShape(),
4343
randomShape(),

src/test/java/org/locationtech/spatial4j/shape/RandomizedShapeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public RandomizedShapeTest(SpatialContext ctx) {
4141
this.ctx = ctx;
4242
}
4343

44-
public static void checkShapesImplementEquals( Class[] classes ) {
45-
for( Class clazz : classes ) {
44+
public static void checkShapesImplementEquals( Class<?>[] classes ) {
45+
for( Class<?> clazz : classes ) {
4646
try {
4747
clazz.getDeclaredMethod( "equals", Object.class );
4848
} catch (Exception e) {

src/test/java/org/locationtech/spatial4j/shape/ShapeCollectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected ShapeCollection generateRandomShape(Point nearP) {
9696
//1st 2 are near nearP, the others are anywhere
9797
shapes.add(randomRectangle( i < 2 ? nearP : null));
9898
}
99-
ShapeCollection shapeCollection = new ShapeCollection<>(shapes, ctx);
99+
ShapeCollection<Rectangle> shapeCollection = new ShapeCollection<>(shapes, ctx);
100100

101101
//test shapeCollection.getBoundingBox();
102102
Rectangle msBbox = shapeCollection.getBoundingBox();

src/test/java/org/locationtech/spatial4j/util/Geom.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ public static Polygon first(MultiPolygon mp) {
303303
/**
304304
* Returns the geometries of a geometry collection as an array.
305305
*/
306+
@SuppressWarnings("unchecked")
306307
public static <T extends Geometry> T[] array(GeometryCollection gc, T[] array) {
307308
for (int i =0 ; i < gc.getNumGeometries(); i++) {
308309
array[i] = (T) gc.getGeometryN(i);
@@ -320,34 +321,33 @@ public static <T extends Geometry> T[] array(GeometryCollection gc, T[] array) {
320321
*
321322
* @see {@link GeometryFactory#buildGeometry(Collection)}
322323
*/
323-
public static <T extends Geometry> T narrow(GeometryCollection gc) {
324+
public static Geometry narrow(GeometryCollection gc) {
324325

325326
if (gc.getNumGeometries() == 0) {
326-
return (T) gc;
327+
return gc;
327328
}
328329

329330
List<Geometry> objects = new ArrayList<>(gc.getNumGeometries());
330331
for (Geometry g : iterate(gc)) {
331332
objects.add(g);
332333
}
333334

334-
return (T) gc.getFactory().buildGeometry(objects);
335+
return gc.getFactory().buildGeometry(objects);
335336
}
336337

337338
/**
338339
* Recursively flattens a geometry collection into it's constituent geometry objects.
339340
*/
340-
public static <T extends Geometry> List<T> flatten(GeometryCollection gc) {
341-
return flatten(Collections.singletonList((Geometry)gc));
341+
public static List<Geometry> flatten(GeometryCollection gc) {
342+
return flatten(Collections.singletonList(gc));
342343
}
343344

344345
/**
345346
* Recursively flattens a list of geometries into it's constituent geometry objects.
346347
*/
347-
public static <T extends Geometry> List<T> flatten(List<Geometry> gl) {
348-
List<T> flat = new ArrayList<>();
349-
LinkedList<Geometry> q = new LinkedList<>();
350-
q.addAll(gl);
348+
public static List<Geometry> flatten(List<Geometry> gl) {
349+
List<Geometry> flat = new ArrayList<>();
350+
LinkedList<Geometry> q = new LinkedList<>(gl);
351351

352352
while (!q.isEmpty()) {
353353
Geometry g = q.removeFirst();
@@ -357,7 +357,7 @@ public static <T extends Geometry> List<T> flatten(List<Geometry> gl) {
357357
}
358358
}
359359
else {
360-
flat.add((T) g);
360+
flat.add(g);
361361
}
362362
}
363363

src/test/java/org/locationtech/spatial4j/util/GeomBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ <T extends Geometry> T[] gpop(int n, Class<T> clazz) {
391391
+ "but found %d", n, gstack.size()));
392392
}
393393

394-
T[] l = (T[]) Array.newInstance(clazz, n);
394+
@SuppressWarnings("unchecked") T[] l = (T[]) Array.newInstance(clazz, n);
395395
for (int i = 0; i < n; i++) {
396-
Object g = gstack.pop();
396+
Geometry g = gstack.pop();
397397
if (!clazz.isInstance(g)) {
398398
throw new IllegalStateException(String.format(Locale.ROOT,"Expected %s on geometry stack, but "
399399
+ "found %s", clazz.getSimpleName(), g.getClass().getSimpleName()));

0 commit comments

Comments
 (0)