aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-11-18 09:08:40 -0600
committersonartech <sonartech@sonarsource.com>2021-11-18 20:03:33 +0000
commit9f7a5068bb26f2760332c6e0bacec424e2edd47a (patch)
tree51ff128c6f77d1d15db5abe7960a90c74ee3d783 /sonar-duplications
parenteda9dff59cc60209b15b69ef4aa4c18885c0c744 (diff)
downloadsonarqube-9f7a5068bb26f2760332c6e0bacec424e2edd47a.tar.gz
sonarqube-9f7a5068bb26f2760332c6e0bacec424e2edd47a.zip
Improve code quality
Diffstat (limited to 'sonar-duplications')
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java28
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java3
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java11
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java21
4 files changed, 26 insertions, 37 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java b/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
index 012a71cf976..1017c4649c4 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
@@ -32,14 +32,26 @@ public final class Block {
private final int startLine;
private final int endLine;
- private int startUnit;
- private int endUnit;
+ private final int startUnit;
+ private final int endUnit;
/**
* Cache for hash code.
*/
private int hash;
+ private Block(Builder builder) {
+ this.resourceId = builder.resourceId;
+ this.blockHash = builder.blockHash;
+ this.indexInFile = builder.indexInFile;
+
+ this.startLine = builder.startLine;
+ this.endLine = builder.endLine;
+
+ this.startUnit = builder.startUnit;
+ this.endUnit = builder.endUnit;
+ }
+
/**
* @since 2.14
*/
@@ -97,18 +109,6 @@ public final class Block {
}
}
- private Block(Builder builder) {
- this.resourceId = builder.resourceId;
- this.blockHash = builder.blockHash;
- this.indexInFile = builder.indexInFile;
-
- this.startLine = builder.startLine;
- this.endLine = builder.endLine;
-
- this.startUnit = builder.startUnit;
- this.endUnit = builder.endUnit;
- }
-
public String getHashHex() {
return getBlockHash().toString();
}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java b/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java
index 2cb7546fd50..306a91dff6a 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java
@@ -30,6 +30,7 @@ import java.util.Arrays;
* also maybe we can incorporate it into Block to reduce memory footprint during detection of duplicates
*/
public final class ByteArray {
+ private static final String HEXES = "0123456789abcdef";
private final byte[] bytes;
@@ -103,8 +104,6 @@ public final class ByteArray {
return result;
}
- private static final String HEXES = "0123456789abcdef";
-
public String toHexString() {
StringBuilder hex = new StringBuilder(2 * bytes.length);
for (byte b : bytes) {
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java
index 65e182b11eb..dd142833c4c 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java
@@ -30,8 +30,13 @@ import org.sonar.duplications.utils.FastStringComparator;
* Set of {@link Block}s, which internally stored as a sorted list.
*/
final class BlocksGroup {
+ private static final Comparator<String> RESOURCE_ID_COMPARATOR = FastStringComparator.INSTANCE;
final List<Block> blocks;
+ private BlocksGroup() {
+ this.blocks = new ArrayList<>();
+ }
+
/**
* Factory method.
*
@@ -41,10 +46,6 @@ final class BlocksGroup {
return new BlocksGroup();
}
- private BlocksGroup() {
- this.blocks = new ArrayList<>();
- }
-
public int size() {
return blocks.size();
}
@@ -193,8 +194,6 @@ final class BlocksGroup {
return result;
}
- private static final Comparator<String> RESOURCE_ID_COMPARATOR = FastStringComparator.INSTANCE;
-
/**
* Compares {@link Block}s first using {@link Block#getResourceId() resource id} and then using {@link Block#getIndexInFile() index in file}.
*/
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java
index ecb687e36d8..5d01ee6c9b9 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java
@@ -21,7 +21,6 @@ package org.sonar.duplications.detector.suffixtree;
import java.util.ArrayList;
import java.util.List;
-
import org.sonar.duplications.block.Block;
@@ -29,10 +28,15 @@ import org.sonar.duplications.block.Block;
* Simplifies construction of <a href="http://en.wikipedia.org/wiki/Generalised_suffix_tree">generalised suffix-tree</a>.
*/
public final class TextSet extends AbstractText {
+ private final int lengthOfOrigin;
+ private TextSet(List<Object> symbols, int lengthOfOrigin) {
+ super(symbols);
+ this.lengthOfOrigin = lengthOfOrigin;
+ }
public static final class Builder {
- private List<Object> symbols = new ArrayList<>();
+ private final List<Object> symbols = new ArrayList<>();
private Integer lengthOfOrigin;
private int count;
@@ -58,13 +62,6 @@ public final class TextSet extends AbstractText {
return new Builder();
}
- private final int lengthOfOrigin;
-
- private TextSet(List<Object> symbols, int lengthOfOrigin) {
- super(symbols);
- this.lengthOfOrigin = lengthOfOrigin;
- }
-
public boolean isInsideOrigin(int pos) {
return pos < lengthOfOrigin;
}
@@ -100,15 +97,9 @@ public final class TextSet extends AbstractText {
return stringNumber;
}
- public int getStringNumber() {
- return stringNumber;
- }
-
@Override
public String toString() {
return "$" + stringNumber;
}
-
}
-
}