X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FPathFinder.java;h=fe3fdb6e85bfa443bddcc998ca41fd353d5ff516;hp=d8beab5a2d4c60385dec703571d92d5c48a965b0;hb=98572b78fcce9ff28fa7429c9265812bd1e78bf2;hpb=0a440fd3ae3b413cd7de57677aec690f14ec7d53 diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java index d8beab5a..fe3fdb6e 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java @@ -32,10 +32,10 @@ import org.onap.dmaap.datarouter.node.NodeConfig.ProvHop; /** * Given a set of node names and next hops, identify and ignore any cycles and figure out the sequence of next hops to - * get from this node to any other node + * get from this node to any other node. */ -public class PathFinder { +class PathFinder { private ArrayList errors = new ArrayList<>(); private HashMap routes = new HashMap<>(); @@ -47,7 +47,7 @@ public class PathFinder { * @param nodes where we can go * @param hops detours along the way */ - public PathFinder(String origin, String[] nodes, NodeConfig.ProvHop[] hops) { + PathFinder(String origin, String[] nodes, NodeConfig.ProvHop[] hops) { HashSet known = new HashSet<>(); HashMap> ht = new HashMap<>(); for (String n : nodes) { @@ -55,13 +55,13 @@ public class PathFinder { ht.put(n, new HashMap<>()); } for (NodeConfig.ProvHop ph : hops) { - Hop h = getHop(known, ht, ph); - if (h == null) { + Hop hop = getHop(known, ht, ph); + if (hop == null) { continue; } if (ph.getVia().equals(ph.getTo())) { errors.add(ph + " gives destination as via"); - h.bad = true; + hop.bad = true; } } for (String n : known) { @@ -73,21 +73,21 @@ public class PathFinder { } /** - * Get list of errors encountered while finding paths + * Get list of errors encountered while finding paths. * * @return array of error descriptions */ - public String[] getErrors() { - return (errors.toArray(new String[errors.size()])); + String[] getErrors() { + return (errors.toArray(new String[0])); } /** - * Get the route from this node to the specified node + * Get the route from this node to the specified node. * * @param destination node * @return list of node names separated by and ending with "/" */ - public String getPath(String destination) { + String getPath(String destination) { String ret = routes.get(destination); if (ret == null) { return (""); @@ -109,12 +109,12 @@ public class PathFinder { return (to); } nh.mark = true; - String x = plot(nh.basis.getVia(), to, info); + String route = plot(nh.basis.getVia(), to, info); nh.mark = false; if (nh.bad) { return (to); } - return (nh.basis.getVia() + "/" + x); + return (nh.basis.getVia() + "/" + route); } @Nullable @@ -128,21 +128,21 @@ public class PathFinder { return null; } HashMap ht2 = ht.get(ph.getTo()); - Hop h = ht2.get(ph.getFrom()); - if (h != null) { - h.bad = true; - errors.add(ph + " gives duplicate next hop - previous via was " + h.basis.getVia()); + Hop hop = ht2.get(ph.getFrom()); + if (hop != null) { + hop.bad = true; + errors.add(ph + " gives duplicate next hop - previous via was " + hop.basis.getVia()); return null; } - h = new Hop(); - h.basis = ph; - ht2.put(ph.getFrom(), h); + hop = new Hop(); + hop.basis = ph; + ht2.put(ph.getFrom(), hop); if (!known.contains(ph.getVia())) { errors.add(ph + " references unknown via node"); - h.bad = true; + hop.bad = true; return null; } - return h; + return hop; } private static class Hop {