Package org.geotools.graph.structure

Examples of org.geotools.graph.structure.GraphVisitor


   
    iterator.setSource(ends[0]);
    traversal.traverse();
   
    //stopping node should be visited and nodes with greater id should not
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        if (component.getID() <= suspend) assertTrue(component.isVisited());
        else assertTrue(!component.isVisited());
        return(0);
      }
    };
    builder().getGraph().visitNodes(visitor);
   
    //ensure nodes only visited once
    assertTrue(walker.getCount() == nnodes-suspend+1);
   
    traversal.traverse();
   
    //every node should now be visited
    visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        assertTrue(component.isVisited());  
        return(0);
      }
    };
View Full Code Here


   
    iterator.setSource(ends[0]);
    traversal.traverse();
   
    //kill node should be visited and nodes with greater id should not
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        if (component.getID() <= kill) assertTrue(component.isVisited());
        else assertTrue(!component.isVisited());
        return(0);
      }
View Full Code Here

     int k = 4;
     Object[] obj = GraphTestUtil.buildPerfectBinaryTree(builder(), k);
     Node root = (Node)obj[0];
     final Map obj2node = (Map)obj[1];
    
     GraphVisitor initializer = new GraphVisitor() {
      public int visit(Graphable component) {
        component.setCount(-1);
        return 0;
      }
     };
    
     CountingWalker walker = new CountingWalker() {
      public int visit(Graphable element, GraphTraversal traversal) {
        element.setCount(getCount());
        return super.visit(element, traversal);
      }
     };
    
     DepthFirstIterator iterator = createIterator();
     BasicGraphTraversal traversal = new BasicGraphTraversal(
       builder().getGraph(), walker, iterator
     );
     traversal.init();
    
     iterator.setSource(root);
     traversal.traverse();
    
     GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        //ensure component visited
        assertTrue(component.isVisited());
       
        Node ln = (Node)obj2node.get(component.getObject().toString() + ".0");
View Full Code Here

       (rn.isVisited() && !ln.isVisited()) ||
       (!rn.isVisited() && ln.isVisited())
     );
     assertTrue(walker.getCount() == 2);
    
     GraphVisitor visitor = new GraphVisitor() {
       public int visit(Graphable component) {
         if (component != root && component != ln && component != rn) {
           assertTrue(!component.isVisited())
         }
         return(0);
       }
     };
     builder().getGraph().visitNodes(visitor);
    
     traversal.traverse();
    
     //ensure all nodes visited
     visitor = new GraphVisitor() {
       public int visit(Graphable component) {
         assertTrue(component.isVisited());
         return(0);
       }
     };
View Full Code Here

     //ensure that subnodes of first visited after root are not visited
     final String id = (ln.getCount() < rn.getCount()) ?
                   ln.getObject().toString() :
                   rn.getObject().toString();
    
     GraphVisitor visitor = new GraphVisitor() {
       public int visit(Graphable component) {
         String eid = component.getObject().toString();
         if (eid.length() <= id.length()) assertTrue(component.isVisited());
         else if (eid.startsWith(id)) assertTrue(!component.isVisited());
         else assertTrue(component.isVisited());
View Full Code Here

    * Expected: 1. All nodes visited.
    */
   public void test_6() {
     int nnodes = 100;
     GraphTestUtil.buildCircular(builder(), nnodes);
     GraphVisitor visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          if (component.getID() == 50) return(Graph.PASS_AND_CONTINUE);
          return(Graph.FAIL_QUERY)
        }
     };
     Node source = (Node)builder().getGraph().queryNodes(visitor).get(0);
    
     CountingWalker walker = new CountingWalker();
     DepthFirstIterator iterator = createIterator();
    
     BasicGraphTraversal traversal = new BasicGraphTraversal(
       builder().getGraph(), walker, iterator
     );
     traversal.init();
    
     iterator.setSource(source);
     traversal.traverse();
    
     //ensure all nodes visisited
     visitor = new GraphVisitor() {
       public int visit(Graphable component) {
         assertTrue(component.isVisited());
         return(0);
       }
     };
View Full Code Here

  public void test_getEdges() {
    assertTrue(m_graph.getEdges() == m_edges);   
  }
 
  public void test_queryNodes() {
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        if (component == m_nodes.get(1) || component == m_nodes.get(2))
          return(BasicGraph.PASS_AND_CONTINUE);
        return(BasicGraph.FAIL_QUERY);
      }
View Full Code Here

    assertTrue(result.get(0) == m_nodes.get(1));
    assertTrue(result.get(1) == m_nodes.get(2));
  }

  public void test_queryEdges() {
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        if (component == m_edges.get(1) || component == m_edges.get(2))
          return(BasicGraph.PASS_AND_CONTINUE);
        return(BasicGraph.FAIL_QUERY);
      }
View Full Code Here

    assertTrue(result.get(1) == m_edges.get(2));
  }
 
  public void test_visitNodes() {
    final HashSet visited = new HashSet();
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        visited.add(component);
        return(0);
      }
    };
View Full Code Here

    }
  }
 
  public void test_visitEdges() {
    final HashSet visited = new HashSet();
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        visited.add(component);
        return(0);
      }
    };
View Full Code Here

TOP

Related Classes of org.geotools.graph.structure.GraphVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.