Java Code Examples for com.vividsolutions.jts.util.Assert#isTrue()

The following examples show how to use com.vividsolutions.jts.util.Assert#isTrue() . 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: Node.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 2
Source File: TestRunnerTestCaseAdapter.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 3
Source File: JdbcEnrollmentAnalyticsManager.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 4
Source File: PolygonizeGraph.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 5
Source File: Root.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 6
Source File: BasicPessimisticLockingIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@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 7
Source File: LineSequencer.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 8
Source File: BasicPessimisticLockingIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@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 9
Source File: PolygonizeGraph.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Computes the next edge pointers going CCW around the given node, for the
 * given edgering label.
 * This algorithm has the effect of converting maximal edgerings into minimal edgerings
 */
private static void computeNextCCWEdges(Node node, long label)
{
  DirectedEdgeStar deStar = node.getOutEdges();
  //PolyDirectedEdge lastInDE = null;
  PolygonizeDirectedEdge firstOutDE = null;
  PolygonizeDirectedEdge prevInDE = null;

  // the edges are stored in CCW order around the star
  List edges = deStar.getEdges();
  //for (Iterator i = deStar.getEdges().iterator(); i.hasNext(); ) {
  for (int i = edges.size() - 1; i >= 0; i--) {
    PolygonizeDirectedEdge de = (PolygonizeDirectedEdge) edges.get(i);
    PolygonizeDirectedEdge sym = (PolygonizeDirectedEdge) de.getSym();

    PolygonizeDirectedEdge outDE = null;
    if (  de.getLabel() == label) outDE = de;
    PolygonizeDirectedEdge inDE = null;
    if (  sym.getLabel() == label) inDE =  sym;

    if (outDE == null && inDE == null) continue;  // this edge is not in edgering

    if (inDE != null) {
      prevInDE = inDE;
    }

    if (outDE != null) {
      if (prevInDE != null) {
        prevInDE.setNext(outDE);
        prevInDE = null;
      }
      if (firstOutDE == null)
        firstOutDE = outDE;
    }
  }
  if (prevInDE != null) {
    Assert.isTrue(firstOutDE != null);
    prevInDE.setNext(firstOutDE);
  }
}
 
Example 10
Source File: EdgeRing.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Traverses a ring of DirectedEdges, accumulating them into a list.
 * This assumes that all dangling directed edges have been removed
 * from the graph, so that there is always a next dirEdge.
 *
 * @param startDE the DirectedEdge to start traversing at
 * @return a List of DirectedEdges that form a ring
 */
public static List findDirEdgesInRing(PolygonizeDirectedEdge startDE)
{
  PolygonizeDirectedEdge de = startDE;
  List edges = new ArrayList();
  do {
    edges.add(de);
    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 edges;
}
 
Example 11
Source File: LineMergeDirectedEdge.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the directed edge that starts at this directed edge's end point, or null
 * if there are zero or multiple directed edges starting there.  
 * @return the directed edge
 */
public LineMergeDirectedEdge getNext() {
  if (getToNode().getDegree() != 2) {
    return null;
  }
  if (getToNode().getOutEdges().getEdges().get(0) == getSym()) {
    return (LineMergeDirectedEdge) getToNode().getOutEdges().getEdges().get(1);
  }
  Assert.isTrue(getToNode().getOutEdges().getEdges().get(1) == getSym());

  return (LineMergeDirectedEdge) getToNode().getOutEdges().getEdges().get(0);
}
 
Example 12
Source File: Parameters.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the singleton. Be sure to call #setParameters first.
 */
public static Parameters getInstance() {
    Assert.isTrue(arguments != null);
    if (instance == null)
        instance = new Parameters();
    return instance;
}
 
Example 13
Source File: Point.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void init(CoordinateSequence coordinates)
{
  if (coordinates == null) {
    coordinates = getFactory().getCoordinateSequenceFactory().create(new Coordinate[]{});
  }
  Assert.isTrue(coordinates.size() <= 1);
  this.coordinates = coordinates;
}
 
Example 14
Source File: IndexTester.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
void runSelfQuery(List items)
{
  double querySize = 0.0;
  for (int i = 0; i < items.size(); i++) {
    Envelope env = (Envelope) items.get(i);
    List list = index.query(env);
    Assert.isTrue(!list.isEmpty());
    querySize += list.size();
  }
  System.out.println("Avg query size = " + querySize / items.size());
}
 
Example 15
Source File: HtmlWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Object actualResult(TestCaseEdit testCaseEdit, String opName, String first,
    String second) throws Exception {
  try {
    Assert.isTrue((first.equalsIgnoreCase("A")) || (first.equalsIgnoreCase("B")));
    Class geometryClass = Class.forName("com.vividsolutions.jts.geom.Geometry");
    Geometry source = testCaseEdit.getGeometry(first.equalsIgnoreCase("A") ? 0 : 1);
    Object[] target;
    Class[] targetClasses;
    if (second == null) {
      target = new Object[]{};
      targetClasses = new Class[]{};
    }
    else {
      target = new Object[]{
          testCaseEdit.getGeometry(second.equalsIgnoreCase("A") ? 0 : 1)
          };
      targetClasses = new Class[]{
          geometryClass
          };
    }
    Method op = geometryClass.getMethod(opName, targetClasses);
    return op.invoke(source, target);
  }
  catch (InvocationTargetException e) {
    throw (Exception) e.getTargetException();
  }
}
 
Example 16
Source File: HtmlWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void write(File outputDirectory, TestCaseList testCaseList, PrecisionModel precisionModel) throws IOException {
  if (busyDialog != null) {
    busyDialog.setDescription("Saving .html and .gif files");
  }
  Assert.isTrue(outputDirectory.isDirectory());
  this.outputDirectory = outputDirectory;
  MapAndList runMapAndRuns = runMapAndRuns(testCaseList);
  Map runMap = runMapAndRuns.map;
  List runs  = runMapAndRuns.list;
  createHtmlFile("contents-frame.html", indexHtml(runs, runMap, precisionModel));
  createHtmlFile("index.html", testTopHtml());
  int runSkey = 0;
  for (Iterator i = runs.iterator(); i.hasNext(); ) {
    String runDescription = (String) i.next();
    runSkey++;
    List testables = (List) runMap.get(runDescription);
    int caseSkey = 0;
    for (Iterator m = testables.iterator(); m.hasNext(); ) {
      Testable testable = (Testable) m.next();
      caseSkey++;
      if (busyDialog != null) {
        busyDialog.setDescription("Saving .html and .gif files: " + caseSkey
             + " of " + testCaseList.getList().size() + " tests");
      }
      createHtmlFile("Run" + runSkey + AppStrings.LABEL_TEST_CASE + caseSkey + ".html", html(testable, runSkey, caseSkey));
    }
  }
}
 
Example 17
Source File: BasicPessimisticLockingIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenFoundRecordWithPessimisticRead_whenFindingNewOne_PessimisticLockExceptionThrown() {
    try {
        EntityManager entityManager = getEntityManagerWithOpenTransaction();
        entityManager.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_READ);

        EntityManager entityManager2 = getEntityManagerWithOpenTransaction();
        entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_READ);

        entityManager.close();
        entityManager2.close();
    } catch (Exception e) {
        Assert.isTrue(e instanceof PessimisticLockException);
    }
}
 
Example 18
Source File: PNGWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void write(File outputDirectory, TestCaseEdit testCase, PrecisionModel precisionModel) throws IOException {
  Assert.isTrue(outputDirectory.isDirectory());
  this.outputDirectory = outputDirectory;
  createPNGFile("geoms", testCase.getGeometry(0),
      testCase.getGeometry(1), testCase.getResult(),
      IMAGE_WIDTH, IMAGE_HEIGHT);
}
 
Example 19
Source File: Parameters.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns true if key is one of the parameters. Case-insensitive.
 */
public boolean contains(String key) {
    Assert.isTrue(allowedKeys.contains(key.toLowerCase()));
    return hashtable.containsKey(key.toLowerCase());
}
 
Example 20
Source File: Parameters.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns the value of the specified parameter, or null if there is no such key. Case-insensitive.
 */
public String get(String key) {
    Assert.isTrue(allowedKeys.contains(key.toLowerCase()));
    return (String) hashtable.get(key.toLowerCase());
}