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

Commit02532a9

Browse files
authored
Update JavaDoc for DiffUtils class (#163)
1 parent9f88cf9 commit02532a9

File tree

1 file changed

+73
-46
lines changed

1 file changed

+73
-46
lines changed

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

Lines changed: 73 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
importjava.util.function.BiPredicate;
3131

3232
/**
33-
*Implementsthe difference and patching engine
33+
*Utility class to implementthe difference and patching engine.
3434
*/
3535
publicfinalclassDiffUtils {
3636

@@ -39,38 +39,63 @@ public final class DiffUtils {
3939
*/
4040
staticDiffAlgorithmFactoryDEFAULT_DIFF =MyersDiff.factory();
4141

42+
/**
43+
* Sets the default diff algorithm factory to be used by all diff routines.
44+
*
45+
* @param factory a {@link DiffAlgorithmFactory} represnting the new default diff algorithm factory.
46+
*/
4247
publicstaticvoidwithDefaultDiffAlgorithmFactory(DiffAlgorithmFactoryfactory) {
4348
DEFAULT_DIFF =factory;
4449
}
4550

4651
/**
47-
* Computes the difference between the original and revised list of elements
48-
* with default diff algorithm
52+
* Computes the difference between two sequences of elements using the default diff algorithm.
4953
*
50-
* @param <T> types to be diffed
51-
* @param original The original text. Must not be {@code null}.
52-
* @param revised The revised text. Must not be {@code null}.
53-
* @param progress progress listener
54-
* @return The patch describing the difference between the original and
55-
* revised sequences. Never {@code null}.
54+
* @param <T> a generic representing the type of the elements to be compared.
55+
* @param original a {@link List} represnting the original sequence of elements. Must not be {@code null}.
56+
* @param revised a {@link List} represnting the revised sequence of elements. Must not be {@code null}.
57+
* @param progress a {@link DiffAlgorithmListener} represnting the progress listener. Can be {@code null}.
58+
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
5659
*/
5760
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,DiffAlgorithmListenerprogress) {
5861
returnDiffUtils.diff(original,revised,DEFAULT_DIFF.create(),progress);
5962
}
6063

64+
/**
65+
* Computes the difference between two sequences of elements using the default diff algorithm.
66+
*
67+
* @param <T> a generic representing the type of the elements to be compared.
68+
* @param original a {@link List} represnting the original sequence of elements. Must not be {@code null}.
69+
* @param revised a {@link List} represnting the revised sequence of elements. Must not be {@code null}.
70+
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
71+
*/
6172
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised) {
6273
returnDiffUtils.diff(original,revised,DEFAULT_DIFF.create(),null);
6374
}
6475

76+
/**
77+
* Computes the difference between two sequences of elements using the default diff algorithm.
78+
*
79+
* @param <T> a generic representing the type of the elements to be compared.
80+
* @param original a {@link List} represnting the original sequence of elements. Must not be {@code null}.
81+
* @param revised a {@link List} represnting the revised sequence of elements. Must not be {@code null}.
82+
* @param includeEqualParts a {@link boolean} represnting whether to include equal parts in the resulting patch.
83+
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
84+
*/
6585
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,booleanincludeEqualParts) {
6686
returnDiffUtils.diff(original,revised,DEFAULT_DIFF.create(),null,includeEqualParts);
6787
}
6888

6989
/**
70-
* Computes the difference between the original and revised text.
90+
* Computes the difference between two strings using the default diff algorithm.
91+
*
92+
* @param sourceText a {@link String} represnting the original string. Must not be {@code null}.
93+
* @param targetText a {@link String} represnting the revised string. Must not be {@code null}.
94+
* @param progress a {@link DiffAlgorithmListener} represnting the progress listener. Can be {@code null}.
95+
* @return The patch describing the difference between the original and revised strings. Never {@code null}.
7196
*/
7297
publicstaticPatch<String>diff(StringsourceText,StringtargetText,
73-
DiffAlgorithmListenerprogress) {
98+
DiffAlgorithmListenerprogress) {
7499
returnDiffUtils.diff(
75100
Arrays.asList(sourceText.split("\n")),
76101
Arrays.asList(targetText.split("\n")),progress);
@@ -80,17 +105,16 @@ public static Patch<String> diff(String sourceText, String targetText,
80105
* Computes the difference between the original and revised list of elements
81106
* with default diff algorithm
82107
*
83-
* @param source The original text. Must not be {@code null}.
84-
* @param target The revised text. Must not be {@code null}.
85-
*
86-
* @param equalizer the equalizer object to replace the default compare
108+
* @param source a {@link List} represnting the original text. Must not be {@code null}.
109+
* @param target a {@link List} represnting the revised text. Must not be {@code null}.
110+
* @param equalizer a {@link BiPredicate} represnting the equalizer object to replace the default compare
87111
* algorithm (Object.equals). If {@code null} the default equalizer of the
88-
* default algorithm is used..
112+
* default algorithm is used.
89113
* @return The patch describing the difference between the original and
90114
* revised sequences. Never {@code null}.
91115
*/
92116
publicstatic <T>Patch<T>diff(List<T>source,List<T>target,
93-
BiPredicate<T,T>equalizer) {
117+
BiPredicate<T,T>equalizer) {
94118
if (equalizer !=null) {
95119
returnDiffUtils.diff(source,target,
96120
DEFAULT_DIFF.create(equalizer));
@@ -99,39 +123,40 @@ public static <T> Patch<T> diff(List<T> source, List<T> target,
99123
}
100124

101125
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,
102-
DiffAlgorithmI<T>algorithm,DiffAlgorithmListenerprogress) {
126+
DiffAlgorithmI<T>algorithm,DiffAlgorithmListenerprogress) {
103127
returndiff(original,revised,algorithm,progress,false);
104128
}
105129

106130
/**
107131
* Computes the difference between the original and revised list of elements
108132
* with default diff algorithm
109133
*
110-
* @param originalThe original text. Must not be {@code null}.
111-
* @param revisedThe revised text. Must not be {@code null}.
112-
* @param algorithmThe diff algorithm. Must not be {@code null}.
113-
* @param progressThe diff algorithm listener.
134+
* @param originala {@link List} represnting the original text. Must not be {@code null}.
135+
* @param reviseda {@link List} represnting the revised text. Must not be {@code null}.
136+
* @param algorithma {@link DiffAlgorithmI} represnting the diff algorithm. Must not be {@code null}.
137+
* @param progressa {@link DiffAlgorithmListener} represnting the diff algorithm listener.
114138
* @param includeEqualParts Include equal data parts into the patch.
115139
* @return The patch describing the difference between the original and
116140
* revised sequences. Never {@code null}.
117141
*/
118142
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,
119-
DiffAlgorithmI<T>algorithm,DiffAlgorithmListenerprogress,
120-
booleanincludeEqualParts) {
143+
DiffAlgorithmI<T>algorithm,DiffAlgorithmListenerprogress,
144+
booleanincludeEqualParts) {
121145
Objects.requireNonNull(original,"original must not be null");
122146
Objects.requireNonNull(revised,"revised must not be null");
123147
Objects.requireNonNull(algorithm,"algorithm must not be null");
124148

125149
returnPatch.generate(original,revised,algorithm.computeDiff(original,revised,progress),includeEqualParts);
126150
}
127151

152+
128153
/**
129154
* Computes the difference between the original and revised list of elements
130155
* with default diff algorithm
131156
*
132-
* @param originalThe original text. Must not be {@code null}.
133-
* @param revisedThe revised text. Must not be {@code null}.
134-
* @param algorithmThe diff algorithm. Must not be {@code null}.
157+
* @param originala {@link List} represnting the original text. Must not be {@code null}.
158+
* @param reviseda {@link List} represnting the revised text. Must not be {@code null}.
159+
* @param algorithma {@link DiffAlgorithmI} represnting the diff algorithm. Must not be {@code null}.
135160
* @return The patch describing the difference between the original and
136161
* revised sequences. Never {@code null}.
137162
*/
@@ -144,9 +169,10 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithm
144169
* "trick" to make out of texts lists of characters, like DiffRowGenerator
145170
* does and merges those changes at the end together again.
146171
*
147-
* @param original
148-
* @param revised
149-
* @return
172+
* @param original a {@link String} represnting the original text. Must not be {@code null}.
173+
* @param revised a {@link String} represnting the revised text. Must not be {@code null}.
174+
* @return The patch describing the difference between the original and
175+
* revised sequences. Never {@code null}.
150176
*/
151177
publicstaticPatch<String>diffInline(Stringoriginal,Stringrevised) {
152178
List<String>origList =newArrayList<>();
@@ -165,37 +191,38 @@ public static Patch<String> diffInline(String original, String revised) {
165191
returnpatch;
166192
}
167193

168-
privatestaticList<String>compressLines(List<String>lines,Stringdelimiter) {
169-
if (lines.isEmpty()) {
170-
returnCollections.emptyList();
171-
}
172-
returnCollections.singletonList(String.join(delimiter,lines));
173-
}
174-
175194
/**
176-
*Patch the originaltext with given patch
195+
*Applies thegiven patch to theoriginallist and returns the revised list.
177196
*
178-
* @param original the originaltext
179-
* @param patchthe givenpatch
180-
* @return the revisedtext
181-
* @throws PatchFailedException ifcan't applypatch
197+
* @param originala {@link List} represntingthe originallist.
198+
* @param patcha {@link List} represnting thepatch to apply.
199+
* @return the revisedlist.
200+
* @throws PatchFailedException ifthepatch cannot be applied.
182201
*/
183202
publicstatic <T>List<T>patch(List<T>original,Patch<T>patch)
184203
throwsPatchFailedException {
185204
returnpatch.applyTo(original);
186205
}
187206

188207
/**
189-
*Unpatch the revisedtext for a given patch
208+
*Applies thegiven patch to therevisedlist and returns the original list.
190209
*
191-
* @param revised the revised text
192-
* @param patch the given patch
193-
* @return the original text
210+
* @param revised a {@link List} represnting the revised list.
211+
* @param patch a {@link Patch} represnting the patch to apply.
212+
* @return the original list.
213+
* @throws PatchFailedException if the patch cannot be applied.
194214
*/
195215
publicstatic <T>List<T>unpatch(List<T>revised,Patch<T>patch) {
196216
returnpatch.restore(revised);
197217
}
198218

219+
privatestaticList<String>compressLines(List<String>lines,Stringdelimiter) {
220+
if (lines.isEmpty()) {
221+
returnCollections.emptyList();
222+
}
223+
returnCollections.singletonList(String.join(delimiter,lines));
224+
}
225+
199226
privateDiffUtils() {
200227
}
201228
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp