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

Adjust generic parameters for PECS principle.#214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
wumpz merged 1 commit intojava-diff-utils:masterfromagoss94:master
Sep 5, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,8 @@
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) {
Expand DownExpand Up@@ -92,9 +93,9 @@ public int hash(DataList<T> s, int i) {

class DataList<T> extends Sequence {

final List<T> data;
final List<? extendsT> data;

public DataList(List<T> data) {
public DataList(List<? extendsT> data) {
this.data = data;
}

Expand Down
26 changes: 16 additions & 10 deletionsjava-diff-utils/src/main/java/com/github/difflib/DiffUtils.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,7 +57,8 @@ public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory)
* @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);
}

Expand All@@ -69,7 +70,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithm
* @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<? extendsT> original, List<? extendsT> revised) {
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null);
}

Expand All@@ -82,7 +83,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised) {
* @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<? extendsT> original, List<? extendsT> revised, boolean includeEqualParts) {
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null, includeEqualParts);
}

Expand DownExpand Up@@ -110,15 +111,19 @@ public static Patch<String> diff(String sourceText, String targetText, DiffAlgor
* @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));
}
return DiffUtils.diff(source, target, new MyersDiff<>());
}

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);
}

Expand All@@ -135,8 +140,8 @@ public static <T> Patch<T> diff(
* revised sequences. Never {@code null}.
*/
public static <T> Patch<T> diff(
List<T> original,
List<T> revised,
List<? extendsT> original,
List<? extendsT> revised,
DiffAlgorithmI<T> algorithm,
DiffAlgorithmListener progress,
boolean includeEqualParts) {
Expand All@@ -157,7 +162,8 @@ public static <T> Patch<T> diff(
* @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);
}

Expand DownExpand Up@@ -196,7 +202,7 @@ public static Patch<String> diffInline(String original, String revised) {
* @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<? extendsT> original, Patch<T> patch) throws PatchFailedException {
return patch.applyTo(original);
}

Expand All@@ -208,7 +214,7 @@ public static <T> List<T> patch(List<T> original, Patch<T> patch) throws PatchFa
* @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<? extendsT> revised, Patch<T> patch) {
return patch.restore(revised);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,5 +25,5 @@
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);
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<? extendsT> source, List<? extendsT> target, DiffAlgorithmListener progress);

/**
* Simple extension to compute a changeset using arrays.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,13 +31,13 @@
*/
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;
}
Expand All@@ -48,7 +48,8 @@ public MyersDiff(final BiPredicate<T, T> equalizer) {
* 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");

Expand All@@ -71,9 +72,10 @@ public List<Change> computeDiff(final List<T> source, final List<T> target, Diff
* @param orig The original sequence.
* @param rev The revised sequence.
* @return A minimum {@link PathNode Path} accross the differences graph.
* @throwsDifferentiationFailedException if a diff path could not be found.
* @throwsIllegalStateException 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");

Expand DownExpand Up@@ -140,10 +142,10 @@ private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmL
* @param orig The original sequence.
* @param rev The revised sequence.
* @return A {@link Patch} script corresponding to the path.
* @throwsDifferentiationFailedException if a {@link Patch} could not be
* @throwsIllegalStateException 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<? extendsT> orig, List<? extendsT> rev) {
Objects.requireNonNull(actualPath, "path is null");
Objects.requireNonNull(orig, "original sequence is null");
Objects.requireNonNull(rev, "revised sequence is null");
Expand DownExpand Up@@ -190,7 +192,7 @@ public <T> DiffAlgorithmI<T> create() {
}

@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);
}
};
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,19 +32,20 @@
*/
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");

Expand DownExpand Up@@ -200,10 +201,10 @@ private class DiffData {
final int[] vDown;
final int[] vUp;
final List<Change> script;
final List<T> source;
final List<T> target;
final List<? extendsT> source;
final List<? extendsT> target;

public DiffData(List<T> source, List<T> target) {
public DiffData(List<? extendsT> source, List<? extendsT> target) {
this.source = source;
this.target = target;
size = source.size() + target.size() + 2;
Expand DownExpand Up@@ -237,7 +238,7 @@ public <T> DiffAlgorithmI<T> create() {
}

@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);
}
};
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
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> {
Expand DownExpand Up@@ -49,6 +49,6 @@ public String toString() {

@Override
public AbstractDelta<T> withChunks(Chunk<T> original, Chunk<T> revised) {
return new EqualDelta<T>(original, revised);
return new EqualDelta<>(original, revised);
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ public Patch(int estimatedPatchSize) {
* @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<? extendsT> target) throws PatchFailedException {
List<T> result = new ArrayList<>(target);
applyToExisting(result);
return result;
Expand DownExpand Up@@ -244,7 +244,7 @@ public Patch withConflictOutput(ConflictOutput<T> conflictOutput) {
* @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<? extendsT> target) {
List<T> result = new ArrayList<>(target);
restoreToExisting(result);
return result;
Expand DownExpand Up@@ -294,12 +294,12 @@ public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Chan
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<? extendsT> 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<? extendsT> original, List<? extendsT> revised, List<Change> _changes, boolean includeEquals) {
Patch<T> patch = new Patch<>(_changes.size());
int startOriginal = 0;
int startRevised = 0;
Expand Down
40 changes: 20 additions & 20 deletionspom.xml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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>
Expand DownExpand Up@@ -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>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp