HashedSequence<StringText> hashedSource = HashedSequence.wrap(new StringText(source), StringTextComparator.IGNORE_WHITESPACE);
HashedSequenceComparator<StringText> hashedComparator = new HashedSequenceComparator<StringText>(StringTextComparator.IGNORE_WHITESPACE);
- ViolationTrackingBlocksRecognizer rec = new ViolationTrackingBlocksRecognizer(hashedReference, hashedSource, hashedComparator);
+ IssueTrackingBlocksRecognizer rec = new IssueTrackingBlocksRecognizer(hashedReference, hashedSource, hashedComparator);
Multimap<Integer, DefaultIssue> newIssuesByLines = newIssuesByLines(newIssues, rec, result);
Multimap<Integer, IssueDto> lastIssuesByLines = lastIssuesByLines(result.unmatched(), rec);
}
}
- private Multimap<Integer, DefaultIssue> newIssuesByLines(Collection<DefaultIssue> newIssues, ViolationTrackingBlocksRecognizer rec, IssueTrackingResult result) {
+ private Multimap<Integer, DefaultIssue> newIssuesByLines(Collection<DefaultIssue> newIssues, IssueTrackingBlocksRecognizer rec, IssueTrackingResult result) {
Multimap<Integer, DefaultIssue> newIssuesByLines = LinkedHashMultimap.create();
for (DefaultIssue newIssue : newIssues) {
if (isNotAlreadyMapped(newIssue, result) && rec.isValidLineInSource(newIssue.line())) {
return newIssuesByLines;
}
- private Multimap<Integer, IssueDto> lastIssuesByLines(Collection<IssueDto> lastIssues, ViolationTrackingBlocksRecognizer rec) {
+ private Multimap<Integer, IssueDto> lastIssuesByLines(Collection<IssueDto> lastIssues, IssueTrackingBlocksRecognizer rec) {
Multimap<Integer, IssueDto> lastIssuesByLines = LinkedHashMultimap.create();
for (IssueDto pastIssue : lastIssues) {
if (rec.isValidLineInReference(pastIssue.getLine())) {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.plugins.core.issue.tracking;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.sonar.plugins.core.issue.tracking.HashedSequence;
+import org.sonar.plugins.core.issue.tracking.HashedSequenceComparator;
+import org.sonar.plugins.core.issue.tracking.StringText;
+import org.sonar.plugins.core.issue.tracking.StringTextComparator;
+
+import javax.annotation.Nullable;
+
+public class IssueTrackingBlocksRecognizer {
+
+ private final HashedSequence<StringText> a;
+ private final HashedSequence<StringText> b;
+ private final HashedSequenceComparator<StringText> cmp;
+
+ @VisibleForTesting
+ public IssueTrackingBlocksRecognizer(String referenceSource, String source) {
+ this.a = HashedSequence.wrap(new StringText(referenceSource), StringTextComparator.IGNORE_WHITESPACE);
+ this.b = HashedSequence.wrap(new StringText(source), StringTextComparator.IGNORE_WHITESPACE);
+ this.cmp = new HashedSequenceComparator<StringText>(StringTextComparator.IGNORE_WHITESPACE);
+ }
+
+ public IssueTrackingBlocksRecognizer(HashedSequence<StringText> a, HashedSequence<StringText> b, HashedSequenceComparator<StringText> cmp) {
+ this.a = a;
+ this.b = b;
+ this.cmp = cmp;
+ }
+
+ public boolean isValidLineInReference(@Nullable Integer line) {
+ return (line != null) && (0 <= line - 1) && (line - 1 < a.length());
+ }
+
+ public boolean isValidLineInSource(@Nullable Integer line) {
+ return (line != null) && (0 <= line - 1) && (line - 1 < b.length());
+ }
+
+ /**
+ * @param startA number of line from first version of text (numbering starts from 0)
+ * @param startB number of line from second version of text (numbering starts from 0)
+ */
+ public int computeLengthOfMaximalBlock(int startA, int startB) {
+ if (!cmp.equals(a, startA, b, startB)) {
+ return 0;
+ }
+ int length = 0;
+ int ai = startA;
+ int bi = startB;
+ while (ai < a.length() && bi < b.length() && cmp.equals(a, ai, b, bi)) {
+ ai++;
+ bi++;
+ length++;
+ }
+ ai = startA;
+ bi = startB;
+ while (ai >= 0 && bi >= 0 && cmp.equals(a, ai, b, bi)) {
+ ai--;
+ bi--;
+ length++;
+ }
+ // Note that position (startA, startB) was counted twice
+ return length - 1;
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.plugins.core.issue.tracking;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.sonar.plugins.core.issue.tracking.HashedSequence;
-import org.sonar.plugins.core.issue.tracking.HashedSequenceComparator;
-import org.sonar.plugins.core.issue.tracking.StringText;
-import org.sonar.plugins.core.issue.tracking.StringTextComparator;
-
-import javax.annotation.Nullable;
-
-public class ViolationTrackingBlocksRecognizer {
-
- private final HashedSequence<StringText> a;
- private final HashedSequence<StringText> b;
- private final HashedSequenceComparator<StringText> cmp;
-
- @VisibleForTesting
- public ViolationTrackingBlocksRecognizer(String referenceSource, String source) {
- this.a = HashedSequence.wrap(new StringText(referenceSource), StringTextComparator.IGNORE_WHITESPACE);
- this.b = HashedSequence.wrap(new StringText(source), StringTextComparator.IGNORE_WHITESPACE);
- this.cmp = new HashedSequenceComparator<StringText>(StringTextComparator.IGNORE_WHITESPACE);
- }
-
- public ViolationTrackingBlocksRecognizer(HashedSequence<StringText> a, HashedSequence<StringText> b, HashedSequenceComparator<StringText> cmp) {
- this.a = a;
- this.b = b;
- this.cmp = cmp;
- }
-
- public boolean isValidLineInReference(@Nullable Integer line) {
- return (line != null) && (0 <= line - 1) && (line - 1 < a.length());
- }
-
- public boolean isValidLineInSource(@Nullable Integer line) {
- return (line != null) && (0 <= line - 1) && (line - 1 < b.length());
- }
-
- /**
- * @param startA number of line from first version of text (numbering starts from 0)
- * @param startB number of line from second version of text (numbering starts from 0)
- */
- public int computeLengthOfMaximalBlock(int startA, int startB) {
- if (!cmp.equals(a, startA, b, startB)) {
- return 0;
- }
- int length = 0;
- int ai = startA;
- int bi = startB;
- while (ai < a.length() && bi < b.length() && cmp.equals(a, ai, b, bi)) {
- ai++;
- bi++;
- length++;
- }
- ai = startA;
- bi = startB;
- while (ai >= 0 && bi >= 0 && cmp.equals(a, ai, b, bi)) {
- ai--;
- bi--;
- length++;
- }
- // Note that position (startA, startB) was counted twice
- return length - 1;
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.plugins.core.issue.tracking;
+
+import org.junit.Test;
+import org.sonar.plugins.core.issue.tracking.IssueTrackingBlocksRecognizer;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueTrackingBlocksRecognizerTest {
+
+ @Test
+ public void test() {
+ assertThat(compute(t("abcde"), t("abcde"), 3, 3)).isEqualTo(5);
+ assertThat(compute(t("abcde"), t("abcd"), 3, 3)).isEqualTo(4);
+ assertThat(compute(t("bcde"), t("abcde"), 3, 3)).isEqualTo(0);
+ assertThat(compute(t("bcde"), t("abcde"), 2, 3)).isEqualTo(4);
+ }
+
+ private static int compute(String a, String b, int ai, int bi) {
+ IssueTrackingBlocksRecognizer rec = new IssueTrackingBlocksRecognizer(a, b);
+ return rec.computeLengthOfMaximalBlock(ai, bi);
+ }
+
+ private static String t(String text) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < text.length(); i++) {
+ sb.append(text.charAt(i)).append('\n');
+ }
+ return sb.toString();
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.plugins.core.issue.tracking;
-
-import org.junit.Test;
-import org.sonar.plugins.core.issue.tracking.ViolationTrackingBlocksRecognizer;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class ViolationTrackingBlocksRecognizerTest {
-
- @Test
- public void test() {
- assertThat(compute(t("abcde"), t("abcde"), 3, 3)).isEqualTo(5);
- assertThat(compute(t("abcde"), t("abcd"), 3, 3)).isEqualTo(4);
- assertThat(compute(t("bcde"), t("abcde"), 3, 3)).isEqualTo(0);
- assertThat(compute(t("bcde"), t("abcde"), 2, 3)).isEqualTo(4);
- }
-
- private static int compute(String a, String b, int ai, int bi) {
- ViolationTrackingBlocksRecognizer rec = new ViolationTrackingBlocksRecognizer(a, b);
- return rec.computeLengthOfMaximalBlock(ai, bi);
- }
-
- private static String t(String text) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < text.length(); i++) {
- sb.append(text.charAt(i)).append('\n');
- }
- return sb.toString();
- }
-
-}