com.vividsolutions.jts.util.Assert Java Examples
The following examples show how to use
com.vividsolutions.jts.util.Assert.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicPessimisticLockingIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenRecordWithPessimisticWrite_whenUpdatingRecord_PessimisticLockExceptionThrown() { try { EntityManager entityManager = getEntityManagerWithOpenTransaction(); PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_WRITE); EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); PessimisticLockingStudent resultStudent2 = entityManager2.find(PessimisticLockingStudent.class, 1L); resultStudent2.setName("Change"); entityManager2.persist(resultStudent2); entityManager2.getTransaction() .commit(); entityManager.close(); entityManager2.close(); } catch (Exception e) { Assert.isTrue(e instanceof PessimisticLockException); } }
Example #2
Source File: GeometryEditorEx.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private Geometry editInternal(Geometry geometry) { // if client did not supply a GeometryFactory, use the one from the input Geometry if (targetFactory == null) targetFactory = geometry.getFactory(); if (geometry instanceof GeometryCollection) { return editGeometryCollection((GeometryCollection) geometry); } if (geometry instanceof Polygon) { return editPolygon((Polygon) geometry); } if (geometry instanceof Point) { return editPoint((Point) geometry); } if (geometry instanceof LinearRing) { return editLinearRing((LinearRing) geometry); } if (geometry instanceof LineString) { return editLineString((LineString) geometry); } Assert.shouldNeverReachHere("Unsupported Geometry class: " + geometry.getClass().getName()); return null; }
Example #3
Source File: TestRunnerTestCaseAdapter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public String getWellKnownText(int index) { if (index == 0) { if (testCase.getGeometryA() == null) { return null; } return wktWriter.write(testCase.getGeometryA()); } else if (index == 1) { if (testCase.getGeometryB() == null) { return null; } return wktWriter.write(testCase.getGeometryB()); } Assert.shouldNeverReachHere(); return null; }
Example #4
Source File: TestRunnerTestCaseAdapter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private Test getABTest(String opName) { Assert.isTrue(GeometryMethodOperation.isBooleanFunction(opName) || GeometryMethodOperation.isGeometryFunction(opName)); for (Iterator i = testCase.getTests().iterator(); i.hasNext(); ) { Test test = (Test) i.next(); if (test.getOperation().equalsIgnoreCase(opName) && ((!opName.equalsIgnoreCase("relate")) || test.getExpectedResult().equals(new BooleanResult(true))) && (test.getGeometryIndex().equalsIgnoreCase("A")) && ((test.getArgumentCount() == 0) || ( test.getArgument(0) != null && (test.getArgument(0).equalsIgnoreCase("B"))))) { return test; } } return null; }
Example #5
Source File: XMLTestWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public String getTestXML(Geometry geometry, String opName, String[] arguments) { String xml = " <test>\n"; xml += " <op name=\"" + opName + "\" arg1=\"A\""; int j = 2; for (int i = 0; i < arguments.length; i++) { String argument = arguments[i]; Assert.isTrue(argument != null); xml += " arg" + j + "=\"" + argument + "\""; j++; } xml += ">\n"; xml += StringUtil.indent(wktWriter.writeFormatted(geometry) + "\n", 6); xml += " </op>\n"; xml += " </test>\n"; return xml; }
Example #6
Source File: StaticMethodGeometryFunction.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public static StaticMethodGeometryFunction createFunction(Method method) { Assert.isTrue(Geometry.class.isAssignableFrom((method.getParameterTypes())[0])); Class clz = method.getDeclaringClass(); String category = extractCategory(ClassUtil.getClassname(clz)); String funcName = method.getName(); String description = extractDescription(method); String[] paramNames = extractParamNames(method); Class[] paramTypes = extractParamTypes(method); Class returnType = method.getReturnType(); return new StaticMethodGeometryFunction(category, funcName, description, paramNames, paramTypes, returnType, method); }
Example #7
Source File: Test.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public String toXml() { String xml = ""; xml += "<test>" + StringUtil.newLine; if (description != null && description.length() > 0) { xml += " <desc>" + StringUtil.escapeHTML(description) + "</desc>" + StringUtil.newLine; } xml += " <op name=\"" + operation + "\""; xml += " arg1=\"" + geometryIndex + "\""; int j = 2; for (Iterator i = arguments.iterator(); i.hasNext(); ) { String argument = (String) i.next(); Assert.isTrue(argument != null); xml += " arg" + j + "=\"" + argument + "\""; j++; } xml += ">" + StringUtil.newLine; xml += StringUtil.indent(expectedResult.toFormattedString(), 4) + StringUtil.newLine; xml += " </op>" + StringUtil.newLine; xml += "</test>" + StringUtil.newLine; return xml; }
Example #8
Source File: Vector2D.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Rotates a vector by a given number of quarter-circles (i.e. multiples of 90 * degrees or Pi/2 radians). A positive number rotates counter-clockwise, a * negative number rotates clockwise. Under this operation the magnitude of * the vector and the absolute values of the ordinates do not change, only * their sign and ordinate index. * * @param numQuarters * the number of quarter-circles to rotate by * @return the rotated vector. */ public Vector2D rotateByQuarterCircle(int numQuarters) { int nQuad = numQuarters % 4; if (numQuarters < 0 && nQuad != 0) { nQuad = nQuad + 4; } switch (nQuad) { case 0: return create(x, y); case 1: return create(-y, x); case 2: return create(-x, -y); case 3: return create(y, -x); } Assert.shouldNeverReachHere(); return null; }
Example #9
Source File: PolygonizeGraph.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Finds all nodes in a maximal edgering which are self-intersection nodes * @param startDE * @param label * @return the list of intersection nodes found, * or <code>null</code> if no intersection nodes were found */ private static List findIntersectionNodes(PolygonizeDirectedEdge startDE, long label) { PolygonizeDirectedEdge de = startDE; List intNodes = null; do { Node node = de.getFromNode(); if (getDegree(node, label) > 1) { if (intNodes == null) intNodes = new ArrayList(); intNodes.add(node); } de = de.getNext(); Assert.isTrue(de != null, "found null DE in ring"); Assert.isTrue(de == startDE || ! de.isInRing(), "found DE already in ring"); } while (de != startDE); return intNodes; }
Example #10
Source File: LineSequencer.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void computeSequence() { if (isRun) { return; } isRun = true; List sequences = findSequences(); if (sequences == null) return; sequencedGeometry = buildSequencedGeometry(sequences); isSequenceable = true; int finalLineCount = sequencedGeometry.getNumGeometries(); Assert.isTrue(lineCount == finalLineCount, "Lines were missing from result"); Assert.isTrue(sequencedGeometry instanceof LineString || sequencedGeometry instanceof MultiLineString, "Result is not lineal"); }
Example #11
Source File: LineSequencer.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void addReverseSubpath(DirectedEdge de, ListIterator lit, boolean expectedClosed) { // trace an unvisited path *backwards* from this de Node endNode = de.getToNode(); Node fromNode = null; while (true) { lit.add(de.getSym()); de.getEdge().setVisited(true); fromNode = de.getFromNode(); DirectedEdge unvisitedOutDE = findUnvisitedBestOrientedDE(fromNode); // this must terminate, since we are continually marking edges as visited if (unvisitedOutDE == null) break; de = unvisitedOutDE.getSym(); } if (expectedClosed) { // the path should end at the toNode of this de, otherwise we have an error Assert.isTrue(fromNode == endNode, "path not contiguous"); } }
Example #12
Source File: ConvexHull.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** *@param vertices the vertices of a linear ring, which may or may not be * flattened (i.e. vertices collinear) *@return the coordinates with unnecessary (collinear) vertices * removed */ private Coordinate[] cleanRing(Coordinate[] original) { Assert.equals(original[0], original[original.length - 1]); ArrayList<Coordinate> cleanedRing = new ArrayList<Coordinate>(); Coordinate previousDistinctCoordinate = null; for (int i = 0; i <= original.length - 2; i++) { Coordinate currentCoordinate = original[i]; Coordinate nextCoordinate = original[i+1]; if (currentCoordinate.equals(nextCoordinate)) { continue; } if (previousDistinctCoordinate != null && isBetween(previousDistinctCoordinate, currentCoordinate, nextCoordinate)) { continue; } cleanedRing.add(currentCoordinate); previousDistinctCoordinate = currentCoordinate; } cleanedRing.add(original[original.length - 1]); Coordinate[] cleanedRingCoordinates = new Coordinate[cleanedRing.size()]; return cleanedRing.toArray(cleanedRingCoordinates); }
Example #13
Source File: SegmentPointComparator.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Compares two {@link Coordinate}s for their relative position along a segment * lying in the specified {@link Octant}. * * @return -1 node0 occurs first; * 0 the two nodes are equal; * 1 node1 occurs first */ public static int compare(int octant, Coordinate p0, Coordinate p1) { // nodes can only be equal if their coordinates are equal if (p0.equals2D(p1)) return 0; int xSign = relativeSign(p0.x, p1.x); int ySign = relativeSign(p0.y, p1.y); switch (octant) { case 0: return compareValue(xSign, ySign); case 1: return compareValue(ySign, xSign); case 2: return compareValue(ySign, -xSign); case 3: return compareValue(-xSign, ySign); case 4: return compareValue(-xSign, -ySign); case 5: return compareValue(-ySign, -xSign); case 6: return compareValue(-ySign, xSign); case 7: return compareValue(xSign, -ySign); } Assert.shouldNeverReachHere("invalid octant value"); return 0; }
Example #14
Source File: Root.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * insert an item which is known to be contained in the tree rooted at * the given QuadNode root. Lower levels of the tree will be created * if necessary to hold the item. */ private void insertContained(Node tree, Envelope itemEnv, Object item) { Assert.isTrue(tree.getEnvelope().contains(itemEnv)); /** * Do NOT create a new quad for zero-area envelopes - this would lead * to infinite recursion. Instead, use a heuristic of simply returning * the smallest existing quad containing the query */ boolean isZeroX = IntervalSize.isZeroWidth(itemEnv.getMinX(), itemEnv.getMaxX()); boolean isZeroY = IntervalSize.isZeroWidth(itemEnv.getMinY(), itemEnv.getMaxY()); NodeBase node; if (isZeroX || isZeroY) node = tree.find(itemEnv); else node = tree.getNode(itemEnv); node.add(item); }
Example #15
Source File: JdbcEnrollmentAnalyticsManager.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Returns an encoded column name wrapped in lower directive if not numeric * or boolean. * * @param item the {@link QueryItem}. */ @Override protected String getColumn( QueryItem item ) { String colName = item.getItemName(); if ( item.hasProgramStage() ) { colName = quote( colName ); Assert.isTrue( item.hasProgram(), "Can not query item with program stage but no program:" + item.getItemName() ); String eventTableName = "analytics_event_" + item.getProgram().getUid(); return "(select " + colName + " from " + eventTableName + " where " + eventTableName + ".pi = " + ANALYTICS_TBL_ALIAS + ".pi " + "and " + colName + " is not null " + "and ps = '" + item.getProgramStage().getUid() + "' " + "order by executiondate " + "desc limit 1 )"; } else { return quoteAlias( colName ); } }
Example #16
Source File: BasicPessimisticLockingIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenRecordWithPessimisticRead_whenUpdatingRecord_PessimisticLockExceptionThrown() { try { EntityManager entityManager = getEntityManagerWithOpenTransaction(); PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_READ); EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); PessimisticLockingStudent resultStudent2 = entityManager2.find(PessimisticLockingStudent.class, 1L); resultStudent2.setName("Change"); entityManager2.persist(resultStudent2); entityManager2.getTransaction() .commit(); entityManager.close(); entityManager2.close(); } catch (Exception e) { Assert.isTrue(e instanceof PessimisticLockException); } }
Example #17
Source File: BasicPessimisticLockingIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenRecordAndRefreshWithPessimisticRead_whenFindingWithPessimisticWrite_PessimisticLockExceptionThrown() { try { EntityManager entityManager = getEntityManagerWithOpenTransaction(); PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_FORCE_INCREMENT); EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_WRITE); entityManager.close(); entityManager2.close(); } catch (Exception e) { Assert.isTrue(e instanceof PessimisticLockException); } }
Example #18
Source File: BasicPessimisticLockingIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenRecordWithPessimisticReadLock_whenFindingNewOne_PessimisticLockExceptionThrown() { try { EntityManager entityManager = getEntityManagerWithOpenTransaction(); PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); entityManager.lock(resultStudent, LockModeType.PESSIMISTIC_READ); EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_FORCE_INCREMENT); entityManager.close(); entityManager2.close(); } catch (Exception e) { Assert.isTrue(e instanceof PessimisticLockException); } }
Example #19
Source File: BasicPessimisticLockingIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenRecordWithPessimisticReadQuery_whenQueryingNewOne_PessimisticLockExceptionThrown() throws IOException { try { EntityManager entityManager = getEntityManagerWithOpenTransaction(); Query query = entityManager.createQuery("from Student where studentId = :studentId"); query.setParameter("studentId", 1L); query.setLockMode(LockModeType.PESSIMISTIC_WRITE); query.getResultList(); EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); Query query2 = entityManager2.createQuery("from Student where studentId = :studentId"); query2.setParameter("studentId", 1L); query2.setLockMode(LockModeType.PESSIMISTIC_READ); query2.getResultList(); entityManager.close(); entityManager2.close(); } catch (Exception e) { Assert.isTrue(e instanceof PessimisticLockException); } }
Example #20
Source File: SameStructureTester.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public static boolean isSameStructure(Geometry g1, Geometry g2) { if (g1.getClass() != g2.getClass()) return false; if (g1 instanceof GeometryCollection) return isSameStructureCollection((GeometryCollection) g1, (GeometryCollection) g2); else if (g1 instanceof Polygon) return isSameStructurePolygon((Polygon) g1, (Polygon) g2); else if (g1 instanceof LineString) return isSameStructureLineString((LineString) g1, (LineString) g2); else if (g1 instanceof Point) return isSameStructurePoint((Point) g1, (Point) g2); Assert.shouldNeverReachHere( "Unsupported Geometry class: " + g1.getClass().getName()); return false; }
Example #21
Source File: WKBWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Writes a {@link Geometry} to an {@link OutStream}. * * @param geom the geometry to write * @param os the out stream to write to * @throws IOException if an I/O error occurs */ public void write(Geometry geom, OutStream os) throws IOException { if (geom instanceof Point) writePoint((Point) geom, os); // LinearRings will be written as LineStrings else if (geom instanceof LineString) writeLineString((LineString) geom, os); else if (geom instanceof Polygon) writePolygon((Polygon) geom, os); else if (geom instanceof MultiPoint) writeGeometryCollection(WKBConstants.wkbMultiPoint, (MultiPoint) geom, os); else if (geom instanceof MultiLineString) writeGeometryCollection(WKBConstants.wkbMultiLineString, (MultiLineString) geom, os); else if (geom instanceof MultiPolygon) writeGeometryCollection(WKBConstants.wkbMultiPolygon, (MultiPolygon) geom, os); else if (geom instanceof GeometryCollection) writeGeometryCollection(WKBConstants.wkbGeometryCollection, (GeometryCollection) geom, os); else { Assert.shouldNeverReachHere("Unknown Geometry type"); } }
Example #22
Source File: LengthIndexOfPoint.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Finds the nearest index along the linear {@link Geometry} * to a given {@link Coordinate} * after the specified minimum index. * If possible the location returned will be strictly greater than the * <code>minLocation</code>. * If this is not possible, the * value returned will equal <code>minLocation</code>. * (An example where this is not possible is when * minLocation = [end of line] ). * * @param inputPt the coordinate to locate * @param minIndex the minimum location for the point location * @return the location of the nearest point */ public double indexOfAfter(Coordinate inputPt, double minIndex) { if (minIndex < 0.0) return indexOf(inputPt); // sanity check for minIndex at or past end of line double endIndex = linearGeom.getLength(); if (endIndex < minIndex) return endIndex; double closestAfter = indexOfFromStart(inputPt, minIndex); /** * Return the minDistanceLocation found. */ Assert.isTrue(closestAfter >= minIndex, "computed index is before specified minimum index"); return closestAfter; }
Example #23
Source File: LocationIndexOfPoint.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Find the nearest {@link LinearLocation} along the linear {@link Geometry} * to a given {@link Coordinate} * after the specified minimum {@link LinearLocation}. * If possible the location returned will be strictly greater than the * <code>minLocation</code>. * If this is not possible, the * value returned will equal <code>minLocation</code>. * (An example where this is not possible is when * minLocation = [end of line] ). * * @param inputPt the coordinate to locate * @param minIndex the minimum location for the point location * @return the location of the nearest point */ public LinearLocation indexOfAfter(Coordinate inputPt, LinearLocation minIndex) { if (minIndex == null) return indexOf(inputPt); // sanity check for minLocation at or past end of line LinearLocation endLoc = LinearLocation.getEndLocation(linearGeom); if (endLoc.compareTo(minIndex) <= 0) return endLoc; LinearLocation closestAfter = indexOfFromStart(inputPt, minIndex); /** * Return the minDistanceLocation found. * This will not be null, since it was initialized to minLocation */ Assert.isTrue(closestAfter.compareTo(minIndex) >= 0, "computed location is before specified minimum location"); return closestAfter; }
Example #24
Source File: GeometryEditor.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private Geometry editInternal(Geometry geometry, GeometryEditorOperation operation) { // if client did not supply a GeometryFactory, use the one from the input Geometry if (factory == null) factory = geometry.getFactory(); if (geometry instanceof GeometryCollection) { return editGeometryCollection((GeometryCollection) geometry, operation); } if (geometry instanceof Polygon) { return editPolygon((Polygon) geometry, operation); } if (geometry instanceof Point) { return operation.edit(geometry, factory); } if (geometry instanceof LineString) { return operation.edit(geometry, factory); } Assert.shouldNeverReachHere("Unsupported Geometry class: " + geometry.getClass().getName()); return null; }
Example #25
Source File: Node.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
void insertNode(Node node) { Assert.isTrue(env == null || env.contains(node.env)); //System.out.println(env); //System.out.println(quad.env); int index = getSubnodeIndex(node.env, centrex, centrey); //System.out.println(index); if (node.level == level - 1) { subnode[index] = node; //System.out.println("inserted"); } else { // the quad is not a direct child, so make a new child quad to contain it // and recursively insert the quad Node childNode = createSubnode(index); childNode.insertNode(node); subnode[index] = childNode; } }
Example #26
Source File: Root.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * insert an item which is known to be contained in the tree rooted at * the given Node. Lower levels of the tree will be created * if necessary to hold the item. */ private void insertContained(Node tree, Interval itemInterval, Object item) { Assert.isTrue(tree.getInterval().contains(itemInterval)); /** * Do NOT create a new node for zero-area intervals - this would lead * to infinite recursion. Instead, use a heuristic of simply returning * the smallest existing node containing the query */ boolean isZeroArea = IntervalSize.isZeroWidth(itemInterval.getMin(), itemInterval.getMax()); NodeBase node; if (isZeroArea) node = tree.find(itemInterval); else node = tree.getNode(itemInterval); node.add(item); }
Example #27
Source File: Point.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void init(CoordinateSequence coordinates) { if (coordinates == null) { coordinates = getFactory().getCoordinateSequenceFactory().create(new Coordinate[]{}); } Assert.isTrue(coordinates.size() <= 1); this.coordinates = coordinates; }
Example #28
Source File: TestRunnerTestCaseAdapter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public Geometry getGeometry(int index) { if (index == 0) { return testCase.getGeometryA(); } else if (index == 1) { return testCase.getGeometryB(); } Assert.shouldNeverReachHere(); return null; }
Example #29
Source File: ExtractLineByLocation.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private Geometry reverse(Geometry linear) { if (linear instanceof LineString) return ((LineString) linear).reverse(); if (linear instanceof MultiLineString) return ((MultiLineString) linear).reverse(); Assert.shouldNeverReachHere("non-linear geometry encountered"); return null; }
Example #30
Source File: TestRunnerTestCaseAdapter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public void setGeometry(int index, Geometry g) { if (index == 0) { testCase.setGeometryA(g); } else if (index == 1) { testCase.setGeometryB(g); } else { Assert.shouldNeverReachHere(); } }