nanomunchers.graph
Class GraphFactory

java.lang.Object
  extended bynanomunchers.graph.GraphFactory

public class GraphFactory
extends java.lang.Object

The only way to build a new graph is through the Factory.

Author:
David Kaplin

Constructor Summary
GraphFactory()
           
 
Method Summary
static Graph buildFromParts(Node[] nodes, Edge[] edges)
          Creats a new graph from a set of nodes and edges
static Graph buildGridGraph(int width, int height)
          Builds a graph that resembles a city grid.
static Graph buildRandomized(Graph src, double chanceNodeRemoved)
          Builds a graph with a random number of edges removed
static Graph loadFile(java.lang.String name)
           
static Graph loadHttpURL(java.lang.String url)
          Attempts to load a graph from anywhere in the web.
static void saveFile(java.lang.String name, Graph toSave)
          Saves a given graph to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphFactory

public GraphFactory()
Method Detail

buildRandomized

public static Graph buildRandomized(Graph src,
                                    double chanceNodeRemoved)
Builds a graph with a random number of edges removed

Parameters:
src - intial graph before removal
chanceNodeRemoved - 0.0 - 1.0 of removal
Returns:
a new graph that contains less edges.

buildFromParts

public static Graph buildFromParts(Node[] nodes,
                                   Edge[] edges)
Creats a new graph from a set of nodes and edges

Parameters:
nodes - from a previous graph
edges - from a previous graph
Returns:
a new graph

buildGridGraph

public static Graph buildGridGraph(int width,
                                   int height)
Builds a graph that resembles a city grid.

Parameters:
width - of the grid
height - of the grid
Returns:
a new Graph

saveFile

public static void saveFile(java.lang.String name,
                            Graph toSave)
                     throws java.io.IOException
Saves a given graph to a file.

Parameters:
name - of the file to save
toSave - Graph data to save.
Throws:
java.io.IOException - related to file issues

loadHttpURL

public static Graph loadHttpURL(java.lang.String url)
                         throws java.io.IOException
Attempts to load a graph from anywhere in the web.

Parameters:
url - location of the graph
Returns:
a new graph from the data retrieved.
Throws:
java.io.IOException - any possible problems with the file or connection.

loadFile

public static Graph loadFile(java.lang.String name)
                      throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException