org.sonar.duplications.block.Block.getResourceId()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中org.sonar.duplications.block.Block.getResourceId()方法的一些代码示例,展示了Block.getResourceId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getResourceId()方法的具体详情如下:
包路径:org.sonar.duplications.block.Block
类名称:Block
方法名:getResourceId

Block.getResourceId介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

/**
 * First block from this group with specified resource id.
 */
@CheckForNull
public Block first(String resourceId) {
 for (Block block : blocks) {
  if (resourceId.equals(block.getResourceId())) {
   return block;
  }
 }
 return null;
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public int compare(Block b1, Block b2) {
 int c = RESOURCE_ID_COMPARATOR.compare(b1.getResourceId(), b2.getResourceId());
 if (c == 0) {
  return b1.getIndexInFile() - b2.getIndexInFile();
 }
 return c;
}

代码示例来源:origin: SonarSource/sonarqube

public DuplicationsCollector(TextSet text) {
 this.text = text;
 this.originResourceId = text.getBlock(0).getResourceId();
}

代码示例来源:origin: SonarSource/sonarqube

private static TextSet createTextSet(CloneIndex index, Collection<Block> fileBlocks) {
 Set<ByteArray> hashes = new HashSet<>();
 for (Block fileBlock : fileBlocks) {
  hashes.add(fileBlock.getBlockHash());
 }
 String originResourceId = fileBlocks.iterator().next().getResourceId();
 Map<String, List<Block>> fromIndex = retrieveFromIndex(index, originResourceId, hashes);
 if (fromIndex.isEmpty() && hashes.size() == fileBlocks.size()) {
  // optimization for the case when there is no duplications
  return null;
 }
 return createTextSet(fileBlocks, fromIndex);
}

代码示例来源:origin: SonarSource/sonarqube

private static Map<String, List<Block>> retrieveFromIndex(CloneIndex index, String originResourceId, Set<ByteArray> hashes) {
 Map<String, List<Block>> collection = new HashMap<>();
 for (ByteArray hash : hashes) {
  Collection<Block> blocks = index.getBySequenceHash(hash);
  for (Block blockFromIndex : blocks) {
   // Godin: skip blocks for this file if they come from index
   String resourceId = blockFromIndex.getResourceId();
   if (!originResourceId.equals(resourceId)) {
    List<Block> list = collection.get(resourceId);
    if (list == null) {
     list = new ArrayList<>();
     collection.put(resourceId, list);
    }
    list.add(blockFromIndex);
   }
  }
 }
 return collection;
}

代码示例来源:origin: SonarSource/sonarqube

private static List<Block[]> pairs(BlocksGroup beginGroup, BlocksGroup endGroup, int len) {
 List<Block[]> result = new ArrayList<>();
 List<Block> beginBlocks = beginGroup.blocks;
 List<Block> endBlocks = endGroup.blocks;
 int i = 0;
 int j = 0;
 while (i < beginBlocks.size() && j < endBlocks.size()) {
  Block beginBlock = beginBlocks.get(i);
  Block endBlock = endBlocks.get(j);
  int c = RESOURCE_ID_COMPARATOR.compare(beginBlock.getResourceId(), endBlock.getResourceId());
  if (c == 0) {
   c = beginBlock.getIndexInFile() + len - 1 - endBlock.getIndexInFile();
  }
  if (c == 0) {
   result.add(new Block[] {beginBlock, endBlock});
   i++;
   j++;
  }
  if (c > 0) {
   j++;
  }
  if (c < 0) {
   i++;
  }
 }
 return result;
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public void insert(Block block) {
 getByResourceId(block.getResourceId()).add(block);
 getBySequenceHash(block.getBlockHash()).add(block);
}

代码示例来源:origin: SonarSource/sonarqube

Block block1 = list1.get(i);
Block block2 = list2.get(j);
int c = RESOURCE_ID_COMPARATOR.compare(block1.getResourceId(), block2.getResourceId());
if (c != 0) {
 j++;

代码示例来源:origin: SonarSource/sonarqube

Block block1 = list1.get(i);
Block block2 = list2.get(j);
int c = RESOURCE_ID_COMPARATOR.compare(block1.getResourceId(), block2.getResourceId());
if (c > 0) {
 j++;

代码示例来源:origin: SonarSource/sonarqube

for (Block blockFromIndex : cloneIndex.getBySequenceHash(hash)) {
 if (!originResourceId.equals(blockFromIndex.getResourceId())) {
  group.blocks.add(blockFromIndex);

代码示例来源:origin: SonarSource/sonarqube

private void reportClones(BlocksGroup beginGroup, BlocksGroup endGroup, int cloneLength) {
 List<Block[]> pairs = beginGroup.pairs(endGroup, cloneLength);
 ClonePart origin = null;
 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());
  if (originResourceId.equals(part.getResourceId())) {
   if (origin == null || part.getUnitStart() < origin.getUnitStart()) {
    origin = part;
   }
  }
  parts.add(part);
 }
 filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build());
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * {@inheritDoc}
 * <p>
 * <strong>Note that this implementation allows insertion of two blocks with same index for one resource.</strong>
 * </p>
 */
@Override
public void insert(Block block) {
 sorted = false;
 ensureCapacity();
 resourceIds[size] = block.getResourceId();
 int[] hash = block.getBlockHash().toIntArray();
 if (hash.length != hashInts) {
  throw new IllegalArgumentException("Expected " + hashInts + " ints in hash, but got " + hash.length);
 }
 int offset = size * blockInts;
 for (int i = 0; i < hashInts; i++) {
  blockData[offset++] = hash[i];
 }
 blockData[offset++] = block.getIndexInFile();
 blockData[offset++] = block.getStartLine();
 blockData[offset++] = block.getEndLine();
 blockData[offset++] = block.getStartUnit();
 blockData[offset] = block.getEndUnit();
 size++;
}

代码示例来源:origin: SonarSource/sonarqube

Block lastBlock = text.getBlock(b[1]);
ClonePart part = new ClonePart(
 firstBlock.getResourceId(),
 firstBlock.getIndexInFile(),
 firstBlock.getStartLine(),

代码示例来源:origin: SonarSource/sonarqube

private void findClones(Collection<Block> fileBlocks) {
 originResourceId = fileBlocks.iterator().next().getResourceId();

代码示例来源:origin: SonarSource/sonarqube

@Test
public void testBuilder() {
 ByteArray hash = new ByteArray(1);
 Block block = Block.builder()
   .setResourceId("resource")
   .setBlockHash(hash)
   .setIndexInFile(1)
   .setLines(2, 3)
   .setUnit(4, 5)
   .build();
 assertThat(block.getResourceId(), is("resource"));
 assertThat(block.getBlockHash(), sameInstance(hash));
 assertThat(block.getIndexInFile(), is(1));
 assertThat(block.getStartLine(), is(2));
 assertThat(block.getEndLine(), is(3));
 assertThat(block.getStartUnit(), is(4));
 assertThat(block.getEndUnit(), is(5));
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

/**
 * First block from this group with specified resource id.
 */
public Block first(String resourceId) {
 for (Block block : blocks) {
  if (resourceId.equals(block.getResourceId())) {
   return block;
  }
 }
 return null;
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

@Override
public int compare(Block b1, Block b2) {
 int c = RESOURCE_ID_COMPARATOR.compare(b1.getResourceId(), b2.getResourceId());
 if (c == 0) {
  return b1.getIndexInFile() - b2.getIndexInFile();
 }
 return c;
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

@Override
public void insert(Block block) {
 byResource.put(block.getResourceId(), block);
 byHash.put(block.getBlockHash(), block);
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

public DuplicationsCollector(TextSet text) {
 this.text = text;
 this.originResourceId = text.getBlock(0).getResourceId();
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

private static TextSet createTextSet(CloneIndex index, Collection<Block> fileBlocks) {
 Set<ByteArray> hashes = Sets.newHashSet();
 for (Block fileBlock : fileBlocks) {
  hashes.add(fileBlock.getBlockHash());
 }
 String originResourceId = fileBlocks.iterator().next().getResourceId();
 Map<String, List<Block>> fromIndex = retrieveFromIndex(index, originResourceId, hashes);
 if (fromIndex.isEmpty() && hashes.size() == fileBlocks.size()) {
  // optimization for the case when there is no duplications
  return null;
 }
 return createTextSet(fileBlocks, fromIndex);
}

相关文章