Package org.sonar.duplications.block

Examples of org.sonar.duplications.block.ByteArray


      int endLine = unit.getEndLine();

      // TODO Godin: in fact we could work directly with id instead of key - this will allow to decrease memory consumption
      Block block = Block.builder()
        .setResourceId(resourceKey)
        .setBlockHash(new ByteArray(hash))
        .setIndexInFile(indexInFile)
        .setLines(startLine, endLine)
        .build();

      // Group blocks by hash
View Full Code Here


  public void only_one_query_of_index_for_each_unique_hash() {
    CloneIndex index = spy(createIndex());
    Block[] fileBlocks = newBlocks("a", "1 2 1 2");
    detect(index, fileBlocks);

    verify(index).getBySequenceHash(new ByteArray("01"));
    verify(index).getBySequenceHash(new ByteArray("02"));
    verifyNoMoreInteractions(index);
  }
View Full Code Here

    CloneIndex cloneIndex = createIndex();
    Block.Builder block = Block.builder()
      .setResourceId("a")
      .setLines(0, 1);
    Block[] fileBlocks = new Block[]{
      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);
    assertThat(clones.size(), is(1));
View Full Code Here

  protected static Block[] newBlocks(String resourceId, String hashes) {
    List<Block> result = Lists.newArrayList();
    int indexInFile = 0;
    for (int i = 0; i < hashes.length(); i += 2) {
      Block block = newBlock(resourceId, new ByteArray("0" + hashes.charAt(i)), indexInFile);
      result.add(block);
      indexInFile++;
    }
    return result.toArray(new Block[result.size()]);
  }
View Full Code Here

    Block block = blocks.get(0);
    // assertThat(block.getLengthInUnits(), is(11));
    assertThat(block.getStartLine(), is(1));
    assertThat(block.getEndLine(), is(2));
    assertThat(block.getBlockHash(), is(new ByteArray(1L * 31 + 2)));

    block = blocks.get(1);
    // assertThat(block.getLengthInUnits(), is(33));
    assertThat(block.getStartLine(), is(2));
    assertThat(block.getEndLine(), is(3));
    assertThat(block.getBlockHash(), is(new ByteArray(2L * 31 + 3)));
  }
View Full Code Here

      int startUnit = blockData[offset++];
      int endUnit = blockData[offset];

      Block block = blockBuilder
          .setResourceId(resourceId)
          .setBlockHash(new ByteArray(hash))
          .setIndexInFile(indexInFile)
          .setLines(firstLineNumber, lastLineNumber)
          .setUnit(startUnit, endUnit)
          .build();
      result.add(block);
View Full Code Here

      TokensLine lastFragment = fragmentsArr[last];
      // add last statement to hash
      hash = hash * PRIME_BASE + lastFragment.getHashCode();
      // create block
      Block block = blockBuilder
        .setBlockHash(new ByteArray(hash))
        .setIndexInFile(first)
        .setLines(firstFragment.getStartLine(), lastFragment.getEndLine())
        .setUnit(firstFragment.getStartUnit(), lastFragment.getEndUnit())
        .build();
      blocks.add(block);
View Full Code Here

    index.insert(newBlock("d", 1));
    index.insert(newBlock("e", 1));
    index.insert(newBlock("e", 2));
    index.insert(newBlock("e", 3));

    assertThat(index.getBySequenceHash(new ByteArray(1L)).size(), is(5));
    assertThat(index.getBySequenceHash(new ByteArray(2L)).size(), is(2));
    assertThat(index.getBySequenceHash(new ByteArray(3L)).size(), is(1));
    assertThat(index.getBySequenceHash(new ByteArray(4L)).size(), is(0));
    assertThat(index.getByResourceId("a").size(), is(2));
    assertThat(index.getByResourceId("b").size(), is(1));
    assertThat(index.getByResourceId("e").size(), is(3));
    assertThat(index.getByResourceId("does not exist").size(), is(0));
  }
View Full Code Here

  @Test
  public void should_construct_blocks_with_normalized_hash() {
    index.insert(newBlock("a", 1));
    index.insert(newBlock("b", 1));
    index.insert(newBlock("c", 1));
    ByteArray requestedHash = new ByteArray(1L);
    Collection<Block> blocks = index.getBySequenceHash(requestedHash);
    assertThat(blocks.size(), is(3));
    for (Block block : blocks) {
      assertThat(block.getBlockHash(), sameInstance(requestedHash));
    }
View Full Code Here

   * Expected: exception during search by 8-byte hash.
   */
  @Test(expected = IllegalArgumentException.class)
  public void attempt_to_find_hash_of_incorrect_size() {
    CloneIndex index = new PackedMemoryCloneIndex(4, 1);
    index.getBySequenceHash(new ByteArray(1L));
  }
View Full Code Here

TOP

Related Classes of org.sonar.duplications.block.ByteArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.