Package org.geotools.graph.build

Examples of org.geotools.graph.build.GraphBuilder


 
  /**
   * @see GraphBuilder#clone(boolean)
   */
  public Object clone(boolean deep) throws Exception {
    GraphBuilder builder = (GraphBuilder)getClass().newInstance();
    if (deep) builder.importGraph(getGraph());
   
    return(builder);
  }
View Full Code Here


   *
   * @see GraphReaderWriter#read()
   */
  public Graph read() throws Exception {
    //read builder property
    GraphBuilder builder = (GraphBuilder)getProperty(BUILDER);
 
    //create file input stream
    ObjectInputStream objin = new ObjectInputStream(
      new BufferedInputStream(
        new FileInputStream((String)getProperty(FILENAME))
      )
    );
   
    //read header
    int nnodes = objin.readInt();
    int nedges = objin.readInt();
   
    //rebuild edge collection, upon reading an edge, at the edge to the
    // adjacency list of each of its nodes
    int count = 0;
    while(count++ < nedges) {
      Edge e = (Edge)objin.readObject();
      e.getNodeA().setVisited(false);
      e.getNodeB().setVisited(false);
      builder.addEdge(e);
    }
   
    //rebuild node collection
    for (
      Iterator itr = builder.getGraph().getEdges().iterator(); itr.hasNext();
    ) {
      Edge e = (Edge)itr.next();
   
      if (!e.getNodeA().isVisited()) {
        e.getNodeA().setVisited(true);
        builder.addNode(e.getNodeA())
     
     
      if (!e.getNodeB().isVisited()) {
        e.getNodeB().setVisited(true);
        builder.addNode(e.getNodeB());
      }
    }
   
    //check if object stream is empty, if not, there are nodes of degree 0
    // in the graph
    try {
      Node n;
     
      while((n = (Node)objin.readObject()) != null) {
        builder.addNode(n)
     
    }
    catch(EOFException ignore) {}
   
    return(builder.getGraph());
  }
View Full Code Here

TOP

Related Classes of org.geotools.graph.build.GraphBuilder

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.