X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Futil%2FTopologicalSort.java;fp=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Futil%2FTopologicalSort.java;h=cea5a906f771f27ef9e2a106db793ed17212417c;hb=84929adc0968c0ad916b85ba9cb49d622abd17a7;hp=bb41743ef978a8a79b2886ed0e5cc95c133dcbbf;hpb=56d7e0525c7e580b6113cb82d0e7cb978a8e826b;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java index bb41743ef9..cea5a906f7 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java @@ -19,9 +19,15 @@ import com.google.common.collect.Sets; */ public final class TopologicalSort { + /** + * It isn't desirable to create instance of this class + */ + private TopologicalSort() { + } + /** * Topological sort of dependent nodes in acyclic graphs. - * + * * @return Sorted {@link List} of {@link Node}s. Order: Nodes with no * dependencies starting. * @throws IllegalStateException @@ -54,13 +60,13 @@ public final class TopologicalSort { } private static Set getDependentNodes(Set nodes) { - Set S = Sets.newHashSet(); + Set dependentNodes = Sets.newHashSet(); for (Node n : nodes) { if (n.getOutEdges().size() == 0) { - S.add(n); + dependentNodes.add(n); } } - return S; + return dependentNodes; } private static void detectCycles(Set nodes) { @@ -75,14 +81,13 @@ public final class TopologicalSort { break; } } - Preconditions.checkState(cycle == false, - "Cycle detected in graph around node: " + cycledNode); + Preconditions.checkState(!cycle, "Cycle detected in graph around node: " + cycledNode); } /** * Interface for nodes in graph that can be sorted topologically */ - public static interface Node { + public interface Node { Set getInEdges(); Set getOutEdges(); @@ -91,7 +96,7 @@ public final class TopologicalSort { /** * Interface for edges in graph that can be sorted topologically */ - public static interface Edge { + public interface Edge { Node getFrom(); Node getTo(); @@ -160,23 +165,30 @@ public final class TopologicalSort { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } EdgeImpl other = (EdgeImpl) obj; if (from == null) { - if (other.from != null) + if (other.from != null) { return false; - } else if (!from.equals(other.from)) + } + } else if (!from.equals(other.from)) { return false; + } if (to == null) { - if (other.to != null) + if (other.to != null) { return false; - } else if (!to.equals(other.to)) + } + } else if (!to.equals(other.to)) { return false; + } return true; } }