Skip to content

Commit

Permalink
Prevent overlogging of debug msgs in Graph impl
Browse files Browse the repository at this point in the history
* Refactored the logging in Graph to honour the 
Levels set in Logger.
* Got rid of some un-used methods.
  • Loading branch information
krmahadevan committed Oct 28, 2022
1 parent fba0723 commit 8a34c03
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions testng-core/src/main/java/org/testng/internal/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @author Cedric Beust, Aug 19, 2004
*/
public class Graph<T> {
private static final boolean m_verbose = true;
private final Map<T, Node<T>> m_nodes = Maps.newLinkedHashMap();
private List<T> m_strictlySortedNodes = null;
private final Comparator<Node<T>> comparator;
Expand Down Expand Up @@ -59,7 +58,6 @@ public void addPredecessor(T tm, T predecessor) {
throw new TestNGException("Non-existing node: " + tm);
} else {
node.addPredecessor(predecessor);
addNeighbor(tm, predecessor);
// Remove these two nodes from the independent list
initializeIndependentNodes();
m_independentNodes.remove(predecessor);
Expand All @@ -68,10 +66,6 @@ public void addPredecessor(T tm, T predecessor) {
}
}

private void addNeighbor(T tm, T predecessor) {
findNode(tm).addNeighbor(findNode(predecessor));
}

private Collection<Node<T>> getNodes() {
return m_nodes.values();
}
Expand Down Expand Up @@ -133,9 +127,7 @@ public void topologicalSort() {
}

log("=============== DONE SORTING");
if (m_verbose) {
dumpSortedNodes();
}
dumpSortedNodes();
}

private void initializeIndependentNodes() {
Expand Down Expand Up @@ -173,15 +165,11 @@ private void removeFromNodes(List<Node<T>> nodes, Node<T> node) {
}

private static void log(String s) {
if (m_verbose) {
Logger.getLogger(Graph.class).debug("[Graph] " + s);
}
log(() -> s);
}

private static void log(Supplier<String> s) {
if (m_verbose) {
Logger.getLogger(Graph.class).debug("[Graph] " + s.get());
}
Logger.getLogger(Graph.class).debug("[Graph] " + s.get());
}

private Node<T> findNodeWithNoPredecessors(List<Node<T>> nodes) {
Expand Down Expand Up @@ -253,12 +241,6 @@ public Node(T tm) {
m_object = tm;
}

private final Set<Node<T>> m_neighbors = new HashSet<>();

public void addNeighbor(Node<T> neighbor) {
m_neighbors.add(neighbor);
}

@Override
public Node<T> clone() {
Node<T> result = new Node<>(m_object);
Expand Down

0 comments on commit 8a34c03

Please sign in to comment.