Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf0fe7a2

Browse files
committed
Merge origin/master
2 parents54bf402 +d506d62 commitf0fe7a2

23 files changed

+471
-342
lines changed

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
[![Build Status](https://travis-ci.org/wumpz/java-diff-utils.svg?branch=master)](https://travis-ci.org/wumpz/java-diff-utils)[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7eba77f10bed4c2a8d08ac8dc8da4a86)](https://www.codacy.com/app/wumpz/java-diff-utils?utm_source=github.com&utm_medium=referral&utm_content=wumpz/java-diff-utils&utm_campaign=Badge_Grade)
55
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.wumpz/diffutils/badge.svg)](http://maven-badges.herokuapp.com/maven-central/com.github.wumpz/diffutils)
66

7-
**After a while using it, at least for me, this one seems to be feature complete. If someone finds bugs or has improvement ideas, please file an issue. I wonder why that this project is a zero issue project.**
8-
97

108
##Intro ##
119
Diff Utils library is an OpenSource library for performing the comparison operations between texts: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.
@@ -54,7 +52,11 @@ This is a test ~senctence~**for diffutils**.
5452
But it can easily replaced by any other which is better for handing your texts. I have plan to add implementation of some in future.
5553

5654
###Changelog ###
55+
* Version 3.0-SNAPSHOT
56+
* Due to licensing issues Delta.java and DiffAlgorithm.java were removed.
5757
* Version 2.3-SNAPSHOT
58+
* Introduced a process listener to diff algorithms. For long running
59+
diffs one could implement some progress information.
5860
* automatic module name for JDK 9 and higher usage
5961
* Version 2.2
6062
* released at maven central

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<groupId>com.github.wumpz</groupId>
44
<artifactId>diffutils</artifactId>
55
<packaging>jar</packaging>
6-
<version>2.3-SNAPSHOT</version>
6+
<version>3.0-SNAPSHOT</version>
77
<name>java-diff-utils</name>
88
<description>The DiffUtils library for computing diffs, applying patches, generationg side-by-side view in Java.</description>
99
<url>https://github.com/wumpz/java-diff-utils</url>

‎src/main/java/com/github/difflib/DiffUtils.java‎

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
*/
2020
packagecom.github.difflib;
2121

22-
importcom.github.difflib.algorithm.DiffAlgorithm;
22+
importcom.github.difflib.algorithm.DiffAlgorithmI;
23+
importcom.github.difflib.algorithm.DiffAlgorithmListener;
2324
importcom.github.difflib.algorithm.DiffException;
2425
importcom.github.difflib.algorithm.myers.MyersDiff;
25-
importcom.github.difflib.patch.Delta;
26+
importcom.github.difflib.patch.AbstractDelta;
2627
importcom.github.difflib.patch.Patch;
2728
importcom.github.difflib.patch.PatchFailedException;
2829
importjava.util.ArrayList;
@@ -37,7 +38,6 @@
3738
* Implements the difference and patching engine
3839
*
3940
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
40-
* @version 0.4.1
4141
*/
4242
publicfinalclassDiffUtils {
4343

@@ -46,36 +46,45 @@ public final class DiffUtils {
4646
*
4747
* @param original The original text. Must not be {@code null}.
4848
* @param revised The revised text. Must not be {@code null}.
49+
* @param progress progress listener
4950
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
51+
* @throws com.github.difflib.algorithm.DiffException
5052
*/
53+
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,DiffAlgorithmListenerprogress)throwsDiffException {
54+
returnDiffUtils.diff(original,revised,newMyersDiff<>(),progress);
55+
}
56+
5157
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised)throwsDiffException {
52-
returnDiffUtils.diff(original,revised,newMyersDiff<>());
58+
returnDiffUtils.diff(original,revised,newMyersDiff<>(),null);
5359
}
5460

5561
/**
5662
* Computes the difference between the original and revised text.
5763
*/
58-
publicstaticPatch<String>diff(StringoriginalText,StringrevisedText)throwsDiffException {
59-
returnDiffUtils.diff(Arrays.asList(originalText.split("\n")),Arrays.asList(revisedText.split("\n")));
64+
publicstaticPatch<String>diff(StringsourceText,StringtargetText,
65+
DiffAlgorithmListenerprogress)throwsDiffException {
66+
returnDiffUtils.diff(
67+
Arrays.asList(sourceText.split("\n")),
68+
Arrays.asList(targetText.split("\n")),progress);
6069
}
6170

6271
/**
6372
* Computes the difference between the original and revised list of elements with default diff algorithm
6473
*
65-
* @paramoriginal The original text. Must not be {@code null}.
66-
* @paramrevised The revised text. Must not be {@code null}.
74+
* @paramsource The original text. Must not be {@code null}.
75+
* @paramtarget The revised text. Must not be {@code null}.
6776
*
6877
* @param equalizer the equalizer object to replace the default compare algorithm (Object.equals). If {@code null}
6978
* the default equalizer of the default algorithm is used..
7079
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
7180
*/
72-
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,
81+
publicstatic <T>Patch<T>diff(List<T>source,List<T>target,
7382
BiPredicate<T,T>equalizer)throwsDiffException {
7483
if (equalizer !=null) {
75-
returnDiffUtils.diff(original,revised,
84+
returnDiffUtils.diff(source,target,
7685
newMyersDiff<>(equalizer));
7786
}
78-
returnDiffUtils.diff(original,revised,newMyersDiff<>());
87+
returnDiffUtils.diff(source,target,newMyersDiff<>());
7988
}
8089

8190
/**
@@ -84,16 +93,30 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised,
8493
* @param original The original text. Must not be {@code null}.
8594
* @param revised The revised text. Must not be {@code null}.
8695
* @param algorithm The diff algorithm. Must not be {@code null}.
96+
* @param progress The diff algorithm listener.
8797
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
8898
*/
8999
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,
90-
DiffAlgorithm<T>algorithm)throwsDiffException {
100+
DiffAlgorithmI<T>algorithm,DiffAlgorithmListenerprogress)throwsDiffException {
91101
Objects.requireNonNull(original,"original must not be null");
92102
Objects.requireNonNull(revised,"revised must not be null");
93103
Objects.requireNonNull(algorithm,"algorithm must not be null");
94104

95-
returnPatch.generate(original,revised,algorithm.diff(original,revised));
105+
returnPatch.generate(original,revised,algorithm.computeDiff(original,revised,progress));
96106
}
107+
108+
/**
109+
* Computes the difference between the original and revised list of elements with default diff algorithm
110+
*
111+
* @param original The original text. Must not be {@code null}.
112+
* @param revised The revised text. Must not be {@code null}.
113+
* @param algorithm The diff algorithm. Must not be {@code null}.
114+
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
115+
*/
116+
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,
117+
DiffAlgorithmI<T>algorithm)throwsDiffException {
118+
returndiff(original,revised,algorithm,null);
119+
}
97120

98121
/**
99122
* Computes the difference between the given texts inline. This one uses the "trick" to make out of texts lists of
@@ -113,9 +136,9 @@ public static Patch<String> diffInline(String original, String revised) throws D
113136
revList.add(character.toString());
114137
}
115138
Patch<String>patch =DiffUtils.diff(origList,revList);
116-
for (Delta<String>delta :patch.getDeltas()) {
117-
delta.getOriginal().setLines(compressLines(delta.getOriginal().getLines(),""));
118-
delta.getRevised().setLines(compressLines(delta.getRevised().getLines(),""));
139+
for (AbstractDelta<String>delta :patch.getDeltas()) {
140+
delta.getSource().setLines(compressLines(delta.getSource().getLines(),""));
141+
delta.getTarget().setLines(compressLines(delta.getTarget().getLines(),""));
119142
}
120143
returnpatch;
121144
}

‎src/main/java/com/github/difflib/UnifiedDiffUtils.java‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
importcom.github.difflib.patch.ChangeDelta;
1919
importcom.github.difflib.patch.Chunk;
20-
importcom.github.difflib.patch.Delta;
20+
importcom.github.difflib.patch.AbstractDelta;
2121
importcom.github.difflib.patch.Patch;
2222
importjava.util.ArrayList;
2323
importjava.util.List;
@@ -146,21 +146,21 @@ public static List<String> generateUnifiedDiff(String originalFileName,
146146
ret.add("--- " +originalFileName);
147147
ret.add("+++ " +revisedFileName);
148148

149-
List<Delta<String>>patchDeltas =newArrayList<>(
149+
List<AbstractDelta<String>>patchDeltas =newArrayList<>(
150150
patch.getDeltas());
151151

152152
// code outside the if block also works for single-delta issues.
153-
List<Delta<String>>deltas =newArrayList<>();// current
153+
List<AbstractDelta<String>>deltas =newArrayList<>();// current
154154
// list
155155
// of
156156
// Delta's to
157157
// process
158-
Delta<String>delta =patchDeltas.get(0);
158+
AbstractDelta<String>delta =patchDeltas.get(0);
159159
deltas.add(delta);// add the first Delta to the current set
160160
// if there's more than 1 Delta, we may need to output them together
161161
if (patchDeltas.size() >1) {
162162
for (inti =1;i <patchDeltas.size();i++) {
163-
intposition =delta.getOriginal().getPosition();// store
163+
intposition =delta.getSource().getPosition();// store
164164
// the
165165
// current
166166
// position
@@ -170,9 +170,9 @@ public static List<String> generateUnifiedDiff(String originalFileName,
170170
// Check if the next Delta is too close to the current
171171
// position.
172172
// And if it is, add it to the current set
173-
Delta<String>nextDelta =patchDeltas.get(i);
174-
if ((position +delta.getOriginal().size() +contextSize) >= (nextDelta
175-
.getOriginal().getPosition() -contextSize)) {
173+
AbstractDelta<String>nextDelta =patchDeltas.get(i);
174+
if ((position +delta.getSource().size() +contextSize) >= (nextDelta
175+
.getSource().getPosition() -contextSize)) {
176176
deltas.add(nextDelta);
177177
}else {
178178
// if it isn't, output the current set,
@@ -207,65 +207,65 @@ public static List<String> generateUnifiedDiff(String originalFileName,
207207
* @author Bill James (tankerbay@gmail.com)
208208
*/
209209
privatestaticList<String>processDeltas(List<String>origLines,
210-
List<Delta<String>>deltas,intcontextSize) {
210+
List<AbstractDelta<String>>deltas,intcontextSize) {
211211
List<String>buffer =newArrayList<>();
212212
intorigTotal =0;// counter for total lines output from Original
213213
intrevTotal =0;// counter for total lines output from Original
214214
intline;
215215

216-
Delta<String>curDelta =deltas.get(0);
216+
AbstractDelta<String>curDelta =deltas.get(0);
217217

218218
// NOTE: +1 to overcome the 0-offset Position
219-
intorigStart =curDelta.getOriginal().getPosition() +1 -contextSize;
219+
intorigStart =curDelta.getSource().getPosition() +1 -contextSize;
220220
if (origStart <1) {
221221
origStart =1;
222222
}
223223

224-
intrevStart =curDelta.getRevised().getPosition() +1 -contextSize;
224+
intrevStart =curDelta.getTarget().getPosition() +1 -contextSize;
225225
if (revStart <1) {
226226
revStart =1;
227227
}
228228

229229
// find the start of the wrapper context code
230-
intcontextStart =curDelta.getOriginal().getPosition() -contextSize;
230+
intcontextStart =curDelta.getSource().getPosition() -contextSize;
231231
if (contextStart <0) {
232232
contextStart =0;// clamp to the start of the file
233233
}
234234

235235
// output the context before the first Delta
236-
for (line =contextStart;line <curDelta.getOriginal().getPosition();line++) {//
236+
for (line =contextStart;line <curDelta.getSource().getPosition();line++) {//
237237
buffer.add(" " +origLines.get(line));
238238
origTotal++;
239239
revTotal++;
240240
}
241241

242242
// output the first Delta
243243
buffer.addAll(getDeltaText(curDelta));
244-
origTotal +=curDelta.getOriginal().getLines().size();
245-
revTotal +=curDelta.getRevised().getLines().size();
244+
origTotal +=curDelta.getSource().getLines().size();
245+
revTotal +=curDelta.getTarget().getLines().size();
246246

247247
intdeltaIndex =1;
248248
while (deltaIndex <deltas.size()) {// for each of the other Deltas
249-
Delta<String>nextDelta =deltas.get(deltaIndex);
250-
intintermediateStart =curDelta.getOriginal().getPosition()
251-
+curDelta.getOriginal().getLines().size();
252-
for (line =intermediateStart;line <nextDelta.getOriginal()
249+
AbstractDelta<String>nextDelta =deltas.get(deltaIndex);
250+
intintermediateStart =curDelta.getSource().getPosition()
251+
+curDelta.getSource().getLines().size();
252+
for (line =intermediateStart;line <nextDelta.getSource()
253253
.getPosition();line++) {
254254
// output the code between the last Delta and this one
255255
buffer.add(" " +origLines.get(line));
256256
origTotal++;
257257
revTotal++;
258258
}
259259
buffer.addAll(getDeltaText(nextDelta));// output the Delta
260-
origTotal +=nextDelta.getOriginal().getLines().size();
261-
revTotal +=nextDelta.getRevised().getLines().size();
260+
origTotal +=nextDelta.getSource().getLines().size();
261+
revTotal +=nextDelta.getTarget().getLines().size();
262262
curDelta =nextDelta;
263263
deltaIndex++;
264264
}
265265

266266
// Now output the post-Delta context code, clamping the end of the file
267-
contextStart =curDelta.getOriginal().getPosition()
268-
+curDelta.getOriginal().getLines().size();
267+
contextStart =curDelta.getSource().getPosition()
268+
+curDelta.getSource().getLines().size();
269269
for (line =contextStart; (line < (contextStart +contextSize))
270270
&& (line <origLines.size());line++) {
271271
buffer.add(" " +origLines.get(line));
@@ -275,7 +275,7 @@ private static List<String> processDeltas(List<String> origLines,
275275

276276
// Create and insert the block header, conforming to the Unified Diff
277277
// standard
278-
StringBufferheader =newStringBuffer();
278+
StringBuilderheader =newStringBuilder();
279279
header.append("@@ -");
280280
header.append(origStart);
281281
header.append(",");
@@ -297,12 +297,12 @@ private static List<String> processDeltas(List<String> origLines,
297297
* @return list of String lines of code.
298298
* @author Bill James (tankerbay@gmail.com)
299299
*/
300-
privatestaticList<String>getDeltaText(Delta<String>delta) {
300+
privatestaticList<String>getDeltaText(AbstractDelta<String>delta) {
301301
List<String>buffer =newArrayList<>();
302-
for (Stringline :delta.getOriginal().getLines()) {
302+
for (Stringline :delta.getSource().getLines()) {
303303
buffer.add("-" +line);
304304
}
305-
for (Stringline :delta.getRevised().getLines()) {
305+
for (Stringline :delta.getTarget().getLines()) {
306306
buffer.add("+" +line);
307307
}
308308
returnbuffer;

‎src/main/java/com/github/difflib/algorithm/Change.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/**
2121
*
22-
* @authortoben
22+
* @author<a href="t.warneke@gmx.net">Tobias Warneke</a>
2323
*/
2424
publicclassChange {
2525

‎src/main/java/com/github/difflib/algorithm/DiffAlgorithm.java‎

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp