]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6370 Decrease coupling of sonar-duplications with guava
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 25 May 2015 19:38:15 +0000 (21:38 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 28 May 2015 07:28:50 +0000 (09:28 +0200)
18 files changed:
sonar-batch/src/main/java/org/sonar/batch/cpd/DefaultCpdEngine.java
sonar-batch/src/main/java/org/sonar/batch/cpd/DuplicationPredicates.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/cpd/DuplicationPredicatesTest.java [new file with mode: 0644]
sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java
sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java
sonar-duplications/src/main/java/org/sonar/duplications/CodeFragment.java
sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
sonar-duplications/src/main/java/org/sonar/duplications/block/BlockChunker.java
sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java
sonar-duplications/src/main/java/org/sonar/duplications/detector/original/Filter.java
sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java
sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/Search.java
sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithm.java
sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java
sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java
sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java
sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java

index 3674eca2ee04b02d2dd40a49404e55ff918a4833..93fc1726b46cab5c7046e61bebb783b2a709fbdc 100644 (file)
@@ -37,7 +37,6 @@ import org.sonar.api.resources.Project;
 import org.sonar.api.utils.SonarException;
 import org.sonar.batch.cpd.index.IndexFactory;
 import org.sonar.batch.cpd.index.SonarDuplicationsIndex;
-import org.sonar.duplications.DuplicationPredicates;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.internal.pmd.TokenizerBridge;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/DuplicationPredicates.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/DuplicationPredicates.java
new file mode 100644 (file)
index 0000000..0e6567e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.cpd;
+
+import com.google.common.base.Predicate;
+import org.sonar.duplications.index.CloneGroup;
+
+import javax.annotation.Nullable;
+
+public final class DuplicationPredicates {
+
+  private DuplicationPredicates() {
+  }
+
+  public static Predicate<CloneGroup> numberOfUnitsNotLessThan(int min) {
+    return new NumberOfUnitsNotLessThan(min);
+  }
+
+  private static class NumberOfUnitsNotLessThan implements Predicate<CloneGroup> {
+    private final int min;
+
+    public NumberOfUnitsNotLessThan(int min) {
+      this.min = min;
+    }
+
+    @Override
+    public boolean apply(@Nullable CloneGroup input) {
+      return input != null && input.getLengthInUnits() >= min;
+    }
+  }
+
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/cpd/DuplicationPredicatesTest.java b/sonar-batch/src/test/java/org/sonar/batch/cpd/DuplicationPredicatesTest.java
new file mode 100644 (file)
index 0000000..d3e318c
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.cpd;
+
+import com.google.common.base.Predicate;
+import org.junit.Test;
+import org.sonar.duplications.index.CloneGroup;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DuplicationPredicatesTest {
+
+  @Test
+  public void testNumberOfUnitsNotLessThan() {
+    Predicate<CloneGroup> predicate = DuplicationPredicates.numberOfUnitsNotLessThan(5);
+    assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(6).build())).isTrue();
+    assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(5).build())).isTrue();
+    assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(4).build())).isFalse();
+  }
+
+}
index 57501d25d7a1a4183a6db5d0416f4d6845e990b8..675c3f152f2d8d74b873f2166e34cf196109db02 100644 (file)
  */
 package net.sourceforge.pmd.cpd;
 
-import com.google.common.io.Closeables;
-
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.io.StringReader;
 import java.lang.ref.SoftReference;
 import java.util.ArrayList;
 import java.util.List;
@@ -59,9 +62,7 @@ public class SourceCode {
     protected abstract Reader getReader() throws Exception;
 
     protected List<String> load() {
-      LineNumberReader lnr = null;
-      try {
-        lnr = new LineNumberReader(getReader());
+      try (LineNumberReader lnr = new LineNumberReader(getReader())) {
         List<String> lines = new ArrayList<>();
         String currentLine;
         while ((currentLine = lnr.readLine()) != null) {
@@ -70,8 +71,6 @@ public class SourceCode {
         return lines;
       } catch (Exception e) {
         throw new IllegalStateException("Problem while reading " + getFileName() + ":" + e.getMessage(), e);
-      } finally {
-        Closeables.closeQuietly(lnr);
       }
     }
   }
index 395c9f9bdc29db86293a8936656eb8d0c5eb6b07..0a18f175a79209443b7aaab6fcbc96f25425c08c 100644 (file)
  */
 package net.sourceforge.pmd.cpd;
 
-import com.google.common.annotations.Beta;
-import org.apache.commons.lang.builder.ToStringBuilder;
-
 import java.util.HashMap;
 import java.util.Map;
+import org.apache.commons.lang.builder.ToStringBuilder;
 
 /**
  * @since 2.2
@@ -81,7 +79,6 @@ public class TokenEntry implements Comparable<TokenEntry> {
    *
    * @since 2.14
    */
-  @Beta
   public String getValue() {
     return value;
   }
index 42e30bfec1343b3ade127d8b758b430865241c54..375061dff8a599ca4d5aaa2a5d950a11669efd71 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.duplications;
 
-import com.google.common.annotations.Beta;
 
 /**
  * TODO Enforce contracts of this interface in concrete classes by using preconditions, currently this leads to failures of tests.
@@ -28,7 +27,6 @@ import com.google.common.annotations.Beta;
  *
  * @since 2.14
  */
-@Beta
 public interface CodeFragment {
 
   /**
index 349ada7dd162f49f701d4937fd0d275d65ff7435..32167066a40fbc54ec79cf7975aae17f7e07793d 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.duplications.block;
 
-import com.google.common.annotations.Beta;
 import org.sonar.duplications.CodeFragment;
 
 /**
@@ -89,7 +88,6 @@ public final class Block implements CodeFragment {
       return this;
     }
 
-    @Beta
     public Builder setUnit(int start, int end) {
       this.startUnit = start;
       this.endUnit = end;
@@ -142,7 +140,6 @@ public final class Block implements CodeFragment {
   /**
    * @since 2.14
    */
-  @Beta
   public int getStartUnit() {
     return startUnit;
   }
@@ -150,7 +147,6 @@ public final class Block implements CodeFragment {
   /**
    * @since 2.14
    */
-  @Beta
   public int getEndUnit() {
     return endUnit;
   }
index d7adf472f2f97622e80204de7516786a680d7568..31034f70f631355f6efd38f3f2caa009a3df3fe9 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.block;
 
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
 import org.sonar.duplications.statement.Statement;
 
 import java.util.Collections;
@@ -55,7 +55,7 @@ public class BlockChunker {
   }
 
   public List<Block> chunk(String resourceId, List<Statement> statements) {
-    List<Statement> filtered = Lists.newArrayList();
+    List<Statement> filtered = new ArrayList<>();
     int i = 0;
     while (i < statements.size()) {
       Statement first = statements.get(i);
@@ -75,7 +75,7 @@ public class BlockChunker {
       return Collections.emptyList();
     }
     Statement[] statementsArr = statements.toArray(new Statement[statements.size()]);
-    List<Block> blocks = Lists.newArrayListWithCapacity(statementsArr.length - blockSize + 1);
+    List<Block> blocks = new ArrayList<>(statementsArr.length - blockSize + 1);
     long hash = 0;
     int first = 0;
     int last = 0;
index 063d98891acb585be4336f0cca6c94b9b4c553b5..67689f1e70c572d8a0865a80eaec3f44f5b6ad77 100644 (file)
  */
 package org.sonar.duplications.detector.original;
 
+import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
-
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.utils.FastStringComparator;
 
-import com.google.common.collect.Lists;
-
 /**
  * Set of {@link Block}s, which internally stored as a sorted list.
  */
@@ -44,7 +42,7 @@ final class BlocksGroup {
   protected final List<Block> blocks;
 
   private BlocksGroup() {
-    this.blocks = Lists.newArrayList();
+    this.blocks = new ArrayList<>();
   }
 
   public int size() {
@@ -167,7 +165,7 @@ final class BlocksGroup {
   }
 
   private static List<Block[]> pairs(BlocksGroup beginGroup, BlocksGroup endGroup, int len) {
-    List<Block[]> result = Lists.newArrayList();
+    List<Block[]> result = new ArrayList<>();
     List<Block> beginBlocks = beginGroup.blocks;
     List<Block> endBlocks = endGroup.blocks;
     int i = 0;
@@ -180,7 +178,7 @@ final class BlocksGroup {
         c = beginBlock.getIndexInFile() + len - 1 - endBlock.getIndexInFile();
       }
       if (c == 0) {
-        result.add(new Block[] { beginBlock, endBlock });
+        result.add(new Block[] {beginBlock, endBlock});
         i++;
         j++;
       }
index 1ea553dfd41549bbc358ef4f1cb51e47293249bf..4289f084b633180e6ce6b143a9ff4d9ac9ff74ab 100644 (file)
 package org.sonar.duplications.detector.original;
 
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
-
 import org.sonar.duplications.detector.ContainsInComparator;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.ClonePart;
 import org.sonar.duplications.utils.SortedListsUtils;
 
-import com.google.common.collect.Lists;
-
 /**
  * Performs incremental and brute force algorithm in order to filter clones, which are fully covered by other clones.
  * All clones for filtering must be of the same origin - there is no sanity check on this.
@@ -48,7 +46,7 @@ final class Filter {
    * 
    * @see #add(CloneGroup)
    */
-  private final List<CloneGroup> filtered = Lists.newLinkedList();
+  private final List<CloneGroup> filtered = new LinkedList<>();
 
   /**
    * @return current results of filtering
@@ -115,7 +113,7 @@ final class Filter {
     List<ClonePart> firstParts = first.getCloneParts();
     List<ClonePart> secondParts = second.getCloneParts();
     return SortedListsUtils.contains(secondParts, firstParts, new ContainsInComparator(second.getCloneUnitLength(), first.getCloneUnitLength()))
-        && SortedListsUtils.contains(firstParts, secondParts, ContainsInComparator.RESOURCE_ID_COMPARATOR);
+      && SortedListsUtils.contains(firstParts, secondParts, ContainsInComparator.RESOURCE_ID_COMPARATOR);
   }
 
 }
index 0c721b48a3aea350b4671ae911876b7417017232..bfd95e633b69dfea1fe7c8666ca024012cea3f81 100644 (file)
  */
 package org.sonar.duplications.detector.original;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.CloneIndex;
 import org.sonar.duplications.index.ClonePart;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Implementation of algorithm described in paper
  * <a href="http://www4.in.tum.de/~juergens/publications/icsm2010_crc.pdf">Index-Based Code Clone Detection: Incremental, Distributed, Scalable</a>
@@ -69,7 +68,7 @@ public final class OriginalCloneDetectionAlgorithm {
 
     // Godin: create one group per unique hash
     // TODO Godin: can we create map with expected size?
-    Map<ByteArray, BlocksGroup> groupsByHash = Maps.newHashMap();
+    Map<ByteArray, BlocksGroup> groupsByHash = new HashMap<>();
     for (Block fileBlock : fileBlocks) {
       ByteArray hash = fileBlock.getBlockHash();
       BlocksGroup sameHash = groupsByHash.get(hash);
@@ -202,16 +201,16 @@ public final class OriginalCloneDetectionAlgorithm {
     List<Block[]> pairs = beginGroup.pairs(endGroup, cloneLength);
 
     ClonePart origin = null;
-    List<ClonePart> parts = Lists.newArrayList();
+    List<ClonePart> parts = new ArrayList<>();
 
     for (int i = 0; i < pairs.size(); i++) {
       Block[] pair = pairs.get(i);
       Block firstBlock = pair[0];
       Block lastBlock = pair[1];
       ClonePart part = new ClonePart(firstBlock.getResourceId(),
-          firstBlock.getIndexInFile(),
-          firstBlock.getStartLine(),
-          lastBlock.getEndLine());
+        firstBlock.getIndexInFile(),
+        firstBlock.getStartLine(),
+        lastBlock.getEndLine());
 
       if (originResourceId.equals(part.getResourceId())) {
         if (origin == null) {
index a1b4d795fc4d9a9262ba1eb938f9c3f610be7a5b..70f1dce99b94083ceff512d563cb60955eb76a1b 100644 (file)
  */
 package org.sonar.duplications.detector.suffixtree;
 
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.detector.ContainsInComparator;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.ClonePart;
 import org.sonar.duplications.utils.SortedListsUtils;
 
-import java.util.Collections;
-import java.util.List;
-
 /**
  * Implementation of {@link Search.Collector}, which constructs {@link CloneGroup}s.
  */
@@ -37,7 +36,7 @@ public class DuplicationsCollector extends Search.Collector {
   private final TextSet text;
   private final String originResourceId;
 
-  private final List<CloneGroup> filtered = Lists.newArrayList();
+  private final List<CloneGroup> filtered = new ArrayList<>();
 
   private int length;
   private int count;
@@ -66,7 +65,6 @@ public class DuplicationsCollector extends Search.Collector {
    *
    * @param start number of first block from text for this part
    * @param end number of last block from text for this part
-   * @param len number of blocks in this part
    */
   @Override
   public void part(int start, int end) {
@@ -84,15 +82,15 @@ public class DuplicationsCollector extends Search.Collector {
 
     CloneGroup.Builder builder = CloneGroup.builder().setLength(length);
 
-    List<ClonePart> parts = Lists.newArrayListWithCapacity(count);
+    List<ClonePart> parts = new ArrayList<>(count);
     for (int[] b : blockNumbers) {
       Block firstBlock = text.getBlock(b[0]);
       Block lastBlock = text.getBlock(b[1]);
       ClonePart part = new ClonePart(
-          firstBlock.getResourceId(),
-          firstBlock.getIndexInFile(),
-          firstBlock.getStartLine(),
-          lastBlock.getEndLine());
+        firstBlock.getResourceId(),
+        firstBlock.getIndexInFile(),
+        firstBlock.getStartLine(),
+        lastBlock.getEndLine());
 
       // TODO Godin: maybe use FastStringComparator here ?
       if (originResourceId.equals(part.getResourceId())) {
index f010b4dbf01f50c09caae6c82cd25bf07482c4f4..5afde31f2d804375f85bec4d4c7ef1946c491406 100644 (file)
  */
 package org.sonar.duplications.detector.suffixtree;
 
-import com.google.common.collect.Lists;
-
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
 
 public final class Search {
 
@@ -29,8 +33,8 @@ public final class Search {
   private final TextSet text;
   private final Collector reporter;
 
-  private final List<Integer> list = Lists.newArrayList();
-  private final List<Node> innerNodes = Lists.newArrayList();
+  private final List<Integer> list = new ArrayList<>();
+  private final List<Node> innerNodes = new ArrayList<>();
 
   public static void perform(TextSet text, Collector reporter) {
     new Search(SuffixTree.create(text), text, reporter).compute();
@@ -64,7 +68,7 @@ public final class Search {
    * Depth-first search (DFS).
    */
   private void dfs() {
-    Deque<Node> stack = Lists.newLinkedList();
+    Deque<Node> stack = new LinkedList<>();
     stack.add(tree.getRootNode());
     while (!stack.isEmpty()) {
       Node node = stack.removeLast();
index e95bb043b1aca16438386dde549b4cb8055f9e1e..aba733f1d3d43d4d902613551c0d9e1a48f4be1e 100644 (file)
  */
 package org.sonar.duplications.detector.suffixtree;
 
-import java.util.*;
-
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.CloneIndex;
 
-import com.google.common.collect.*;
-
 public final class SuffixTreeCloneDetectionAlgorithm {
 
   public static List<CloneGroup> detect(CloneIndex cloneIndex, Collection<Block> fileBlocks) {
     if (fileBlocks.isEmpty()) {
-      return Collections.EMPTY_LIST;
+      return Collections.emptyList();
     }
     TextSet text = createTextSet(cloneIndex, fileBlocks);
     if (text == null) {
-      return Collections.EMPTY_LIST;
+      return Collections.emptyList();
     }
     DuplicationsCollector reporter = new DuplicationsCollector(text);
     Search.perform(text, reporter);
@@ -47,7 +52,7 @@ public final class SuffixTreeCloneDetectionAlgorithm {
   }
 
   private static TextSet createTextSet(CloneIndex index, Collection<Block> fileBlocks) {
-    Set<ByteArray> hashes = Sets.newHashSet();
+    Set<ByteArray> hashes = new HashSet<>();
     for (Block fileBlock : fileBlocks) {
       hashes.add(fileBlock.getBlockHash());
     }
@@ -66,7 +71,7 @@ public final class SuffixTreeCloneDetectionAlgorithm {
   private static TextSet createTextSet(Collection<Block> fileBlocks, Map<String, List<Block>> fromIndex) {
     TextSet.Builder textSetBuilder = TextSet.builder();
     // TODO Godin: maybe we can reduce size of tree and so memory consumption by removing non-repeatable blocks
-    List<Block> sortedFileBlocks = Lists.newArrayList(fileBlocks);
+    List<Block> sortedFileBlocks = new ArrayList<>(fileBlocks);
     Collections.sort(sortedFileBlocks, BLOCK_COMPARATOR);
     textSetBuilder.add(sortedFileBlocks);
 
@@ -88,7 +93,7 @@ public final class SuffixTreeCloneDetectionAlgorithm {
   }
 
   private static Map<String, List<Block>> retrieveFromIndex(CloneIndex index, String originResourceId, Set<ByteArray> hashes) {
-    Map<String, List<Block>> collection = Maps.newHashMap();
+    Map<String, List<Block>> collection = new HashMap<>();
     for (ByteArray hash : hashes) {
       Collection<Block> blocks = index.getBySequenceHash(hash);
       for (Block blockFromIndex : blocks) {
@@ -97,7 +102,7 @@ public final class SuffixTreeCloneDetectionAlgorithm {
         if (!originResourceId.equals(resourceId)) {
           List<Block> list = collection.get(resourceId);
           if (list == null) {
-            list = Lists.newArrayList();
+            list = new ArrayList<>();
             collection.put(resourceId, list);
           }
           list.add(blockFromIndex);
index 82ab1db55a6633444da71a50e4f45de22f9dd79e..4958bc0502e4a69576e7d119f6f70a49e7ca1614 100644 (file)
  */
 package org.sonar.duplications.detector.suffixtree;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.sonar.duplications.block.Block;
 
-import com.google.common.collect.Lists;
 
 /**
  * Simplifies construction of <a href="http://en.wikipedia.org/wiki/Generalised_suffix_tree">generalised suffix-tree</a>.
@@ -32,7 +32,7 @@ public final class TextSet extends AbstractText {
 
   public static final class Builder {
 
-    private List<Object> symbols = Lists.newArrayList();
+    private List<Object> symbols = new ArrayList();
     private Integer lengthOfOrigin;
     private int count;
 
index 05eab3dd10812652018f01370c0f1ad981a7590f..0fec9682046bf49dfb4980f9c95adb12e0cb082a 100644 (file)
  */
 package org.sonar.duplications.index;
 
-import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-
 import java.util.ArrayList;
 import java.util.List;
 
@@ -104,7 +102,6 @@ public class CloneGroup {
    *
    * @since 2.14
    */
-  @Beta
   public int getLengthInUnits() {
     return length;
   }
index 21a0f890ab0d897ba4f1edeeab339ef5eb09d611..f0257cef0e2bb230c302548ebf02576b01f0658d 100644 (file)
  */
 package org.sonar.duplications.index;
 
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
 import org.sonar.duplications.utils.FastStringComparator;
 
-import java.util.Collection;
-import java.util.List;
-
 /**
  * Provides an index optimized by memory.
  * <p>
@@ -102,7 +101,7 @@ public class PackedMemoryCloneIndex extends AbstractCloneIndex {
 
     int index = DataUtils.binarySearch(byResourceId);
 
-    List<Block> result = Lists.newArrayList();
+    List<Block> result = new ArrayList<>();
     int realIndex = resourceIdsIndex[index];
     while (index < size && FastStringComparator.INSTANCE.compare(resourceIds[realIndex], resourceId) == 0) {
       // extract block (note that there is no need to extract resourceId)
@@ -118,12 +117,12 @@ public class PackedMemoryCloneIndex extends AbstractCloneIndex {
       int endUnit = blockData[offset];
 
       Block block = blockBuilder
-          .setResourceId(resourceId)
-          .setBlockHash(new ByteArray(hash))
-          .setIndexInFile(indexInFile)
-          .setLines(firstLineNumber, lastLineNumber)
-          .setUnit(startUnit, endUnit)
-          .build();
+        .setResourceId(resourceId)
+        .setBlockHash(new ByteArray(hash))
+        .setIndexInFile(indexInFile)
+        .setLines(firstLineNumber, lastLineNumber)
+        .setUnit(startUnit, endUnit)
+        .build();
       result.add(block);
 
       index++;
@@ -151,7 +150,7 @@ public class PackedMemoryCloneIndex extends AbstractCloneIndex {
 
     int index = DataUtils.binarySearch(byBlockHash);
 
-    List<Block> result = Lists.newArrayList();
+    List<Block> result = new ArrayList<>();
     while (index < size && !isLessByHash(size, index)) {
       // extract block (note that there is no need to extract hash)
       String resourceId = resourceIds[index];
@@ -163,12 +162,12 @@ public class PackedMemoryCloneIndex extends AbstractCloneIndex {
       int endUnit = blockData[offset];
 
       Block block = blockBuilder
-          .setResourceId(resourceId)
-          .setBlockHash(sequenceHash)
-          .setIndexInFile(indexInFile)
-          .setLines(firstLineNumber, lastLineNumber)
-          .setUnit(startUnit, endUnit)
-          .build();
+        .setResourceId(resourceId)
+        .setBlockHash(sequenceHash)
+        .setIndexInFile(indexInFile)
+        .setLines(firstLineNumber, lastLineNumber)
+        .setUnit(startUnit, endUnit)
+        .build();
       result.add(block);
       index++;
     }
index 1d32920872162748142c4c2df3961adc8bd93577..20208ed6b8348b7b55395c9ffb73ea4dd9c10569 100644 (file)
  */
 package org.sonar.duplications.internal.pmd;
 
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.List;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
 
-import java.util.List;
-
 /**
  * Differences with {@link org.sonar.duplications.block.BlockChunker}:
  * works with {@link TokensLine},
@@ -51,7 +50,7 @@ public class PmdBlockChunker {
    * @return ArrayList as we need a serializable object
    */
   public List<Block> chunk(String resourceId, List<TokensLine> fragments) {
-    List<TokensLine> filtered = Lists.newArrayList();
+    List<TokensLine> filtered = new ArrayList<>();
     int i = 0;
     while (i < fragments.size()) {
       TokensLine first = fragments.get(i);
@@ -68,10 +67,10 @@ public class PmdBlockChunker {
     fragments = filtered;
 
     if (fragments.size() < blockSize) {
-      return Lists.newArrayList();
+      return new ArrayList<>();
     }
     TokensLine[] fragmentsArr = fragments.toArray(new TokensLine[fragments.size()]);
-    List<Block> blocks = Lists.newArrayListWithCapacity(fragmentsArr.length - blockSize + 1);
+    List<Block> blocks = new ArrayList<>(fragmentsArr.length - blockSize + 1);
     long hash = 0;
     int first = 0;
     int last = 0;