Class GraphCycleDetector


  • public class GraphCycleDetector
    extends java.lang.Object
    Helper class for graph cycle detection. Usage : - addRelations() + removeRelations() to create target graph. - checkCycles() to get cycles in the graph, if any.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addRelations​(java.lang.String child, java.util.Collection<java.lang.String> parents)
      Add child/parent relations to the graph
      java.util.Set<java.lang.String> checkCycles()
      Check cycles among the graph.
      void removeRelations​(java.lang.String child, java.util.Collection<java.lang.String> parents)
      Remove child/parent relations from the graph
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GraphCycleDetector

        public GraphCycleDetector()
    • Method Detail

      • addRelations

        public void addRelations​(java.lang.String child,
                                 java.util.Collection<java.lang.String> parents)
        Add child/parent relations to the graph
        Parameters:
        child - the child unit id
        parents - the list of parent unit ids
      • removeRelations

        public void removeRelations​(java.lang.String child,
                                    java.util.Collection<java.lang.String> parents)
        Remove child/parent relations from the graph
        Parameters:
        child - the child unit id
        parents - the list of parent unit ids
      • checkCycles

        public java.util.Set<java.lang.String> checkCycles()
        Check cycles among the graph.
        Returns:
        a set of unit ids having one or more cycles is any. An empty set is returned if no cycles are detected.