]> source.dussan.org Git - sonarqube.git/commitdiff
Remove deprecated and unused code
authorEvgeny Mandrikov <mandrikov@gmail.com>
Sun, 12 Feb 2012 16:44:41 +0000 (20:44 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 13 Feb 2012 07:42:13 +0000 (11:42 +0400)
sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java
sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex2.java [deleted file]
sonar-duplications/src/test/java/org/sonar/duplications/block/BlockTest.java
sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java
sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java
sonar-duplications/src/test/java/org/sonar/duplications/index/MemoryCloneIndexTest.java [deleted file]
sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java

index 822454db2050d85d4704002eeccd5416c6654e57..e618a3c161432cf343b8cca1650bb2ca64b3a839 100644 (file)
@@ -113,18 +113,6 @@ public final class Block implements CodeFragment {
     this.endUnit = builder.endUnit;
   }
 
-  /**
-   * @deprecated since 2.14 use {@link #builder()}
-   */
-  @Deprecated
-  public Block(String resourceId, ByteArray blockHash, int indexInFile, int startLine, int endLine) {
-    this.resourceId = resourceId;
-    this.blockHash = blockHash;
-    this.indexInFile = indexInFile;
-    this.startLine = startLine;
-    this.endLine = endLine;
-  }
-
   public String getHashHex() {
     return getBlockHash().toString();
   }
index afefdef5c07ede7496ab04e7f4e369d63007d0ad..84f3633f5f65bf3bd18f49cbc7a108a550ff039b 100644 (file)
@@ -147,7 +147,7 @@ public final class OriginalCloneDetectionAlgorithm {
       // stored in a0. Clones are only reported, if tuples are lost in
       // Line 12, as otherwise all current clones could be prolonged
       // by one statement. Clone reporting matches tuples that, after
-      // correction of the statement index, appear in both c(i) and a;
+      // correction of the statement index, appear in both c(i) and a,
       // each matched pair corresponds to a single clone. Its location
       // can be extracted from the filename and info fields.
 
index cd7f520120b8b3a4ce6d70c7ff5788e4a13037cf..64377a4955df0cdc7958ea831ef7d32f300d3280 100644 (file)
  */
 package org.sonar.duplications.index;
 
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Comparator;
-
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
 
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.TreeMultimap;
+import java.util.Collection;
 
 public class MemoryCloneIndex implements CloneIndex {
 
-  private final TreeMultimap<String, Block> filenameIndex;
-  private final HashMultimap<ByteArray, Block> sequenceHashIndex;
-
-  private static final class ValueComparator implements Comparator<Block>, Serializable {
-
-    private static final long serialVersionUID = 6048010242032502222L;
-
-    public int compare(Block o1, Block o2) {
-      if (o2.getResourceId().equals(o1.getResourceId())) {
-        return o1.getIndexInFile() - o2.getIndexInFile();
-      }
-      return o1.getResourceId().compareTo(o2.getResourceId());
-    }
-  }
-
-  private static final class KeyComparator implements Comparator<String>, Serializable {
-
-    private static final long serialVersionUID = 8705841881237170539L;
-
-    public int compare(String o1, String o2) {
-      return o1.compareTo(o2);
-    }
-  }
-
-  public MemoryCloneIndex() {
-    filenameIndex = TreeMultimap.create(new KeyComparator(), new ValueComparator());
-    sequenceHashIndex = HashMultimap.create();
-  }
-
-  public Collection<String> getAllUniqueResourceId() {
-    return filenameIndex.keySet();
-  }
-
-  public boolean containsResourceId(String resourceId) {
-    return filenameIndex.containsKey(resourceId);
-  }
+  private Multimap<String, Block> byResource = ArrayListMultimap.create();
+  private Multimap<ByteArray, Block> byHash = ArrayListMultimap.create();
 
-  public Collection<Block> getByResourceId(String fileName) {
-    return filenameIndex.get(fileName);
+  public Collection<Block> getByResourceId(String resourceId) {
+    return byResource.get(resourceId);
   }
 
   public Collection<Block> getBySequenceHash(ByteArray sequenceHash) {
-    return sequenceHashIndex.get(sequenceHash);
+    return byHash.get(sequenceHash);
   }
 
-  public void insert(Block tuple) {
-    filenameIndex.put(tuple.getResourceId(), tuple);
-    sequenceHashIndex.put(tuple.getBlockHash(), tuple);
+  public void insert(Block block) {
+    byResource.put(block.getResourceId(), block);
+    byHash.put(block.getBlockHash(), block);
   }
 
 }
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex2.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex2.java
deleted file mode 100644 (file)
index 324a5e1..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.duplications.index;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.sonar.duplications.block.Block;
-import org.sonar.duplications.block.ByteArray;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-public class MemoryCloneIndex2 extends AbstractCloneIndex {
-
-  private Map<String, List<Block>> byResource = Maps.newHashMap();
-  private Map<ByteArray, List<Block>> byHash = Maps.newHashMap();
-
-  public Collection<Block> getByResourceId(String resourceId) {
-    return get(byResource, resourceId);
-  }
-
-  public Collection<Block> getBySequenceHash(ByteArray sequenceHash) {
-    return get(byHash, sequenceHash);
-  }
-
-  public void insert(Block block) {
-    put(byResource, block.getResourceId(), block);
-    put(byHash, block.getBlockHash(), block);
-  }
-
-  private static <T> List<Block> get(Map<T, List<Block>> map, T key) {
-    List<Block> blocks = map.get(key);
-    return blocks != null ? blocks : Collections.EMPTY_LIST;
-  }
-
-  private static <T> void put(Map<T, List<Block>> map, T key, Block value) {
-    List<Block> blocks = map.get(key);
-    if (blocks == null) {
-      blocks = Lists.newLinkedList();
-      map.put(key, blocks);
-    }
-    blocks.add(value);
-  }
-
-}
index fd86e55c699a199d50c599516b713cc26e632d54..71477b0c6eb2028fd1d3cac4124b9196d0033966 100644 (file)
@@ -21,8 +21,9 @@ package org.sonar.duplications.block;
 
 import org.junit.Test;
 
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertThat;
 
 public class BlockTest {
 
@@ -48,55 +49,4 @@ public class BlockTest {
     assertThat(block.getEndUnit(), is(5));
   }
 
-  @Test
-  public void fieldsTest() {
-    String fileName = "someFile";
-    int statementIndex = 4;
-    ByteArray hash = new ByteArray(12345);
-    Block tuple = new Block(fileName, hash, statementIndex, 0, 10);
-    assertThat(tuple.getResourceId(), equalTo(fileName));
-    assertThat(tuple.getIndexInFile(), equalTo(statementIndex));
-    assertEquals(tuple.getBlockHash(), hash);
-  }
-
-  @Test
-  public void tupleEqualsTest() {
-    Block tuple1 = new Block("somefile", new ByteArray(123), 1, 1, 10);
-    Block tuple2 = new Block("somefile", new ByteArray(123), 1, 1, 10);
-    Block tupleArr = new Block("somefile", new ByteArray(333), 1, 1, 10);
-    Block tupleIndex = new Block("somefile", new ByteArray(123), 2, 1, 10);
-    Block tupleName = new Block("other", new ByteArray(123), 1, 1, 10);
-
-    assertTrue(tuple1.equals(tuple2));
-    assertThat(tuple1.toString(), is(tuple2.toString()));
-
-    assertFalse(tuple1.equals(tupleArr));
-    assertThat(tuple1.toString(), not(equalTo(tupleArr.toString())));
-
-    assertFalse(tuple1.equals(tupleIndex));
-    assertThat(tuple1.toString(), not(equalTo(tupleIndex.toString())));
-
-    assertFalse(tuple1.equals(tupleName));
-    assertThat(tuple1.toString(), not(equalTo(tupleName.toString())));
-  }
-
-  @Test
-  public void hashCodeTest() {
-    String[] files = {"file1", "file2"};
-    int[] unitIndexes = {1, 2};
-    ByteArray[] arrays = {new ByteArray(123), new ByteArray(321)};
-
-    // fileName is in hashCode()
-    int defaultTupleHashCode = new Block(files[0], arrays[0], unitIndexes[0], 1, 10).hashCode();
-    int fileNameTupleHashCode = new Block(files[1], arrays[0], unitIndexes[0], 1, 10).hashCode();
-    assertThat(defaultTupleHashCode, not(equalTo(fileNameTupleHashCode)));
-
-    // statementIndex is in hashCode()
-    int indexTupleHashCode = new Block(files[0], arrays[0], unitIndexes[1], 1, 10).hashCode();
-    assertThat(defaultTupleHashCode, not(equalTo(indexTupleHashCode)));
-
-    // sequenceHash is in hashCode()
-    int sequenceHashTupleHashCode = new Block(files[0], arrays[1], unitIndexes[0], 1, 10).hashCode();
-    assertThat(defaultTupleHashCode, not(equalTo(sequenceHashTupleHashCode)));
-  }
 }
index 3ce2f6a70f963d0c2049dde8fcdd9512d612ef10..7a216b12c95d8e84e93a2fd5735082345b26b666 100644 (file)
  */
 package org.sonar.duplications.detector;
 
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
-
-import java.util.*;
-
+import com.google.common.collect.Lists;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.duplications.block.Block;
@@ -41,7 +30,13 @@ import org.sonar.duplications.index.ClonePart;
 import org.sonar.duplications.index.MemoryCloneIndex;
 import org.sonar.duplications.junit.TestNamePrinter;
 
-import com.google.common.collect.Lists;
+import java.util.*;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.*;
+import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
 
 public abstract class DetectorTestCase {
 
@@ -55,7 +50,12 @@ public abstract class DetectorTestCase {
    * so we can simply use index and hash.
    */
   protected static Block newBlock(String resourceId, ByteArray hash, int index) {
-    return new Block(resourceId, hash, index, index, index + LINES_PER_BLOCK);
+    return Block.builder()
+        .setResourceId(resourceId)
+        .setBlockHash(hash)
+        .setIndexInFile(index)
+        .setLines(index, index + LINES_PER_BLOCK)
+        .build();
   }
 
   protected static ClonePart newClonePart(String resourceId, int unitStart, int cloneUnitLength) {
@@ -390,10 +390,13 @@ public abstract class DetectorTestCase {
   @Test
   public void same_lines_but_different_indexes() {
     CloneIndex cloneIndex = createIndex();
+    Block.Builder block = Block.builder()
+        .setResourceId("a")
+        .setLines(0, 1);
     List<Block> fileBlocks = Arrays.asList(
-        new Block("a", new ByteArray("1".getBytes()), 0, 0, 1),
-        new Block("a", new ByteArray("2".getBytes()), 1, 0, 1),
-        new Block("a", new ByteArray("1".getBytes()), 2, 0, 1));
+        block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(),
+        block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(),
+        block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build());
     List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
 
     print(clones);
index 536456c7a2d6c2a480a3d9e09fd9a6e95e66048b..e2476d411469db30167c74b499c16bbf5f2e403d 100644 (file)
  */
 package org.sonar.duplications.detector.original;
 
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
 import org.junit.Test;
 import org.sonar.duplications.block.Block;
 
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
 public class BlocksGroupTest {
 
   /**
    * {@link BlocksGroup} uses only resourceId and index from block, thus we can simplify testing.
    */
   private static Block newBlock(String resourceId, int indexInFile) {
-    return new Block(resourceId, null, indexInFile, indexInFile, indexInFile);
+    return Block.builder()
+        .setResourceId(resourceId)
+        .setIndexInFile(indexInFile)
+        .setLines(indexInFile, indexInFile)
+        .build();
   }
 
   public static BlocksGroup newBlocksGroup(Block... blocks) {
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/index/MemoryCloneIndexTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/index/MemoryCloneIndexTest.java
deleted file mode 100644 (file)
index a2996cf..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.duplications.index;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collection;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.duplications.block.Block;
-import org.sonar.duplications.block.ByteArray;
-
-public class MemoryCloneIndexTest {
-
-  private CloneIndex cloneIndex;
-
-  @Before
-  public void initialize() {
-    cloneIndex = new MemoryCloneIndex();
-  }
-
-  @Test
-  public void byFileName() {
-    Block tuple1 = new Block("a", new ByteArray(0), 0, 0, 10);
-    Block tuple2 = new Block("a", new ByteArray(0), 1, 10, 20);
-
-    assertThat(cloneIndex.getByResourceId("a").size(), is(0));
-
-    cloneIndex.insert(tuple1);
-    assertThat(cloneIndex.getByResourceId("a").size(), is(1));
-
-    cloneIndex.insert(tuple2);
-    assertThat(cloneIndex.getByResourceId("a").size(), is(2));
-  }
-
-  @Test
-  public void bySequenceHash() {
-    Block tuple1 = new Block("a", new ByteArray(0), 0, 0, 5);
-    Block tuple2 = new Block("a", new ByteArray(0), 1, 1, 6);
-
-    assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(0));
-
-    cloneIndex.insert(tuple1);
-    assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(1));
-
-    cloneIndex.insert(tuple2);
-    assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(2));
-  }
-
-  @Test
-  public void insertSame() {
-    Block tuple = new Block("a", new ByteArray(0), 0, 0, 5);
-    Block tupleSame = new Block("a", new ByteArray(0), 0, 0, 5);
-
-    assertThat(cloneIndex.getByResourceId("a").size(), is(0));
-    assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(0));
-
-    cloneIndex.insert(tuple);
-    assertThat(cloneIndex.getByResourceId("a").size(), is(1));
-    assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(1));
-
-    cloneIndex.insert(tupleSame);
-    assertThat(cloneIndex.getByResourceId("a").size(), is(1));
-    assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(1));
-  }
-
-  @Test
-  public void testSorted() {
-    for (int i = 0; i < 10; i++) {
-      cloneIndex.insert(new Block("a", new ByteArray(1), 10 - i, i, i + 5));
-    }
-    assertThat(cloneIndex.getByResourceId("a").size(), is(10));
-    assertThat(cloneIndex.getBySequenceHash(new ByteArray(1)).size(), is(10));
-
-    Collection<Block> set = cloneIndex.getByResourceId("a");
-    int prevStatementIndex = 0;
-    for (Block tuple : set) {
-      assertTrue(tuple.getIndexInFile() > prevStatementIndex);
-      prevStatementIndex = tuple.getIndexInFile();
-    }
-  }
-}
index c47a2be3cfe425647082e02b0cb538bc22f58c51..e99c3b42b4ade510012b22b859a7a4c8d0c767d6 100644 (file)
  */
 package org.sonar.duplications.index;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertThat;
-
-import java.util.Collection;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
 
+import java.util.Collection;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertThat;
+
 public class PackedMemoryCloneIndexTest {
 
   private PackedMemoryCloneIndex index;
@@ -110,7 +110,12 @@ public class PackedMemoryCloneIndexTest {
   }
 
   private static Block newBlock(String resourceId, long hash) {
-    return new Block(resourceId, new ByteArray(hash), 1, 1, 1);
+    return Block.builder()
+        .setResourceId(resourceId)
+        .setBlockHash(new ByteArray(hash))
+        .setIndexInFile(1)
+        .setLines(1, 2)
+        .build();
   }
 
 }