Skip to content

Commit 1b8cd71

Browse files
committed
first codacy cleanup
1 parent f9440b5 commit 1b8cd71

File tree

8 files changed

+21
-32
lines changed

8 files changed

+21
-32
lines changed

src/main/java/difflib/UnifiedDiffUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
4343
List<String[]> rawChunk = new ArrayList<>();
4444
Patch<String> patch = new Patch<>();
4545

46-
int old_ln = 0, new_ln = 0;
46+
int old_ln = 0;
47+
int new_ln = 0;
4748
String tag;
4849
String rest;
4950
for (String line : diff) {
@@ -64,10 +65,10 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
6465
for (String[] raw_line : rawChunk) {
6566
tag = raw_line[0];
6667
rest = raw_line[1];
67-
if (tag.equals(" ") || tag.equals("-")) {
68+
if (" ".equals(tag) || "-".equals(tag)) {
6869
oldChunkLines.add(rest);
6970
}
70-
if (tag.equals(" ") || tag.equals("+")) {
71+
if (" ".equals(tag) || "+".equals(tag)) {
7172
newChunkLines.add(rest);
7273
}
7374
}
@@ -90,7 +91,7 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
9091
if (line.length() > 0) {
9192
tag = line.substring(0, 1);
9293
rest = line.substring(1);
93-
if (tag.equals(" ") || tag.equals("+") || tag.equals("-")) {
94+
if (" ".equals(tag) || "+".equals(tag) || "-".equals(tag)) {
9495
rawChunk.add(new String[]{tag, rest});
9596
}
9697
} else {

src/main/java/difflib/algorithm/myers/MyersDiff.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,12 @@ private PathNode buildPath(final List<T> orig, final List<T> rev)
183183
* @throws DifferentiationFailedException if a {@link Patch} could not be built from the given
184184
* path.
185185
*/
186-
private Patch<T> buildRevision(PathNode path, List<T> orig, List<T> rev) {
187-
Objects.requireNonNull(path, "path is null");
186+
private Patch<T> buildRevision(PathNode actualPath, List<T> orig, List<T> rev) {
187+
Objects.requireNonNull(actualPath, "path is null");
188188
Objects.requireNonNull(orig, "original sequence is null");
189189
Objects.requireNonNull(rev, "revised sequence is null");
190190

191+
PathNode path = actualPath;
191192
Patch<T> patch = new Patch<>();
192193
if (path.isSnake()) {
193194
path = path.prev;

src/main/java/difflib/patch/Chunk.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ public boolean equals(Object obj) {
147147
} else if (!lines.equals(other.lines)) {
148148
return false;
149149
}
150-
if (position != other.position) {
151-
return false;
152-
}
153-
return true;
150+
return position == other.position;
154151
}
155152

156153
@Override

src/main/java/difflib/text/DiffRowGenerator.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
*/
5252
public class DiffRowGenerator {
5353

54+
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\s+|[,.\\[\\](){}/\\\\*+\\-#]");
5455
private final boolean showInlineDiffs;
5556
private final boolean ignoreWhiteSpaces;
5657
private final Function<Boolean, String> oldTag;
@@ -176,7 +177,7 @@ public static Builder create() {
176177
private DiffRowGenerator(Builder builder) {
177178
showInlineDiffs = builder.showInlineDiffs;
178179
ignoreWhiteSpaces = builder.ignoreWhiteSpaces;
179-
oldTag = builder.oldTag;;
180+
oldTag = builder.oldTag;
180181
newTag = builder.newTag;
181182
columnWidth = builder.columnWidth;
182183
mergeOriginalRevised = builder.mergeOriginalRevised;
@@ -185,10 +186,10 @@ private DiffRowGenerator(Builder builder) {
185186
@Override
186187
public boolean equals(String original, String revised) {
187188
if (ignoreWhiteSpaces) {
188-
original = original.trim().replaceAll("\\s+", " ");
189-
revised = revised.trim().replaceAll("\\s+", " ");
189+
return original.trim().replaceAll("\\s+", " ").equals(revised.trim().replaceAll("\\s+", " "));
190+
} else {
191+
return original.equals(revised);
190192
}
191-
return original.equals(revised);
192193
}
193194
};
194195
}
@@ -386,9 +387,7 @@ public static void wrapInTag(List<String> sequence, int startPosition,
386387
sequence.add(endPosition, generator.apply(false));
387388
}
388389

389-
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\s+|[,.\\[\\](){}/\\\\*+\\-#]");
390-
391-
static List<String> splitStringPreserveDelimiter(String str) {
390+
protected final static List<String> splitStringPreserveDelimiter(String str) {
392391
List<String> list = new ArrayList<>();
393392
if (str != null) {
394393
Matcher matcher = SPLIT_PATTERN.matcher(str);
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
package difflib;
22

3-
import java.io.File;
4-
53
/**
64
* Test constants
75
*
86
* @author simon.mittermueller@gmail.com
97
*
108
*/
119
public final class TestConstants {
12-
13-
private TestConstants() {
14-
// prevent construction.
15-
}
16-
1710
public static final String BASE_FOLDER_RESOURCES = "target/test-classes/";
18-
1911
/**
2012
* The base folder containing the test files. Ends with {@link #FS}.
2113
*/
2214
public static final String MOCK_FOLDER = BASE_FOLDER_RESOURCES + "/mocks/";
2315

16+
private TestConstants() {
17+
}
2418
}

src/test/java/difflib/examples/ApplyPatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
public class ApplyPatch {
1414

15-
static final String ORIGINAL = TestConstants.MOCK_FOLDER + "issue10_base.txt";
16-
static final String PATCH = TestConstants.MOCK_FOLDER + "issue10_patch.txt";
15+
private static final String ORIGINAL = TestConstants.MOCK_FOLDER + "issue10_base.txt";
16+
private static final String PATCH = TestConstants.MOCK_FOLDER + "issue10_patch.txt";
1717

1818
public static void main(String[] args) throws PatchFailedException, IOException {
1919
List<String> original = Files.readAllLines(new File(ORIGINAL).toPath());

src/test/java/difflib/examples/ComputeDifference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
public class ComputeDifference {
1414

15-
static final String ORIGINAL = TestConstants.MOCK_FOLDER + "original.txt";
16-
static final String RIVISED = TestConstants.MOCK_FOLDER + "revised.txt";
15+
private static final String ORIGINAL = TestConstants.MOCK_FOLDER + "original.txt";
16+
private static final String RIVISED = TestConstants.MOCK_FOLDER + "revised.txt";
1717

1818
public static void main(String[] args) throws DiffException, IOException {
1919
List<String> original = Files.readAllLines(new File(ORIGINAL).toPath());

src/test/java/difflib/text/StringUtilsTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
*/
3030
public class StringUtilsTest {
3131

32-
public StringUtilsTest() {
33-
}
34-
3532
@BeforeClass
3633
public static void setUpClass() {
3734
}

0 commit comments

Comments
 (0)