From f51d791bf3c45222086f031f75cdaeae0358883a Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Mon, 12 Sep 2011 02:26:06 +0400 Subject: Fix violations --- .../org/sonar/plugins/cpd/DuplicationsData.java | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'plugins/sonar-cpd-plugin/src') diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/DuplicationsData.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/DuplicationsData.java index 1fc00423f99..55072da43b4 100644 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/DuplicationsData.java +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/DuplicationsData.java @@ -21,6 +21,7 @@ package org.sonar.plugins.cpd; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -67,7 +68,7 @@ public class DuplicationsData { } private String getDuplicationXMLData() { - Collections.sort(duplicationXMLEntries); + Collections.sort(duplicationXMLEntries, COMPARATOR); StringBuilder duplicationXML = new StringBuilder(""); for (XmlEntry xmlEntry : duplicationXMLEntries) { duplicationXML.append(xmlEntry.toString()); @@ -76,10 +77,16 @@ public class DuplicationsData { return duplicationXML.toString(); } - /** - * Note: this class has a natural ordering that is inconsistent with equals. - */ - private static final class XmlEntry implements Comparable { + private static final Comparator COMPARATOR = new Comparator() { + public int compare(XmlEntry o1, XmlEntry o2) { + if (o1.startLine == o2.startLine) { + return o1.lines - o2.lines; + } + return o1.startLine - o2.startLine; + } + }; + + private static final class XmlEntry { private String target; private int targetStartLine; private int startLine; @@ -100,13 +107,6 @@ public class DuplicationsData { .append("\" target-resource=\"").append(target).append("\"/>") .toString(); } - - public int compareTo(XmlEntry o) { - if (startLine == o.startLine) { - return lines - o.lines; - } - return startLine - o.startLine; - } } } -- cgit v1.2.3