Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;

Meant to be single-threaded. More work on whole impl if not.
 public class DirectedGraph<T> {
     private Map<T, Vertex<T>> vertices = new HashMap<T, Vertex<T>>();
     private Set<Edge<T>> edges = new HashSet<Edge<T>>();
     private ArrayList inOrderVerticeData = new ArrayList();
     int vertexIDCounter = 0;
     public Collection<Vertex<T>> vertices() {
         return .values();
     public Collection<Edge<T>> edges() {
         return ;
     public Iterable<Edge<T>> edgesOfType(Object type) {
         return new EdgeTypeIterable<T>(type);
     public Collection<T> allData() {
         return .keySet();

data in the order it was added to this graph.
     public Collection<T> getInorderData() {
         return ;
     public void addEdge(T source, T destinationObject type) {
     public void removeEdge(Edge edge) {
     public void removeEdge(T source, T destination) {
         for (Edge edgevertexFor(source).getOutgoingEdges()) {
             if (edge.getDestination().getData() == destination) {
     public Vertex<T> findVertexFor(T data) {
         return .get(data);
     public Vertex<T> vertexFor(T data) {
         Vertex vertex = .get(data);
         if (vertex != nullreturn vertex;
         vertex = new Vertex(thisdata++);
         return vertex;
     public void removeVertexFor(T data) {
         Vertex vertex = vertexFor(data);

the number of vertices in the graph.
     public int size() {
         return allData().size();
     public String toString() {
         StringBuilder buf = new StringBuilder();
         ArrayList<Vertex<T>> verts = new ArrayList<Vertex<T>>(.values());
         for (Vertex<T> vertexverts) {
        return buf.toString();
New to GrepCode? Check out our FAQ X