mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
Adjust generic parameters for PECS principle. (#214)
Spotless update Co-authored-by: Andreas Goss <agoss@itemis.com>
This commit is contained in:
@@ -36,7 +36,8 @@ import org.eclipse.jgit.diff.SequenceComparator;
|
||||
public class HistogramDiff<T> implements DiffAlgorithmI<T> {
|
||||
|
||||
@Override
|
||||
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) {
|
||||
public List<Change> computeDiff(
|
||||
List<? extends T> source, List<? extends T> target, DiffAlgorithmListener progress) {
|
||||
Objects.requireNonNull(source, "source list must not be null");
|
||||
Objects.requireNonNull(target, "target list must not be null");
|
||||
if (progress != null) {
|
||||
@@ -92,9 +93,9 @@ class DataListComparator<T> extends SequenceComparator<DataList<T>> {
|
||||
|
||||
class DataList<T> extends Sequence {
|
||||
|
||||
final List<T> data;
|
||||
final List<? extends T> data;
|
||||
|
||||
public DataList(List<T> data) {
|
||||
public DataList(List<? extends T> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@ public final class DiffUtils {
|
||||
* @param progress a {@link DiffAlgorithmListener} representing the progress listener. Can be {@code null}.
|
||||
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmListener progress) {
|
||||
public static <T> Patch<T> diff(
|
||||
List<? extends T> original, List<? extends T> revised, DiffAlgorithmListener progress) {
|
||||
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), progress);
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ public final class DiffUtils {
|
||||
* @param revised a {@link List} representing the revised sequence of elements. Must not be {@code null}.
|
||||
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised) {
|
||||
public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> revised) {
|
||||
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null);
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ public final class DiffUtils {
|
||||
* @param includeEqualParts a {@link boolean} representing whether to include equal parts in the resulting patch.
|
||||
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised, boolean includeEqualParts) {
|
||||
public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> revised, boolean includeEqualParts) {
|
||||
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null, includeEqualParts);
|
||||
}
|
||||
|
||||
@@ -110,7 +111,8 @@ public final class DiffUtils {
|
||||
* @return The patch describing the difference between the original and
|
||||
* revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> source, List<T> target, BiPredicate<T, T> equalizer) {
|
||||
public static <T> Patch<T> diff(
|
||||
List<? extends T> source, List<? extends T> target, BiPredicate<? super T, ? super T> equalizer) {
|
||||
if (equalizer != null) {
|
||||
return DiffUtils.diff(source, target, DEFAULT_DIFF.create(equalizer));
|
||||
}
|
||||
@@ -118,7 +120,10 @@ public final class DiffUtils {
|
||||
}
|
||||
|
||||
public static <T> Patch<T> diff(
|
||||
List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) {
|
||||
List<? extends T> original,
|
||||
List<? extends T> revised,
|
||||
DiffAlgorithmI<T> algorithm,
|
||||
DiffAlgorithmListener progress) {
|
||||
return diff(original, revised, algorithm, progress, false);
|
||||
}
|
||||
|
||||
@@ -135,8 +140,8 @@ public final class DiffUtils {
|
||||
* revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(
|
||||
List<T> original,
|
||||
List<T> revised,
|
||||
List<? extends T> original,
|
||||
List<? extends T> revised,
|
||||
DiffAlgorithmI<T> algorithm,
|
||||
DiffAlgorithmListener progress,
|
||||
boolean includeEqualParts) {
|
||||
@@ -157,7 +162,8 @@ public final class DiffUtils {
|
||||
* @return The patch describing the difference between the original and
|
||||
* revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm) {
|
||||
public static <T> Patch<T> diff(
|
||||
List<? extends T> original, List<? extends T> revised, DiffAlgorithmI<T> algorithm) {
|
||||
return diff(original, revised, algorithm, null);
|
||||
}
|
||||
|
||||
@@ -196,7 +202,7 @@ public final class DiffUtils {
|
||||
* @return the revised list.
|
||||
* @throws PatchFailedException if the patch cannot be applied.
|
||||
*/
|
||||
public static <T> List<T> patch(List<T> original, Patch<T> patch) throws PatchFailedException {
|
||||
public static <T> List<T> patch(List<? extends T> original, Patch<T> patch) throws PatchFailedException {
|
||||
return patch.applyTo(original);
|
||||
}
|
||||
|
||||
@@ -208,7 +214,7 @@ public final class DiffUtils {
|
||||
* @return the original list.
|
||||
* @throws PatchFailedException if the patch cannot be applied.
|
||||
*/
|
||||
public static <T> List<T> unpatch(List<T> revised, Patch<T> patch) {
|
||||
public static <T> List<T> unpatch(List<? extends T> revised, Patch<T> patch) {
|
||||
return patch.restore(revised);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,5 +25,5 @@ import java.util.function.BiPredicate;
|
||||
public interface DiffAlgorithmFactory {
|
||||
<T> DiffAlgorithmI<T> create();
|
||||
|
||||
<T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer);
|
||||
<T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public interface DiffAlgorithmI<T> {
|
||||
* @param progress progress listener
|
||||
* @return
|
||||
*/
|
||||
List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress);
|
||||
List<Change> computeDiff(List<? extends T> source, List<? extends T> target, DiffAlgorithmListener progress);
|
||||
|
||||
/**
|
||||
* Simple extension to compute a changeset using arrays.
|
||||
|
||||
@@ -31,13 +31,13 @@ import java.util.function.BiPredicate;
|
||||
*/
|
||||
public final class MyersDiff<T> implements DiffAlgorithmI<T> {
|
||||
|
||||
private final BiPredicate<T, T> equalizer;
|
||||
private final BiPredicate<? super T, ? super T> equalizer;
|
||||
|
||||
public MyersDiff() {
|
||||
equalizer = Object::equals;
|
||||
}
|
||||
|
||||
public MyersDiff(final BiPredicate<T, T> equalizer) {
|
||||
public MyersDiff(final BiPredicate<? super T, ? super T> equalizer) {
|
||||
Objects.requireNonNull(equalizer, "equalizer must not be null");
|
||||
this.equalizer = equalizer;
|
||||
}
|
||||
@@ -48,7 +48,8 @@ public final class MyersDiff<T> implements DiffAlgorithmI<T> {
|
||||
* Return empty diff if get the error while procession the difference.
|
||||
*/
|
||||
@Override
|
||||
public List<Change> computeDiff(final List<T> source, final List<T> target, DiffAlgorithmListener progress) {
|
||||
public List<Change> computeDiff(
|
||||
final List<? extends T> source, final List<? extends T> target, DiffAlgorithmListener progress) {
|
||||
Objects.requireNonNull(source, "source list must not be null");
|
||||
Objects.requireNonNull(target, "target list must not be null");
|
||||
|
||||
@@ -71,9 +72,10 @@ public final class MyersDiff<T> implements DiffAlgorithmI<T> {
|
||||
* @param orig The original sequence.
|
||||
* @param rev The revised sequence.
|
||||
* @return A minimum {@link PathNode Path} accross the differences graph.
|
||||
* @throws DifferentiationFailedException if a diff path could not be found.
|
||||
* @throws IllegalStateException if a diff path could not be found.
|
||||
*/
|
||||
private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmListener progress) {
|
||||
private PathNode buildPath(
|
||||
final List<? extends T> orig, final List<? extends T> rev, DiffAlgorithmListener progress) {
|
||||
Objects.requireNonNull(orig, "original sequence is null");
|
||||
Objects.requireNonNull(rev, "revised sequence is null");
|
||||
|
||||
@@ -140,10 +142,10 @@ public final class MyersDiff<T> implements DiffAlgorithmI<T> {
|
||||
* @param orig The original sequence.
|
||||
* @param rev The revised sequence.
|
||||
* @return A {@link Patch} script corresponding to the path.
|
||||
* @throws DifferentiationFailedException if a {@link Patch} could not be
|
||||
* @throws IllegalStateException if a {@link Patch} could not be
|
||||
* built from the given path.
|
||||
*/
|
||||
private List<Change> buildRevision(PathNode actualPath, List<T> orig, List<T> rev) {
|
||||
private List<Change> buildRevision(PathNode actualPath, List<? extends T> orig, List<? extends T> rev) {
|
||||
Objects.requireNonNull(actualPath, "path is null");
|
||||
Objects.requireNonNull(orig, "original sequence is null");
|
||||
Objects.requireNonNull(rev, "revised sequence is null");
|
||||
@@ -190,7 +192,7 @@ public final class MyersDiff<T> implements DiffAlgorithmI<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer) {
|
||||
public <T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer) {
|
||||
return new MyersDiff<>(equalizer);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -32,19 +32,20 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class MyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> {
|
||||
|
||||
private final BiPredicate<T, T> equalizer;
|
||||
private final BiPredicate<? super T, ? super T> equalizer;
|
||||
|
||||
public MyersDiffWithLinearSpace() {
|
||||
equalizer = Object::equals;
|
||||
}
|
||||
|
||||
public MyersDiffWithLinearSpace(final BiPredicate<T, T> equalizer) {
|
||||
public MyersDiffWithLinearSpace(final BiPredicate<? super T, ? super T> equalizer) {
|
||||
Objects.requireNonNull(equalizer, "equalizer must not be null");
|
||||
this.equalizer = equalizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) {
|
||||
public List<Change> computeDiff(
|
||||
List<? extends T> source, List<? extends T> target, DiffAlgorithmListener progress) {
|
||||
Objects.requireNonNull(source, "source list must not be null");
|
||||
Objects.requireNonNull(target, "target list must not be null");
|
||||
|
||||
@@ -200,10 +201,10 @@ public class MyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> {
|
||||
final int[] vDown;
|
||||
final int[] vUp;
|
||||
final List<Change> script;
|
||||
final List<T> source;
|
||||
final List<T> target;
|
||||
final List<? extends T> source;
|
||||
final List<? extends T> target;
|
||||
|
||||
public DiffData(List<T> source, List<T> target) {
|
||||
public DiffData(List<? extends T> source, List<? extends T> target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
size = source.size() + target.size() + 2;
|
||||
@@ -237,7 +238,7 @@ public class MyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer) {
|
||||
public <T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer) {
|
||||
return new MyersDiffWithLinearSpace<>(equalizer);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.github.difflib.patch;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This delta contains equal lines of data. Therefore nothing is to do in applyTo and restore.
|
||||
* This delta contains equal lines of data. Therefore, nothing is to do in applyTo and restore.
|
||||
* @author tobens
|
||||
*/
|
||||
public class EqualDelta<T> extends AbstractDelta<T> {
|
||||
@@ -49,6 +49,6 @@ public class EqualDelta<T> extends AbstractDelta<T> {
|
||||
|
||||
@Override
|
||||
public AbstractDelta<T> withChunks(Chunk<T> original, Chunk<T> revised) {
|
||||
return new EqualDelta<T>(original, revised);
|
||||
return new EqualDelta<>(original, revised);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class Patch<T> implements Serializable {
|
||||
* @return A new list containing the applied patch.
|
||||
* @throws PatchFailedException if the patch cannot be applied
|
||||
*/
|
||||
public List<T> applyTo(List<T> target) throws PatchFailedException {
|
||||
public List<T> applyTo(List<? extends T> target) throws PatchFailedException {
|
||||
List<T> result = new ArrayList<>(target);
|
||||
applyToExisting(result);
|
||||
return result;
|
||||
@@ -244,7 +244,7 @@ public final class Patch<T> implements Serializable {
|
||||
* @param target The list to copy and apply changes to.
|
||||
* @return A new list, containing the restored state.
|
||||
*/
|
||||
public List<T> restore(List<T> target) {
|
||||
public List<T> restore(List<? extends T> target) {
|
||||
List<T> result = new ArrayList<>(target);
|
||||
restoreToExisting(result);
|
||||
return result;
|
||||
@@ -294,12 +294,12 @@ public final class Patch<T> implements Serializable {
|
||||
return generate(original, revised, changes, false);
|
||||
}
|
||||
|
||||
private static <T> Chunk<T> buildChunk(int start, int end, List<T> data) {
|
||||
private static <T> Chunk<T> buildChunk(int start, int end, List<? extends T> data) {
|
||||
return new Chunk<>(start, new ArrayList<>(data.subList(start, end)));
|
||||
}
|
||||
|
||||
public static <T> Patch<T> generate(
|
||||
List<T> original, List<T> revised, List<Change> _changes, boolean includeEquals) {
|
||||
List<? extends T> original, List<? extends T> revised, List<Change> _changes, boolean includeEquals) {
|
||||
Patch<T> patch = new Patch<>(_changes.size());
|
||||
int startOriginal = 0;
|
||||
int startRevised = 0;
|
||||
|
||||
40
pom.xml
40
pom.xml
@@ -132,28 +132,28 @@
|
||||
<sourceDirectories>${project.build.sourceDirectory}</sourceDirectories>
|
||||
<checkstyleRules>
|
||||
<module name="Checker">
|
||||
<module name="SuppressWarningsFilter" />
|
||||
<module name="SuppressWarningsFilter"/>
|
||||
<module name="TreeWalker">
|
||||
<module name="SuppressionCommentFilter" />
|
||||
<module name="AvoidNestedBlocks" />
|
||||
<module name="ConstantName" />
|
||||
<module name="EmptyCatchBlock" />
|
||||
<module name="EmptyStatement" />
|
||||
<module name="MissingOverride" />
|
||||
<module name="MultipleVariableDeclarations" />
|
||||
<module name="ParameterAssignment" />
|
||||
<module name="StringLiteralEquality" />
|
||||
<module name="RedundantImport" />
|
||||
<module name="UnusedImports" />
|
||||
<module name="SuppressionCommentFilter"/>
|
||||
<module name="AvoidNestedBlocks"/>
|
||||
<module name="ConstantName"/>
|
||||
<module name="EmptyCatchBlock"/>
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="MissingOverride"/>
|
||||
<module name="MultipleVariableDeclarations"/>
|
||||
<module name="ParameterAssignment"/>
|
||||
<module name="StringLiteralEquality"/>
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports"/>
|
||||
|
||||
<module name="WhitespaceAfter" />
|
||||
<module name="WhitespaceAfter"/>
|
||||
|
||||
<module name="NeedBraces" />
|
||||
<module name="UnnecessaryParentheses" />
|
||||
<module name="LeftCurly" />
|
||||
<module name="RightCurly" />
|
||||
<module name="NeedBraces"/>
|
||||
<module name="UnnecessaryParentheses"/>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="RightCurly"/>
|
||||
|
||||
<module name="SuppressWarningsHolder" />
|
||||
<module name="SuppressWarningsHolder"/>
|
||||
</module>
|
||||
</module>
|
||||
</checkstyleRules>
|
||||
@@ -188,10 +188,10 @@
|
||||
<plugin>
|
||||
<groupId>com.diffplug.spotless</groupId>
|
||||
<artifactId>spotless-maven-plugin</artifactId>
|
||||
<version>2.30.0</version>
|
||||
<version>2.46.0</version>
|
||||
<configuration>
|
||||
<java>
|
||||
<palantirJavaFormat />
|
||||
<palantirJavaFormat/>
|
||||
<indent>
|
||||
<tabs>true</tabs>
|
||||
<spacesPerTab>2</spacesPerTab>
|
||||
|
||||
Reference in New Issue
Block a user