diff --git a/modules/core/src/main/java/org/locationtech/jts/index/ArrayListVisitor.java b/modules/core/src/main/java/org/locationtech/jts/index/ArrayListVisitor.java index 0a357afe82..2a18fefc54 100644 --- a/modules/core/src/main/java/org/locationtech/jts/index/ArrayListVisitor.java +++ b/modules/core/src/main/java/org/locationtech/jts/index/ArrayListVisitor.java @@ -19,11 +19,11 @@ * * @version 1.7 */ -public class ArrayListVisitor - implements ItemVisitor +public class ArrayListVisitor + implements ItemVisitor { - private final ArrayList items = new ArrayList<>(); + private ArrayList items = new ArrayList(); /** * Creates a new instance. @@ -36,7 +36,7 @@ public ArrayListVisitor() { * * @param item the item to visit */ - public void visitItem(T item) + public void visitItem(Object item) { items.add(item); } @@ -46,6 +46,6 @@ public void visitItem(T item) * * @return the array of items */ - public ArrayList getItems() { return items; } + public ArrayList getItems() { return items; } } diff --git a/modules/core/src/main/java/org/locationtech/jts/index/ItemVisitor.java b/modules/core/src/main/java/org/locationtech/jts/index/ItemVisitor.java index d8e138b9cf..589d9cf188 100644 --- a/modules/core/src/main/java/org/locationtech/jts/index/ItemVisitor.java +++ b/modules/core/src/main/java/org/locationtech/jts/index/ItemVisitor.java @@ -18,12 +18,12 @@ * @version 1.7 */ -public interface ItemVisitor +public interface ItemVisitor { /** * Visits an item in the index. * * @param item the index item to be visited */ - void visitItem(T item); + void visitItem(Object item); } diff --git a/modules/core/src/main/java/org/locationtech/jts/index/SpatialIndex.java b/modules/core/src/main/java/org/locationtech/jts/index/SpatialIndex.java index 8ad13c02cf..c44fcf9fca 100644 --- a/modules/core/src/main/java/org/locationtech/jts/index/SpatialIndex.java +++ b/modules/core/src/main/java/org/locationtech/jts/index/SpatialIndex.java @@ -26,12 +26,12 @@ * * @version 1.7 */ -public interface SpatialIndex +public interface SpatialIndex { /** * Adds a spatial item with an extent specified by the given {@link Envelope} to the index */ - void insert(Envelope itemEnv, T item); + void insert(Envelope itemEnv, Object item); /** * Queries the index for all items whose extents intersect the given search {@link Envelope} @@ -41,7 +41,7 @@ public interface SpatialIndex * @param searchEnv the envelope to query for * @return a list of the items found by the query */ - List query(Envelope searchEnv); + List query(Envelope searchEnv); /** * Queries the index for all items whose extents intersect the given search {@link Envelope}, @@ -52,7 +52,7 @@ public interface SpatialIndex * @param searchEnv the envelope to query for * @param visitor a visitor object to apply to the items found */ - void query(Envelope searchEnv, ItemVisitor visitor); + void query(Envelope searchEnv, ItemVisitor visitor); /** * Removes a single item from the tree. @@ -61,6 +61,6 @@ public interface SpatialIndex * @param item the item to remove * @return true if the item was found */ - boolean remove(Envelope itemEnv, T item); + boolean remove(Envelope itemEnv, Object item); } diff --git a/modules/core/src/main/java/org/locationtech/jts/index/hprtree/HPRtree.java b/modules/core/src/main/java/org/locationtech/jts/index/hprtree/HPRtree.java index 7e7ab315cc..f6f166712a 100644 --- a/modules/core/src/main/java/org/locationtech/jts/index/hprtree/HPRtree.java +++ b/modules/core/src/main/java/org/locationtech/jts/index/hprtree/HPRtree.java @@ -57,8 +57,8 @@ * @author Martin Davis * */ -public class HPRtree - implements SpatialIndex +public class HPRtree + implements SpatialIndex { private static final int ENV_SIZE = 4; @@ -66,7 +66,7 @@ public class HPRtree private static final int DEFAULT_NODE_CAPACITY = 16; - private List> itemsToLoad = new ArrayList<>(); + private List itemsToLoad = new ArrayList<>(); private final int nodeCapacity; @@ -110,29 +110,29 @@ public int size() { } @Override - public void insert(Envelope itemEnv, T item) { + public void insert(Envelope itemEnv, Object item) { if (isBuilt) { throw new IllegalStateException("Cannot insert items after tree is built."); } numItems++; - itemsToLoad.add( new Item<>(itemEnv, item) ); + itemsToLoad.add( new Item(itemEnv, item) ); totalExtent.expandToInclude(itemEnv); } @Override - public List query(Envelope searchEnv) { + public List query(Envelope searchEnv) { build(); if (! totalExtent.intersects(searchEnv)) - return new ArrayList<>(); + return new ArrayList(); - ArrayListVisitor visitor = new ArrayListVisitor<>(); + ArrayListVisitor visitor = new ArrayListVisitor(); query(searchEnv, visitor); return visitor.getItems(); } @Override - public void query(Envelope searchEnv, ItemVisitor visitor) { + public void query(Envelope searchEnv, ItemVisitor visitor) { build(); if (! totalExtent.intersects(searchEnv)) return; @@ -144,7 +144,7 @@ public void query(Envelope searchEnv, ItemVisitor visitor) { } } - private void queryTopLayer(Envelope searchEnv, ItemVisitor visitor) { + private void queryTopLayer(Envelope searchEnv, ItemVisitor visitor) { int layerIndex = layerStartIndex.length - 2; int layerSize = layerSize(layerIndex); // query each node in layer @@ -153,7 +153,7 @@ private void queryTopLayer(Envelope searchEnv, ItemVisitor visitor) { } } - private void queryNode(int layerIndex, int nodeOffset, Envelope searchEnv, ItemVisitor visitor) { + private void queryNode(int layerIndex, int nodeOffset, Envelope searchEnv, ItemVisitor visitor) { int layerStart = layerStartIndex[layerIndex]; int nodeIndex = layerStart + nodeOffset; if (! intersects(nodeBounds, nodeIndex, searchEnv)) return; @@ -175,7 +175,7 @@ private static boolean intersects(double[] bounds, int nodeIndex, Envelope env) return ! isBeyond; } - private void queryNodeChildren(int layerIndex, int blockOffset, Envelope searchEnv, ItemVisitor visitor) { + private void queryNodeChildren(int layerIndex, int blockOffset, Envelope searchEnv, ItemVisitor visitor) { int layerStart = layerStartIndex[layerIndex]; int layerEnd = layerStartIndex[layerIndex + 1]; for (int i = 0; i < nodeCapacity; i++) { @@ -187,15 +187,13 @@ private void queryNodeChildren(int layerIndex, int blockOffset, Envelope searchE } } - private void queryItems(int blockStart, Envelope searchEnv, ItemVisitor visitor) { + private void queryItems(int blockStart, Envelope searchEnv, ItemVisitor visitor) { for (int i = 0; i < nodeCapacity; i++) { int itemIndex = blockStart + i; // don't query past end of items if (itemIndex >= numItems) break; if (intersects(itemBounds, itemIndex * ENV_SIZE, searchEnv)) { - @SuppressWarnings("unchecked") - T item = (T) itemValues[itemIndex]; - visitor.visitItem(item); + visitor.visitItem(itemValues[itemIndex]); } } } @@ -207,7 +205,7 @@ private int layerSize(int layerIndex) { } @Override - public boolean remove(Envelope itemEnv, T item) { + public boolean remove(Envelope itemEnv, Object item) { // TODO Auto-generated method stub return false; } @@ -252,7 +250,7 @@ private void prepareItems() { int valueIndex = 0; itemBounds = new double[itemsToLoad.size() * 4]; itemValues = new Object[itemsToLoad.size()]; - for (Item item : itemsToLoad) { + for (Item item : itemsToLoad) { Envelope envelope = item.getEnvelope(); itemBounds[boundsIndex++] = envelope.getMinX(); itemBounds[boundsIndex++] = envelope.getMinY(); @@ -365,7 +363,7 @@ private void sortItems() { HilbertEncoder encoder = new HilbertEncoder(HILBERT_LEVEL, totalExtent); int[] hilbertValues = new int[itemsToLoad.size()]; int pos = 0; - for (Item item : itemsToLoad) { + for (Item item : itemsToLoad) { hilbertValues[pos++] = encoder.encode(item.getEnvelope()); } quickSortItemsIntoNodes(hilbertValues, 0, itemsToLoad.size() - 1); @@ -395,7 +393,7 @@ private int hoarePartition(int[] values, int lo, int hi) { } private void swapItems(int[] values, int i, int j) { - Item tmpItemp = itemsToLoad.get(i); + Item tmpItemp = itemsToLoad.get(i); itemsToLoad.set(i, itemsToLoad.get(j)); itemsToLoad.set(j, tmpItemp); diff --git a/modules/core/src/main/java/org/locationtech/jts/index/hprtree/Item.java b/modules/core/src/main/java/org/locationtech/jts/index/hprtree/Item.java index 5710b9a212..7de93a1001 100644 --- a/modules/core/src/main/java/org/locationtech/jts/index/hprtree/Item.java +++ b/modules/core/src/main/java/org/locationtech/jts/index/hprtree/Item.java @@ -13,12 +13,12 @@ import org.locationtech.jts.geom.Envelope; -public class Item { +public class Item { - private final Envelope env; - private final T item; + private Envelope env; + private Object item; - public Item(Envelope env, T item) { + public Item(Envelope env, Object item) { this.env = env; this.item = item; } @@ -27,7 +27,7 @@ public Envelope getEnvelope() { return env; } - public T getItem() { + public Object getItem() { return item; } diff --git a/modules/core/src/main/java/org/locationtech/jts/noding/MCIndexNoder.java b/modules/core/src/main/java/org/locationtech/jts/noding/MCIndexNoder.java index e21feecc84..399efda0d9 100644 --- a/modules/core/src/main/java/org/locationtech/jts/noding/MCIndexNoder.java +++ b/modules/core/src/main/java/org/locationtech/jts/noding/MCIndexNoder.java @@ -39,8 +39,8 @@ public class MCIndexNoder extends SinglePassNoder { - private final List monoChains = new ArrayList<>(); - private final SpatialIndex index = new HPRtree<>(); + private List monoChains = new ArrayList(); + private SpatialIndex index= new HPRtree(); private int idCounter = 0; private Collection nodedSegStrings; // statistics @@ -69,9 +69,9 @@ public MCIndexNoder(SegmentIntersector si, double overlapTolerance) this.overlapTolerance = overlapTolerance; } - public List getMonotoneChains() { return monoChains; } + public List getMonotoneChains() { return monoChains; } - public SpatialIndex getIndex() { return index; } + public SpatialIndex getIndex() { return index; } public Collection getNodedSubstrings() { @@ -91,9 +91,13 @@ public void computeNodes(Collection inputSegStrings) private void intersectChains() { MonotoneChainOverlapAction overlapAction = new SegmentOverlapAction(segInt); - for (MonotoneChain queryChain : monoChains) { + + for (Iterator i = monoChains.iterator(); i.hasNext(); ) { + MonotoneChain queryChain = (MonotoneChain) i.next(); Envelope queryEnv = queryChain.getEnvelope(overlapTolerance); - for (MonotoneChain testChain : index.query(queryEnv)) { + List overlapChains = index.query(queryEnv); + for (Iterator j = overlapChains.iterator(); j.hasNext(); ) { + MonotoneChain testChain = (MonotoneChain) j.next(); /** * following test makes sure we only compare each pair of chains once * and that we don't compare a chain to itself @@ -103,7 +107,8 @@ private void intersectChains() nOverlaps++; } // short-circuit if possible - if (segInt.isDone()) return; + if (segInt.isDone()) + return; } } }