Class DirectedGraph<E>


  • public class DirectedGraph<E>
    extends Object
    Directed graph with elements of a certain type as nodes
    Version:
    $Rev$
    Author:
    herrmama, $Author$
    • Constructor Detail

      • DirectedGraph

        public DirectedGraph()
        Default constructor
      • DirectedGraph

        public DirectedGraph​(Collection<E> elements)
        Constructor that adds a number of elements as initial nodes
        Parameters:
        elements - Initial nodes
    • Method Detail

      • add

        public void add​(E element)
        Add an element as node
        Parameters:
        element - Element
      • remove

        public void remove​(E element)
        Remove an element as node
        Parameters:
        element - Element
      • addOrder

        public void addOrder​(E source,
                             E target)
        Add an edge between two elements
        Parameters:
        source - Source element
        target - Target element
      • removeOrder

        public void removeOrder​(E source,
                                E target)
        Remove an edge between two elements
        Parameters:
        source - Source element
        target - Target element
      • getIncoming

        public Set<E> getIncoming​(E element)
        Get the elements which are source of incoming edges
        Parameters:
        element - Element
        Returns:
        Elements
      • getOutgoing

        public Set<E> getOutgoing​(E element)
        Get the elements which are target of outgoing edges
        Parameters:
        element -
        Returns:
        Elements
      • getElements

        public Set<E> getElements()
        Getter for elements
        Returns:
        Elements
      • isEmpty

        public boolean isEmpty()
        Return whether the graph is empty
        Returns:
        empty or not?
      • getNoIncomingElement

        public E getNoIncomingElement()
        Return all elements which do not have incoming edges
        Returns:
        Elements
      • contains

        public boolean contains​(E element)
        Determine whether an element in contained in the directed graph
        Parameters:
        element -
        Returns:
        true if contained, false otherwise
      • getOrdering

        public List<E> getOrdering()
        Calculate a topological sorting of the elements in the directed graph. Note that the directed graph is destroyed in response to this calculation.
        Returns:
        Topological sorting of element, null if the directed graph contains a cycle