org.openide.util
Class TopologicalSortException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by org.openide.util.TopologicalSortException
All Implemented Interfaces:
java.io.Serializable

public final class TopologicalSortException
extends java.lang.Exception

Exception that signals that a topological sort failed due to unsortable nature of the graph and that provides support for reporting and recovering from that state.

Since:
3.30
Author:
Jaroslav Tulach
See Also:
Utilities.topologicalSort(java.util.Collection, java.util.Map>), Serialized Form

Constructor Summary
TopologicalSortException(java.util.Collection vertexes, java.util.Map edges)
           
 
Method Summary
 java.lang.String getMessage()
           
 java.util.List partialSort()
          Because the full sort was not possible, this methods returns the best possible substitute for it that is available.
 void printStackTrace(java.io.PrintStream s)
          Adds description why the graph cannot be sorted.
 void printStackTrace(java.io.PrintWriter w)
          Adds description why the graph cannot be sorted.
 java.util.Set[] topologicalSets()
          As the full topological sort cannot be finished due to cycles in the graph this methods performs a partition topological sort.
 java.lang.String toString()
           
 java.util.Set[] unsortableSets()
          The topological sort could not be finished as there are some objects that are mutually refering to each other.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TopologicalSortException

TopologicalSortException(java.util.Collection vertexes,
                         java.util.Map edges)
Method Detail

partialSort

public final java.util.List partialSort()
Because the full sort was not possible, this methods returns the best possible substitute for it that is available.

Returns:
list of partially sorted objects, the list can be freely modified

unsortableSets

public final java.util.Set[] unsortableSets()
The topological sort could not be finished as there are some objects that are mutually refering to each other. This methods finds such objects and partition them into separate sets. All objects in one set (transitively) refer to each other and thus prevent the sort from succeding. As there can be more of such "unsortable sets" an array of them is returned.

Returns:
array of sets that contain some of the original objects, result shall not be modified

getMessage

public java.lang.String getMessage()
Overrides:
getMessage in class java.lang.Throwable

toString

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

printStackTrace

public final void printStackTrace(java.io.PrintWriter w)
Adds description why the graph cannot be sorted.

Overrides:
printStackTrace in class java.lang.Throwable
Parameters:
w - writer to write to

printStackTrace

public final void printStackTrace(java.io.PrintStream s)
Adds description why the graph cannot be sorted.

Overrides:
printStackTrace in class java.lang.Throwable
Parameters:
s - stream to write to

topologicalSets

public final java.util.Set[] topologicalSets()
As the full topological sort cannot be finished due to cycles in the graph this methods performs a partition topological sort.

First of all it identifies unsortable parts of the graph and partitions the graph into sets of original objects. Each set contains objects that are mutually unsortable (there is a cycle between them). Then the topological sort is performed again on those sets, this sort succeeds because the graph of sets is DAG (all problematic edges were only between objects now grouped inside the sets) and the result forms the return value of this method.

Returns:
array of sorted sets that contain the original objects, each object from the original collection is exactly in one set, result shall not be modified