PolygonHandler implements ShapeHandler { ArrayList assignHolesToShells(final ArrayList shells, final ArrayList holes) { ArrayList holesForShells = new ArrayList(shells.size()); for (int i = 0; i < shells.size(); i++) { holesForShells.add(new ArrayList()); } for (int i = 0; i < holes.size(); i++) { LinearRing testRing = (LinearRing) holes.get(i); LinearRing minShell = null; Envelope minEnv = null; Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); LinearRing tryRing; for (int j = 0; j < shells.size(); j++) { tryRing = (LinearRing) shells.get(j); Envelope tryEnv = tryRing.getEnvelopeInternal(); if (minShell != null) { minEnv = minShell.getEnvelopeInternal(); } boolean isContained = false; Coordinate[] coordList = tryRing.getCoordinates(); if (tryEnv.contains(testEnv) && (CGAlgorithms.isPointInRing(testPt, coordList) || (pointInList( testPt, coordList)))) { isContained = true; } if (isContained) { if ((minShell == null) || minEnv.contains(tryEnv)) { minShell = tryRing; } } } if (minShell == null) { shells.add(testRing); holesForShells.add(new ArrayList()); } else { ((ArrayList) holesForShells.get(shells.indexOf(minShell))) .add(testRing); } } return holesForShells; } PolygonHandler(GeometryFactory gf);  PolygonHandler(ShapeType type, GeometryFactory gf); ShapeType getShapeType(); int getLength(Object geometry); Object read(ByteBuffer buffer, ShapeType type, boolean flatFeature); void write(ByteBuffer buffer, Object geometry);  }
@Test public void testHoleAssignment() { java.awt.Dimension ps = new java.awt.Dimension(500, 500); PrecisionModel precision = new PrecisionModel(); ArrayList shells = new ArrayList(); ArrayList holes = new ArrayList(); int x = 10; int y = 10; shells.add(copyTo(x, y, ps.width - 2 * x, ps.height - 2 * y, rectangle( precision, 0))); int w = 11; int h = 11; int s = 10; int nx = (ps.width - 2 * x) / (w + s); int ny = (ps.height - 2 * y) / (h + s); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { holes.add(copyTo(x + s + i * (w + s), y + s + j * (h + s), w, h, rectangle(precision, 0))); } } PolygonHandler ph = new PolygonHandler(new GeometryFactory()); ArrayList assigned = ph.assignHolesToShells(shells, holes); assertEquals(((ArrayList) assigned.get(0)).size(), holes.size()); }