Skip to content

Commit c6a87a8

Browse files
Cleanup code
1 parent b117553 commit c6a87a8

File tree

13 files changed

+36
-48
lines changed

13 files changed

+36
-48
lines changed

java-diff-utils-jgit/src/test/java/com/github/difflib/algorithm/jgit/LRHistogramDiffTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.io.IOException;
2727
import java.io.InputStream;
2828
import java.io.InputStreamReader;
29-
import java.nio.charset.Charset;
3029
import java.nio.charset.StandardCharsets;
3130
import java.util.ArrayList;
3231
import java.util.List;
@@ -75,8 +74,7 @@ public void diffEnd() {
7574
}
7675

7776
public static List<String> readStringListFromInputStream(InputStream is) throws IOException {
78-
try (BufferedReader reader =
79-
new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())))) {
77+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
8078

8179
return reader.lines().collect(toList());
8280
}

java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,7 @@ private static void insertOrig(List<List<String>> diffList, List<String> result,
428428

429429
// Insert the unchanged content in the source file into result
430430
private static void insert(List<String> result, List<String> noChangeContent) {
431-
for (String ins : noChangeContent) {
432-
result.add(ins);
433-
}
431+
result.addAll(noChangeContent);
434432
}
435433

436434
// Parse the line containing @@ to get the modified line number to delete or add a few lines

java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/PathNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public boolean isBootstrap() {
7979
*
8080
* @return The next first {@link PathNode} or bootstrap node in the path, or <code>null</code> if none found.
8181
*/
82-
public final PathNode previousSnake() {
82+
public PathNode previousSnake() {
8383
if (isBootstrap()) {
8484
return null;
8585
}

java-diff-utils/src/main/java/com/github/difflib/patch/Chunk.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public VerifyChunk verifyChunk(List<T> target) throws PatchFailedException {
107107
* @param position the position of target
108108
* @throws com.github.difflib.patch.PatchFailedException
109109
*/
110-
public VerifyChunk verifyChunk(List<T> target, int fuzz, int position) throws PatchFailedException {
110+
public VerifyChunk verifyChunk(List<T> target, int fuzz, int position) {
111111
//noinspection UnnecessaryLocalVariable
112112
int startIndex = fuzz;
113113
int lastIndex = size() - fuzz;

java-diff-utils/src/main/java/com/github/difflib/patch/ConflictOutput.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@
2929
@FunctionalInterface
3030
public interface ConflictOutput<T> extends Serializable {
3131

32-
public void processConflict(VerifyChunk verifyChunk, AbstractDelta<T> delta, List<T> result)
33-
throws PatchFailedException;
32+
void processConflict(VerifyChunk verifyChunk, AbstractDelta<T> delta, List<T> result) throws PatchFailedException;
3433
}

java-diff-utils/src/main/java/com/github/difflib/text/DiffRowGenerator.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static String adjustWhitespace(String raw) {
9898
return WHITESPACE_PATTERN.matcher(raw.trim()).replaceAll(" ");
9999
}
100100

101-
protected static final List<String> splitStringPreserveDelimiter(String str, Pattern SPLIT_PATTERN) {
101+
protected static List<String> splitStringPreserveDelimiter(String str, Pattern SPLIT_PATTERN) {
102102
List<String> list = new ArrayList<>();
103103
if (str != null) {
104104
Matcher matcher = SPLIT_PATTERN.matcher(str);
@@ -374,9 +374,7 @@ private DiffRow buildDiffRowWithoutNormalizing(Tag type, String orgline, String
374374
}
375375

376376
List<String> normalizeLines(List<String> list) {
377-
return reportLinesUnchanged
378-
? list
379-
: list.stream().map(lineNormalizer::apply).collect(toList());
377+
return reportLinesUnchanged ? list : list.stream().map(lineNormalizer).collect(toList());
380378
}
381379

382380
/**

java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private boolean processLine(String line, UnifiedDiffLine... rules) throws Unifie
241241
}
242242
for (UnifiedDiffLine rule : rules) {
243243
if (rule.processLine(line)) {
244-
LOG.fine(" >>> processed rule " + rule.toString());
244+
LOG.fine(" >>> processed rule " + rule);
245245
return true;
246246
}
247247
}
@@ -256,7 +256,7 @@ private boolean validLine(String line, UnifiedDiffLine... rules) {
256256
}
257257
for (UnifiedDiffLine rule : rules) {
258258
if (rule.validLine(line)) {
259-
LOG.fine(" >>> accepted rule " + rule.toString());
259+
LOG.fine(" >>> accepted rule " + rule);
260260
return true;
261261
}
262262
}

java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffWriter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ private static void processDeltas(
198198
// Create and insert the block header, conforming to the Unified Diff
199199
// standard
200200
writer.accept("@@ -" + origStart + "," + origTotal + " +" + revStart + "," + revTotal + " @@");
201-
buffer.forEach(txt -> {
202-
writer.accept(txt);
203-
});
201+
buffer.forEach(writer);
204202
}
205203

206204
/**

java-diff-utils/src/test/java/com/github/difflib/DiffUtilsTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.io.IOException;
1818
import java.io.InputStream;
1919
import java.io.InputStreamReader;
20-
import java.nio.charset.Charset;
2120
import java.nio.charset.StandardCharsets;
2221
import java.nio.file.Files;
2322
import java.nio.file.Paths;
@@ -154,8 +153,7 @@ public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOExcept
154153
}
155154

156155
public static List<String> readStringListFromInputStream(InputStream is) throws IOException {
157-
try (BufferedReader reader =
158-
new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())))) {
156+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
159157

160158
return reader.lines().collect(toList());
161159
}

java-diff-utils/src/test/java/com/github/difflib/text/DiffRowGeneratorTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.github.difflib.text.deltamerge.InlineDeltaMergeInfo;
1414
import java.io.File;
1515
import java.io.IOException;
16-
import java.net.URISyntaxException;
1716
import java.nio.file.FileSystem;
1817
import java.nio.file.FileSystems;
1918
import java.nio.file.Files;
@@ -878,9 +877,9 @@ private void assertInlineDiffResult(DiffRowGenerator generator, String original,
878877
}
879878

880879
@Test
881-
public void testIssue188HangOnExamples() throws IOException, URISyntaxException {
880+
public void testIssue188HangOnExamples() throws IOException {
882881
try (FileSystem zipFs = FileSystems.newFileSystem(
883-
Paths.get("target/test-classes/com/github/difflib/text/test.zip"), (ClassLoader) null); ) {
882+
Paths.get("target/test-classes/com/github/difflib/text/test.zip"), (ClassLoader) null)) {
884883
List<String> original = Files.readAllLines(zipFs.getPath("old.html"));
885884
List<String> revised = Files.readAllLines(zipFs.getPath("new.html"));
886885

0 commit comments

Comments
 (0)