javatools.datatypes
Class DirectedGraph<E extends java.lang.Comparable<E>>

java.lang.Object
  extended by javatools.datatypes.DirectedGraph<E>
Direct Known Subclasses:
UndirectedGraph

public class DirectedGraph<E extends java.lang.Comparable<E>>
extends java.lang.Object

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class implements a directed Graph.


Nested Class Summary
static class DirectedGraph.Node<E extends java.lang.Comparable<E>>
          Represents a node of in a graph
 
Constructor Summary
DirectedGraph()
          Constructor for subclasses
 
Method Summary
 void addLink(E parent, E child)
          Adds a link from a parent to a child
 boolean contains(E label)
          True if that node exists
static DirectedGraph<java.lang.String> create(java.io.File file, java.util.regex.Pattern pattern)
          Constructs a directed graph from a File.
 DirectedGraph.Node<E> get(E label)
          Returns the node with the given label (or null)
 DirectedGraph.Node<E> getOrMake(E label)
          Returns or creates a node
 java.util.Collection<E> labels()
          Computes the set of labels
 java.util.SortedSet<DirectedGraph.Node<E>> leaves()
          Computes the nodes that have no leaves
 void makeClosure()
          Adds all transitive links
 java.util.Collection<DirectedGraph.Node<E>> nodes()
          Returns all nodes
 int numNodes()
          Returns the number of nodes
 java.util.SortedSet<DirectedGraph.Node<E>> roots()
          Computes the nodes that have no parents
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DirectedGraph

public DirectedGraph()
Constructor for subclasses

Method Detail

addLink

public void addLink(E parent,
                    E child)
Adds a link from a parent to a child


getOrMake

public DirectedGraph.Node<E> getOrMake(E label)
Returns or creates a node


create

public static DirectedGraph<java.lang.String> create(java.io.File file,
                                                     java.util.regex.Pattern pattern)
                                              throws java.io.IOException
Constructs a directed graph from a File. Previously a constructor, but that caused compilation problems

Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

roots

public java.util.SortedSet<DirectedGraph.Node<E>> roots()
Computes the nodes that have no parents


leaves

public java.util.SortedSet<DirectedGraph.Node<E>> leaves()
Computes the nodes that have no leaves


nodes

public java.util.Collection<DirectedGraph.Node<E>> nodes()
Returns all nodes


numNodes

public int numNodes()
Returns the number of nodes


labels

public java.util.Collection<E> labels()
Computes the set of labels


get

public DirectedGraph.Node<E> get(E label)
Returns the node with the given label (or null)


contains

public boolean contains(E label)
True if that node exists


makeClosure

public void makeClosure()
Adds all transitive links