Package org.sonar.duplications.block

Examples of org.sonar.duplications.block.ByteArray


  }

  private static Block newBlock(String resourceId, long hash) {
    return Block.builder()
        .setResourceId(resourceId)
        .setBlockHash(new ByteArray(hash))
        .setIndexInFile(1)
        .setLines(1, 2)
        .build();
  }
View Full Code Here


  @Test
  public void huge() {
    CloneIndex index = createIndex();
    Block[] fileBlocks = new Block[5000];
    for (int i = 0; i < 5000; i++) {
      fileBlocks[i] = newBlock("x", new ByteArray("01"), i);
    }
    List<CloneGroup> result = detect(index, fileBlocks);

    assertEquals(1, result.size());
  }
View Full Code Here

    // Godin: create one group per unique hash
    // TODO Godin: can we create map with expected size?
    Map<ByteArray, BlocksGroup> groupsByHash = Maps.newHashMap();
    for (Block fileBlock : fileBlocks) {
      ByteArray hash = fileBlock.getBlockHash();
      BlocksGroup sameHash = groupsByHash.get(hash);
      if (sameHash == null) {
        sameHash = BlocksGroup.empty();
        groupsByHash.put(hash, sameHash);
      }
      sameHash.blocks.add(fileBlock);
    }

    // Godin: retrieve blocks from index
    for (Map.Entry<ByteArray, BlocksGroup> entry : groupsByHash.entrySet()) {
      ByteArray hash = entry.getKey();
      BlocksGroup group = entry.getValue();
      for (Block blockFromIndex : cloneIndex.getBySequenceHash(hash)) {
        // Godin: skip blocks for this file if they come from index
        if (!originResourceId.equals(blockFromIndex.getResourceId())) {
          group.blocks.add(blockFromIndex);
        }
      }
      Collections.sort(group.blocks, BlocksGroup.BlockComparator.INSTANCE);
    }

    // 3: let c be a list with c(0) = empty
    BlocksGroup[] sameHashBlocksGroups = new BlocksGroup[size + 2];
    sameHashBlocksGroups[0] = BlocksGroup.empty();
    // 4: for i := 1 to length(f) do
    for (Block fileBlock : fileBlocks) {
      ByteArray hash = fileBlock.getBlockHash();
      int i = fileBlock.getIndexInFile() + 1;
      // 5: retrieve tuples with same sequence hash as f(i)
      // 6: store this set as c(i)
      sameHashBlocksGroups[i] = groupsByHash.get(hash);
    }
View Full Code Here

    int count = value.getInt();
    List<Block> blocks = new ArrayList<Block>(count);
    for (int i = 0; i < count; i++) {
      Block.Builder b = Block.builder();
      b.setResourceId(resourceId);
      b.setBlockHash(new ByteArray(value.getByteArray()));
      b.setIndexInFile(value.getInt());
      int startLine = value.getInt();
      int endLine = value.getInt();
      b.setLines(startLine, endLine);
      int startUnit = value.getInt();
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.