From 250b357941de75db87a2879090d554a355095bd9 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 8 Sep 2016 08:54:57 +0200 Subject: [PATCH] Fix Quality flaws --- .../detector/original/BlocksGroup.java | 2 ++ .../OriginalCloneDetectionAlgorithm.java | 31 ++++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java index 05ba74e0eb2..9fcaf2ebf3d 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java @@ -22,6 +22,7 @@ package org.sonar.duplications.detector.original; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import javax.annotation.CheckForNull; import org.sonar.duplications.block.Block; import org.sonar.duplications.utils.FastStringComparator; @@ -72,6 +73,7 @@ final class BlocksGroup { /** * First block from this group with specified resource id. */ + @CheckForNull public Block first(String resourceId) { for (Block block : blocks) { if (resourceId.equals(block.getResourceId())) { diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java index 655bb1ccbb6..be93463a5e4 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java @@ -38,23 +38,8 @@ import org.sonar.duplications.index.ClonePart; */ public final class OriginalCloneDetectionAlgorithm { - /** - * Performs detection and returns list of clone groups between file (which represented as a collection of blocks) and index. - * Note that this method ignores blocks for this file, that will be retrieved from index. - */ - public static List detect(CloneIndex cloneIndex, Collection fileBlocks) { - if (fileBlocks.isEmpty()) { - return Collections.EMPTY_LIST; - } - OriginalCloneDetectionAlgorithm reporter = new OriginalCloneDetectionAlgorithm(cloneIndex); - reporter.findClones(fileBlocks); - return reporter.filter.getResult(); - } - private final CloneIndex cloneIndex; - private final Filter filter = new Filter(); - private String originResourceId; private OriginalCloneDetectionAlgorithm(CloneIndex cloneIndex) { @@ -213,9 +198,7 @@ public final class OriginalCloneDetectionAlgorithm { lastBlock.getEndLine()); if (originResourceId.equals(part.getResourceId())) { - if (origin == null) { - origin = part; - } else if (part.getUnitStart() < origin.getUnitStart()) { + if (origin == null || part.getUnitStart() < origin.getUnitStart()) { origin = part; } } @@ -226,4 +209,16 @@ public final class OriginalCloneDetectionAlgorithm { filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build()); } + /** + * Performs detection and returns list of clone groups between file (which represented as a collection of blocks) and index. + * Note that this method ignores blocks for this file, that will be retrieved from index. + */ + public static List detect(CloneIndex cloneIndex, Collection fileBlocks) { + if (fileBlocks.isEmpty()) { + return Collections.emptyList(); + } + OriginalCloneDetectionAlgorithm reporter = new OriginalCloneDetectionAlgorithm(cloneIndex); + reporter.findClones(fileBlocks); + return reporter.filter.getResult(); + } } -- 2.39.5