From 28f3e15dcd291163c41a1cab1c987344064cf40d Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 24 Oct 2014 11:37:55 +0200 Subject: Replace HashSet by LinkedHashSet to ease reproducibility in test cases --- .../src/main/java/org/sonar/graph/CycleDetector.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'sonar-graph') diff --git a/sonar-graph/src/main/java/org/sonar/graph/CycleDetector.java b/sonar-graph/src/main/java/org/sonar/graph/CycleDetector.java index 6dfb67b633d..29402fcc978 100644 --- a/sonar-graph/src/main/java/org/sonar/graph/CycleDetector.java +++ b/sonar-graph/src/main/java/org/sonar/graph/CycleDetector.java @@ -21,7 +21,7 @@ package org.sonar.graph; import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -30,7 +30,7 @@ public class CycleDetector { private Set vertices; private DirectedGraphAccessor graph; private Set analyzedVertices; - private Set cycles = new HashSet(); + private Set cycles = new LinkedHashSet(); private Set edgesToExclude; private long searchCyclesCalls = 0; private int maxSearchDepth = -1; @@ -38,7 +38,7 @@ public class CycleDetector { private int maxCyclesToFound = Integer.MAX_VALUE; public CycleDetector(DirectedGraphAccessor graph, Collection vertices) { - init(graph, vertices, new HashSet()); + init(graph, vertices, new LinkedHashSet()); } public CycleDetector(DirectedGraphAccessor graph, Collection vertices, Set edgesToExclude) { @@ -46,7 +46,7 @@ public class CycleDetector { } public CycleDetector(DirectedGraphAccessor graph) { - init(graph, graph.getVertices(), new HashSet()); + init(graph, graph.getVertices(), new LinkedHashSet()); } public CycleDetector(DirectedGraphAccessor graph, Set edgesToExclude) { @@ -55,8 +55,8 @@ public class CycleDetector { private void init(DirectedGraphAccessor graph, Collection vertices, Set edgesToExclude) { this.graph = graph; - this.vertices = new HashSet(vertices); - this.analyzedVertices = new HashSet(); + this.vertices = new LinkedHashSet(vertices); + this.analyzedVertices = new LinkedHashSet(); this.edgesToExclude = edgesToExclude; } @@ -87,7 +87,7 @@ public class CycleDetector { try { for (V vertex : vertices) { if (maxSearchDepthActivated || !analyzedVertices.contains(vertex)) { - Set tmpAnalyzedVertices = new HashSet(); + Set tmpAnalyzedVertices = new LinkedHashSet(); searchCycles(vertex, new ArrayList(), tmpAnalyzedVertices); analyzedVertices.addAll(tmpAnalyzedVertices); } @@ -104,7 +104,7 @@ public class CycleDetector { for (Edge edge : graph.getOutgoingEdges(fromVertex)) { V toVertex = edge.getTo(); if (!edgesToExclude.contains(edge) && vertices.contains(toVertex) - && (maxSearchDepthActivated || !analyzedVertices.contains(toVertex))) { + && (maxSearchDepthActivated || !analyzedVertices.contains(toVertex))) { if (path.contains(toVertex)) { path.add(toVertex); List cyclePath = path.subList(path.indexOf(toVertex), path.size()); -- cgit v1.2.3