aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-01-28 11:39:17 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-01-29 13:56:54 +0100
commitc642d3b272ccc98e2ca86faa4b1d0dd959e9dfb4 (patch)
tree47f05c4ae7e04804fde72b790f1ca15616190d6b /sonar-plugin-api
parentfe52419c31e549fb36a3e2262d75a4acb2b0c61b (diff)
downloadsonarqube-c642d3b272ccc98e2ca86faa4b1d0dd959e9dfb4.tar.gz
sonarqube-c642d3b272ccc98e2ca86faa4b1d0dd959e9dfb4.zip
IN claus and group of OR should have constant order and no duplicate
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java20
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java13
2 files changed, 26 insertions, 7 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java
index 6e78677885b..56517648f19 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java
@@ -21,8 +21,8 @@ package org.sonar.api.rule;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-
import java.io.Serializable;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/**
@@ -31,7 +31,7 @@ import javax.annotation.concurrent.Immutable;
* @since 3.6
*/
@Immutable
-public class RuleKey implements Serializable {
+public class RuleKey implements Serializable, Comparable<RuleKey> {
public static final String MANUAL_REPOSITORY_KEY = "manual";
private final String repository;
@@ -82,7 +82,7 @@ public class RuleKey implements Serializable {
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
@@ -90,10 +90,7 @@ public class RuleKey implements Serializable {
return false;
}
RuleKey ruleKey = (RuleKey) o;
- if (!repository.equals(ruleKey.repository)) {
- return false;
- }
- return rule.equals(ruleKey.rule);
+ return repository.equals(ruleKey.repository) && rule.equals(ruleKey.rule);
}
@Override
@@ -110,4 +107,13 @@ public class RuleKey implements Serializable {
public String toString() {
return String.format("%s:%s", repository, rule);
}
+
+ @Override
+ public int compareTo(RuleKey o) {
+ int compareRepositories = this.repository.compareTo(o.repository);
+ if (compareRepositories == 0) {
+ return this.rule.compareTo(o.rule);
+ }
+ return compareRepositories;
+ }
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
index 52ef4baabee..15476493783 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
@@ -121,4 +121,17 @@ public class RuleKeyTest {
assertThat(key1.hashCode()).isEqualTo(key1.hashCode());
assertThat(key1.hashCode()).isEqualTo(key2.hashCode());
}
+
+ @Test
+ public void test_compareTo() {
+ RuleKey aa = RuleKey.of("A", "A");
+ RuleKey ab = RuleKey.of("A", "B");
+
+ assertThat(ab).isGreaterThan(aa);
+ assertThat(aa).isLessThan(ab);
+ assertThat(aa).isNotEqualTo(ab);
+ assertThat(ab).isNotEqualTo(aa);
+ assertThat(aa).isEqualTo(aa);
+ assertThat(ab).isEqualTo(ab);
+ }
}