aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications/src/main/java/org/sonar
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2012-02-03 16:14:58 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-02-04 01:58:31 +0400
commit480b51e830ad9f64a363b86bbf183879a5a76728 (patch)
treeafe8ab464c42aac71f8d25d8b46db05c32458ee7 /sonar-duplications/src/main/java/org/sonar
parentee368b839c08103857e0791c8957f9179e40f058 (diff)
downloadsonarqube-480b51e830ad9f64a363b86bbf183879a5a76728.tar.gz
sonarqube-480b51e830ad9f64a363b86bbf183879a5a76728.zip
Fix some quality flaws
Diffstat (limited to 'sonar-duplications/src/main/java/org/sonar')
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java2
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java12
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java61
3 files changed, 53 insertions, 22 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
index bef9f4e80a4..afefdef5c07 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
@@ -223,7 +223,7 @@ public final class OriginalCloneDetectionAlgorithm {
parts.add(part);
}
- filter.add(new CloneGroup(cloneLength, origin, parts));
+ filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build());
}
}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java
index 6c05737240b..b36f5b3c94f 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java
@@ -80,8 +80,10 @@ public class DuplicationsCollector extends Search.Collector {
*/
@Override
public void endOfGroup() {
- int lengthInUnits = 0;
ClonePart origin = null;
+
+ CloneGroup.Builder builder = CloneGroup.builder().setLength(length);
+
List<ClonePart> parts = Lists.newArrayListWithCapacity(count);
for (int[] b : blockNumbers) {
Block firstBlock = text.getBlock(b[0]);
@@ -97,7 +99,7 @@ public class DuplicationsCollector extends Search.Collector {
if (origin == null) {
origin = part;
// To calculate length important to use the origin, because otherwise block may come from DB without required data
- lengthInUnits = lastBlock.getEndUnit() - firstBlock.getStartUnit() + 1;
+ builder.setLengthInUnits(lastBlock.getEndUnit() - firstBlock.getStartUnit() + 1);
} else if (part.getUnitStart() < origin.getUnitStart()) {
origin = part;
}
@@ -107,11 +109,9 @@ public class DuplicationsCollector extends Search.Collector {
}
Collections.sort(parts, ContainsInComparator.CLONEPART_COMPARATOR);
+ builder.setOrigin(origin).setParts(parts);
- CloneGroup group = new CloneGroup(length, origin, parts);
- group.setLengthInUnits(lengthInUnits);
-
- filter(group);
+ filter(builder.build());
reset();
}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java
index dfb86bb93d6..eda0b40b8cd 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java
@@ -38,10 +38,52 @@ public class CloneGroup {
*/
private int hash;
- public CloneGroup(int cloneLength, ClonePart origin, List<ClonePart> parts) {
- this.cloneLength = cloneLength;
- this.originPart = origin;
- this.parts = ImmutableList.copyOf(parts);
+ /**
+ * @since 2.14
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * @since 2.14
+ */
+ public static final class Builder {
+ private ClonePart origin;
+ private int length;
+ private int lengthInUnits;
+ private List<ClonePart> parts;
+
+ public Builder setLength(int length) {
+ this.length = length;
+ return this;
+ }
+
+ public Builder setOrigin(ClonePart origin) {
+ this.origin = origin;
+ return this;
+ }
+
+ public Builder setParts(List<ClonePart> parts) {
+ this.parts = ImmutableList.copyOf(parts);
+ return this;
+ }
+
+ public Builder setLengthInUnits(int length) {
+ this.lengthInUnits = length;
+ return this;
+ }
+
+ public CloneGroup build() {
+ return new CloneGroup(this);
+ }
+ }
+
+ private CloneGroup(Builder builder) {
+ this.cloneLength = builder.length;
+ this.originPart = builder.origin;
+ this.parts = builder.parts;
+ this.length = builder.lengthInUnits;
}
public ClonePart getOriginPart() {
@@ -61,17 +103,6 @@ public class CloneGroup {
}
/**
- * TODO get rid of this method, otherwise class is not immutable
- *
- * @since 2.14
- * @see #getLengthInUnits()
- */
- @Beta
- public void setLengthInUnits(int length) {
- this.length = length;
- }
-
- /**
* @return clone length in {@link org.sonar.duplications.block.Block}s
*/
public int getCloneUnitLength() {