Skip to content

Commit 6770358

Browse files
author
Andreas Goss
committed
Adjust generic parameters for PECS principle.
Spotless update
1 parent b117553 commit 6770358

File tree

9 files changed

+66
-56
lines changed

9 files changed

+66
-56
lines changed

java-diff-utils-jgit/src/main/java/com/github/difflib/algorithm/jgit/HistogramDiff.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
public class HistogramDiff<T> implements DiffAlgorithmI<T> {
3737

3838
@Override
39-
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) {
39+
public List<Change> computeDiff(
40+
List<? extends T> source, List<? extends T> target, DiffAlgorithmListener progress) {
4041
Objects.requireNonNull(source, "source list must not be null");
4142
Objects.requireNonNull(target, "target list must not be null");
4243
if (progress != null) {
@@ -92,9 +93,9 @@ public int hash(DataList<T> s, int i) {
9293

9394
class DataList<T> extends Sequence {
9495

95-
final List<T> data;
96+
final List<? extends T> data;
9697

97-
public DataList(List<T> data) {
98+
public DataList(List<? extends T> data) {
9899
this.data = data;
99100
}
100101

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory)
5757
* @param progress a {@link DiffAlgorithmListener} representing the progress listener. Can be {@code null}.
5858
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
5959
*/
60-
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmListener progress) {
60+
public static <T> Patch<T> diff(
61+
List<? extends T> original, List<? extends T> revised, DiffAlgorithmListener progress) {
6162
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), progress);
6263
}
6364

@@ -69,7 +70,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithm
6970
* @param revised a {@link List} representing the revised sequence of elements. Must not be {@code null}.
7071
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
7172
*/
72-
public static <T> Patch<T> diff(List<T> original, List<T> revised) {
73+
public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> revised) {
7374
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null);
7475
}
7576

@@ -82,7 +83,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised) {
8283
* @param includeEqualParts a {@link boolean} representing whether to include equal parts in the resulting patch.
8384
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
8485
*/
85-
public static <T> Patch<T> diff(List<T> original, List<T> revised, boolean includeEqualParts) {
86+
public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> revised, boolean includeEqualParts) {
8687
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null, includeEqualParts);
8788
}
8889

@@ -110,15 +111,19 @@ public static Patch<String> diff(String sourceText, String targetText, DiffAlgor
110111
* @return The patch describing the difference between the original and
111112
* revised sequences. Never {@code null}.
112113
*/
113-
public static <T> Patch<T> diff(List<T> source, List<T> target, BiPredicate<T, T> equalizer) {
114+
public static <T> Patch<T> diff(
115+
List<? extends T> source, List<? extends T> target, BiPredicate<? super T, ? super T> equalizer) {
114116
if (equalizer != null) {
115117
return DiffUtils.diff(source, target, DEFAULT_DIFF.create(equalizer));
116118
}
117119
return DiffUtils.diff(source, target, new MyersDiff<>());
118120
}
119121

120122
public static <T> Patch<T> diff(
121-
List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) {
123+
List<? extends T> original,
124+
List<? extends T> revised,
125+
DiffAlgorithmI<T> algorithm,
126+
DiffAlgorithmListener progress) {
122127
return diff(original, revised, algorithm, progress, false);
123128
}
124129

@@ -135,8 +140,8 @@ public static <T> Patch<T> diff(
135140
* revised sequences. Never {@code null}.
136141
*/
137142
public static <T> Patch<T> diff(
138-
List<T> original,
139-
List<T> revised,
143+
List<? extends T> original,
144+
List<? extends T> revised,
140145
DiffAlgorithmI<T> algorithm,
141146
DiffAlgorithmListener progress,
142147
boolean includeEqualParts) {
@@ -157,7 +162,8 @@ public static <T> Patch<T> diff(
157162
* @return The patch describing the difference between the original and
158163
* revised sequences. Never {@code null}.
159164
*/
160-
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm) {
165+
public static <T> Patch<T> diff(
166+
List<? extends T> original, List<? extends T> revised, DiffAlgorithmI<T> algorithm) {
161167
return diff(original, revised, algorithm, null);
162168
}
163169

@@ -196,7 +202,7 @@ public static Patch<String> diffInline(String original, String revised) {
196202
* @return the revised list.
197203
* @throws PatchFailedException if the patch cannot be applied.
198204
*/
199-
public static <T> List<T> patch(List<T> original, Patch<T> patch) throws PatchFailedException {
205+
public static <T> List<T> patch(List<? extends T> original, Patch<T> patch) throws PatchFailedException {
200206
return patch.applyTo(original);
201207
}
202208

@@ -208,7 +214,7 @@ public static <T> List<T> patch(List<T> original, Patch<T> patch) throws PatchFa
208214
* @return the original list.
209215
* @throws PatchFailedException if the patch cannot be applied.
210216
*/
211-
public static <T> List<T> unpatch(List<T> revised, Patch<T> patch) {
217+
public static <T> List<T> unpatch(List<? extends T> revised, Patch<T> patch) {
212218
return patch.restore(revised);
213219
}
214220

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
public interface DiffAlgorithmFactory {
2626
<T> DiffAlgorithmI<T> create();
2727

28-
<T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer);
28+
<T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer);
2929
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface DiffAlgorithmI<T> {
3434
* @param progress progress listener
3535
* @return
3636
*/
37-
List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress);
37+
List<Change> computeDiff(List<? extends T> source, List<? extends T> target, DiffAlgorithmListener progress);
3838

3939
/**
4040
* Simple extension to compute a changeset using arrays.

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
*/
3232
public final class MyersDiff<T> implements DiffAlgorithmI<T> {
3333

34-
private final BiPredicate<T, T> equalizer;
34+
private final BiPredicate<? super T, ? super T> equalizer;
3535

3636
public MyersDiff() {
3737
equalizer = Object::equals;
3838
}
3939

40-
public MyersDiff(final BiPredicate<T, T> equalizer) {
40+
public MyersDiff(final BiPredicate<? super T, ? super T> equalizer) {
4141
Objects.requireNonNull(equalizer, "equalizer must not be null");
4242
this.equalizer = equalizer;
4343
}
@@ -48,7 +48,8 @@ public MyersDiff(final BiPredicate<T, T> equalizer) {
4848
* Return empty diff if get the error while procession the difference.
4949
*/
5050
@Override
51-
public List<Change> computeDiff(final List<T> source, final List<T> target, DiffAlgorithmListener progress) {
51+
public List<Change> computeDiff(
52+
final List<? extends T> source, final List<? extends T> target, DiffAlgorithmListener progress) {
5253
Objects.requireNonNull(source, "source list must not be null");
5354
Objects.requireNonNull(target, "target list must not be null");
5455

@@ -71,9 +72,10 @@ public List<Change> computeDiff(final List<T> source, final List<T> target, Diff
7172
* @param orig The original sequence.
7273
* @param rev The revised sequence.
7374
* @return A minimum {@link PathNode Path} accross the differences graph.
74-
* @throws DifferentiationFailedException if a diff path could not be found.
75+
* @throws IllegalStateException if a diff path could not be found.
7576
*/
76-
private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmListener progress) {
77+
private PathNode buildPath(
78+
final List<? extends T> orig, final List<? extends T> rev, DiffAlgorithmListener progress) {
7779
Objects.requireNonNull(orig, "original sequence is null");
7880
Objects.requireNonNull(rev, "revised sequence is null");
7981

@@ -140,10 +142,10 @@ private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmL
140142
* @param orig The original sequence.
141143
* @param rev The revised sequence.
142144
* @return A {@link Patch} script corresponding to the path.
143-
* @throws DifferentiationFailedException if a {@link Patch} could not be
145+
* @throws IllegalStateException if a {@link Patch} could not be
144146
* built from the given path.
145147
*/
146-
private List<Change> buildRevision(PathNode actualPath, List<T> orig, List<T> rev) {
148+
private List<Change> buildRevision(PathNode actualPath, List<? extends T> orig, List<? extends T> rev) {
147149
Objects.requireNonNull(actualPath, "path is null");
148150
Objects.requireNonNull(orig, "original sequence is null");
149151
Objects.requireNonNull(rev, "revised sequence is null");
@@ -190,7 +192,7 @@ public <T> DiffAlgorithmI<T> create() {
190192
}
191193

192194
@Override
193-
public <T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer) {
195+
public <T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer) {
194196
return new MyersDiff<>(equalizer);
195197
}
196198
};

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@
3232
*/
3333
public class MyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> {
3434

35-
private final BiPredicate<T, T> equalizer;
35+
private final BiPredicate<? super T, ? super T> equalizer;
3636

3737
public MyersDiffWithLinearSpace() {
3838
equalizer = Object::equals;
3939
}
4040

41-
public MyersDiffWithLinearSpace(final BiPredicate<T, T> equalizer) {
41+
public MyersDiffWithLinearSpace(final BiPredicate<? super T, ? super T> equalizer) {
4242
Objects.requireNonNull(equalizer, "equalizer must not be null");
4343
this.equalizer = equalizer;
4444
}
4545

4646
@Override
47-
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) {
47+
public List<Change> computeDiff(
48+
List<? extends T> source, List<? extends T> target, DiffAlgorithmListener progress) {
4849
Objects.requireNonNull(source, "source list must not be null");
4950
Objects.requireNonNull(target, "target list must not be null");
5051

@@ -200,10 +201,10 @@ private class DiffData {
200201
final int[] vDown;
201202
final int[] vUp;
202203
final List<Change> script;
203-
final List<T> source;
204-
final List<T> target;
204+
final List<? extends T> source;
205+
final List<? extends T> target;
205206

206-
public DiffData(List<T> source, List<T> target) {
207+
public DiffData(List<? extends T> source, List<? extends T> target) {
207208
this.source = source;
208209
this.target = target;
209210
size = source.size() + target.size() + 2;
@@ -237,7 +238,7 @@ public <T> DiffAlgorithmI<T> create() {
237238
}
238239

239240
@Override
240-
public <T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer) {
241+
public <T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer) {
241242
return new MyersDiffWithLinearSpace<>(equalizer);
242243
}
243244
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.List;
1919

2020
/**
21-
* This delta contains equal lines of data. Therefore nothing is to do in applyTo and restore.
21+
* This delta contains equal lines of data. Therefore, nothing is to do in applyTo and restore.
2222
* @author tobens
2323
*/
2424
public class EqualDelta<T> extends AbstractDelta<T> {
@@ -49,6 +49,6 @@ public String toString() {
4949

5050
@Override
5151
public AbstractDelta<T> withChunks(Chunk<T> original, Chunk<T> revised) {
52-
return new EqualDelta<T>(original, revised);
52+
return new EqualDelta<>(original, revised);
5353
}
5454
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Patch(int estimatedPatchSize) {
5454
* @return A new list containing the applied patch.
5555
* @throws PatchFailedException if the patch cannot be applied
5656
*/
57-
public List<T> applyTo(List<T> target) throws PatchFailedException {
57+
public List<T> applyTo(List<? extends T> target) throws PatchFailedException {
5858
List<T> result = new ArrayList<>(target);
5959
applyToExisting(result);
6060
return result;
@@ -244,7 +244,7 @@ public Patch withConflictOutput(ConflictOutput<T> conflictOutput) {
244244
* @param target The list to copy and apply changes to.
245245
* @return A new list, containing the restored state.
246246
*/
247-
public List<T> restore(List<T> target) {
247+
public List<T> restore(List<? extends T> target) {
248248
List<T> result = new ArrayList<>(target);
249249
restoreToExisting(result);
250250
return result;
@@ -294,12 +294,12 @@ public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Chan
294294
return generate(original, revised, changes, false);
295295
}
296296

297-
private static <T> Chunk<T> buildChunk(int start, int end, List<T> data) {
297+
private static <T> Chunk<T> buildChunk(int start, int end, List<? extends T> data) {
298298
return new Chunk<>(start, new ArrayList<>(data.subList(start, end)));
299299
}
300300

301301
public static <T> Patch<T> generate(
302-
List<T> original, List<T> revised, List<Change> _changes, boolean includeEquals) {
302+
List<? extends T> original, List<? extends T> revised, List<Change> _changes, boolean includeEquals) {
303303
Patch<T> patch = new Patch<>(_changes.size());
304304
int startOriginal = 0;
305305
int startRevised = 0;

pom.xml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,28 @@
132132
<sourceDirectories>${project.build.sourceDirectory}</sourceDirectories>
133133
<checkstyleRules>
134134
<module name="Checker">
135-
<module name="SuppressWarningsFilter" />
135+
<module name="SuppressWarningsFilter"/>
136136
<module name="TreeWalker">
137-
<module name="SuppressionCommentFilter" />
138-
<module name="AvoidNestedBlocks" />
139-
<module name="ConstantName" />
140-
<module name="EmptyCatchBlock" />
141-
<module name="EmptyStatement" />
142-
<module name="MissingOverride" />
143-
<module name="MultipleVariableDeclarations" />
144-
<module name="ParameterAssignment" />
145-
<module name="StringLiteralEquality" />
146-
<module name="RedundantImport" />
147-
<module name="UnusedImports" />
137+
<module name="SuppressionCommentFilter"/>
138+
<module name="AvoidNestedBlocks"/>
139+
<module name="ConstantName"/>
140+
<module name="EmptyCatchBlock"/>
141+
<module name="EmptyStatement"/>
142+
<module name="MissingOverride"/>
143+
<module name="MultipleVariableDeclarations"/>
144+
<module name="ParameterAssignment"/>
145+
<module name="StringLiteralEquality"/>
146+
<module name="RedundantImport"/>
147+
<module name="UnusedImports"/>
148148

149-
<module name="WhitespaceAfter" />
149+
<module name="WhitespaceAfter"/>
150150

151-
<module name="NeedBraces" />
152-
<module name="UnnecessaryParentheses" />
153-
<module name="LeftCurly" />
154-
<module name="RightCurly" />
151+
<module name="NeedBraces"/>
152+
<module name="UnnecessaryParentheses"/>
153+
<module name="LeftCurly"/>
154+
<module name="RightCurly"/>
155155

156-
<module name="SuppressWarningsHolder" />
156+
<module name="SuppressWarningsHolder"/>
157157
</module>
158158
</module>
159159
</checkstyleRules>
@@ -188,10 +188,10 @@
188188
<plugin>
189189
<groupId>com.diffplug.spotless</groupId>
190190
<artifactId>spotless-maven-plugin</artifactId>
191-
<version>2.30.0</version>
191+
<version>2.46.0</version>
192192
<configuration>
193193
<java>
194-
<palantirJavaFormat />
194+
<palantirJavaFormat/>
195195
<indent>
196196
<tabs>true</tabs>
197197
<spacesPerTab>2</spacesPerTab>

0 commit comments

Comments
 (0)