GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Extract duplicate code into method. (#58) · fgsoap/java-diff-utils@81085d3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java-diff-utils/src/main/java/com/github/difflib
    • UnifiedDiffUtils.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java
+11-24Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,7 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
5959
Matcher m = UNIFIED_DIFF_CHUNK_REGEXP.matcher(line);
6060
if (m.find()) {
6161
// Process the lines in the previous chunk
62-
if (!rawChunk.isEmpty()) {
63-
List<String> oldChunkLines = new ArrayList<>();
64-
List<String> newChunkLines = new ArrayList<>();
65-
66-
for (String[] raw_line : rawChunk) {
67-
tag = raw_line[0];
68-
rest = raw_line[1];
69-
if (" ".equals(tag) || "-".equals(tag)) {
70-
oldChunkLines.add(rest);
71-
}
72-
if (" ".equals(tag) || "+".equals(tag)) {
73-
newChunkLines.add(rest);
74-
}
75-
}
76-
patch.addDelta(new ChangeDelta<>(new Chunk<>(
77-
old_ln - 1, oldChunkLines), new Chunk<>(
78-
new_ln - 1, newChunkLines)));
79-
rawChunk.clear();
80-
}
62+
processLinesInPrevChunk(rawChunk, patch, old_ln, new_ln);
8163
// Parse the @@ header
8264
old_ln = m.group(1) == null ? 1 : Integer.parseInt(m.group(1));
8365
new_ln = m.group(3) == null ? 1 : Integer.parseInt(m.group(3));
@@ -102,6 +84,14 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
10284
}
10385

10486
// Process the lines in the last chunk
87+
processLinesInPrevChunk(rawChunk, patch, old_ln, new_ln);
88+
89+
return patch;
90+
}
91+
92+
private static void processLinesInPrevChunk(List<String[]> rawChunk, Patch<String> patch, int old_ln, int new_ln) {
93+
String tag;
94+
String rest;
10595
if (!rawChunk.isEmpty()) {
10696
List<String> oldChunkLines = new ArrayList<>();
10797
List<String> newChunkLines = new ArrayList<>();
@@ -116,14 +106,11 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
116106
newChunkLines.add(rest);
117107
}
118108
}
119-
120109
patch.addDelta(new ChangeDelta<>(new Chunk<>(
121-
old_ln - 1, oldChunkLines), new Chunk<>(new_ln - 1,
122-
newChunkLines)));
110+
old_ln - 1, oldChunkLines), new Chunk<>(
111+
new_ln - 1, newChunkLines)));
123112
rawChunk.clear();
124113
}
125-
126-
return patch;
127114
}
128115

129116
/**

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.