GeezerVison is showing github.com — Adjust generic parameters for PECS principle. (#214) · akashchamp/java-diff-utils@1ef6162
File treeExpand file treeCollapse file tree Open diff view settings java-diff-utils-jgit/src/main/java/com/github/difflib/algorithm/jgit java-diff-utils/src/main/java/com/github/difflib
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: java-diff-utils-jgit/src/main/java/com/github/difflib/algorithm/jgit/HistogramDiff.java +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 36 | 36 | public class HistogramDiff<T> implements DiffAlgorithmI<T> { | 37 | 37 |
| 38 | 38 | @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) { | 40 | 41 | Objects.requireNonNull(source, "source list must not be null"); | 41 | 42 | Objects.requireNonNull(target, "target list must not be null"); | 42 | 43 | if (progress != null) { | @@ -92,9 +93,9 @@ public int hash(DataList<T> s, int i) { | 92 | 93 |
| 93 | 94 | class DataList<T> extends Sequence { | 94 | 95 |
| 95 | | - final List<T> data; | | 96 | + final List<? extends T> data; | 96 | 97 |
| 97 | | - public DataList(List<T> data) { | | 98 | + public DataList(List<? extends T> data) { | 98 | 99 | this.data = data; | 99 | 100 | } | 100 | 101 |
| |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/DiffUtils.java +16-10Lines changed: 16 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,7 +57,8 @@ public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory) | 57 | 57 | * @param progress a {@link DiffAlgorithmListener} representing the progress listener. Can be {@code null}. | 58 | 58 | * @return The patch describing the difference between the original and revised sequences. Never {@code null}. | 59 | 59 | */ | 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) { | 61 | 62 | return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), progress); | 62 | 63 | } | 63 | 64 |
| @@ -69,7 +70,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithm | 69 | 70 | * @param revised a {@link List} representing the revised sequence of elements. Must not be {@code null}. | 70 | 71 | * @return The patch describing the difference between the original and revised sequences. Never {@code null}. | 71 | 72 | */ | 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) { | 73 | 74 | return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null); | 74 | 75 | } | 75 | 76 |
| @@ -82,7 +83,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised) { | 82 | 83 | * @param includeEqualParts a {@link boolean} representing whether to include equal parts in the resulting patch. | 83 | 84 | * @return The patch describing the difference between the original and revised sequences. Never {@code null}. | 84 | 85 | */ | 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) { | 86 | 87 | return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null, includeEqualParts); | 87 | 88 | } | 88 | 89 |
| @@ -110,15 +111,19 @@ public static Patch<String> diff(String sourceText, String targetText, DiffAlgor | 110 | 111 | * @return The patch describing the difference between the original and | 111 | 112 | * revised sequences. Never {@code null}. | 112 | 113 | */ | 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) { | 114 | 116 | if (equalizer != null) { | 115 | 117 | return DiffUtils.diff(source, target, DEFAULT_DIFF.create(equalizer)); | 116 | 118 | } | 117 | 119 | return DiffUtils.diff(source, target, new MyersDiff<>()); | 118 | 120 | } | 119 | 121 |
| 120 | 122 | 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) { | 122 | 127 | return diff(original, revised, algorithm, progress, false); | 123 | 128 | } | 124 | 129 |
| @@ -135,8 +140,8 @@ public static <T> Patch<T> diff( | 135 | 140 | * revised sequences. Never {@code null}. | 136 | 141 | */ | 137 | 142 | public static <T> Patch<T> diff( | 138 | | - List<T> original, | 139 | | - List<T> revised, | | 143 | + List<? extends T> original, | | 144 | + List<? extends T> revised, | 140 | 145 | DiffAlgorithmI<T> algorithm, | 141 | 146 | DiffAlgorithmListener progress, | 142 | 147 | boolean includeEqualParts) { | @@ -157,7 +162,8 @@ public static <T> Patch<T> diff( | 157 | 162 | * @return The patch describing the difference between the original and | 158 | 163 | * revised sequences. Never {@code null}. | 159 | 164 | */ | 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) { | 161 | 167 | return diff(original, revised, algorithm, null); | 162 | 168 | } | 163 | 169 |
| @@ -196,7 +202,7 @@ public static Patch<String> diffInline(String original, String revised) { | 196 | 202 | * @return the revised list. | 197 | 203 | * @throws PatchFailedException if the patch cannot be applied. | 198 | 204 | */ | 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 { | 200 | 206 | return patch.applyTo(original); | 201 | 207 | } | 202 | 208 |
| @@ -208,7 +214,7 @@ public static <T> List<T> patch(List<T> original, Patch<T> patch) throws PatchFa | 208 | 214 | * @return the original list. | 209 | 215 | * @throws PatchFailedException if the patch cannot be applied. | 210 | 216 | */ | 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) { | 212 | 218 | return patch.restore(revised); | 213 | 219 | } | 214 | 220 |
| |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/algorithm/DiffAlgorithmFactory.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 | public interface DiffAlgorithmFactory { | 26 | 26 | <T> DiffAlgorithmI<T> create(); | 27 | 27 |
| 28 | | - <T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer); | | 28 | + <T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer); | 29 | 29 | } |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/algorithm/DiffAlgorithmI.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,7 +34,7 @@ public interface DiffAlgorithmI<T> { | 34 | 34 | * @param progress progress listener | 35 | 35 | * @return | 36 | 36 | */ | 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); | 38 | 38 |
| 39 | 39 | /** | 40 | 40 | * Simple extension to compute a changeset using arrays. | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MyersDiff.java +10-8Lines changed: 10 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 31 | 31 | */ | 32 | 32 | public final class MyersDiff<T> implements DiffAlgorithmI<T> { | 33 | 33 |
| 34 | | - private final BiPredicate<T, T> equalizer; | | 34 | + private final BiPredicate<? super T, ? super T> equalizer; | 35 | 35 |
| 36 | 36 | public MyersDiff() { | 37 | 37 | equalizer = Object::equals; | 38 | 38 | } | 39 | 39 |
| 40 | | - public MyersDiff(final BiPredicate<T, T> equalizer) { | | 40 | + public MyersDiff(final BiPredicate<? super T, ? super T> equalizer) { | 41 | 41 | Objects.requireNonNull(equalizer, "equalizer must not be null"); | 42 | 42 | this.equalizer = equalizer; | 43 | 43 | } | @@ -48,7 +48,8 @@ public MyersDiff(final BiPredicate<T, T> equalizer) { | 48 | 48 | * Return empty diff if get the error while procession the difference. | 49 | 49 | */ | 50 | 50 | @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) { | 52 | 53 | Objects.requireNonNull(source, "source list must not be null"); | 53 | 54 | Objects.requireNonNull(target, "target list must not be null"); | 54 | 55 |
| @@ -71,9 +72,10 @@ public List<Change> computeDiff(final List<T> source, final List<T> target, Diff | 71 | 72 | * @param orig The original sequence. | 72 | 73 | * @param rev The revised sequence. | 73 | 74 | * @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. | 75 | 76 | */ | 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) { | 77 | 79 | Objects.requireNonNull(orig, "original sequence is null"); | 78 | 80 | Objects.requireNonNull(rev, "revised sequence is null"); | 79 | 81 |
| @@ -140,10 +142,10 @@ private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmL | 140 | 142 | * @param orig The original sequence. | 141 | 143 | * @param rev The revised sequence. | 142 | 144 | * @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 | 144 | 146 | * built from the given path. | 145 | 147 | */ | 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) { | 147 | 149 | Objects.requireNonNull(actualPath, "path is null"); | 148 | 150 | Objects.requireNonNull(orig, "original sequence is null"); | 149 | 151 | Objects.requireNonNull(rev, "revised sequence is null"); | @@ -190,7 +192,7 @@ public <T> DiffAlgorithmI<T> create() { | 190 | 192 | } | 191 | 193 |
| 192 | 194 | @Override | 193 | | - public <T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer) { | | 195 | + public <T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer) { | 194 | 196 | return new MyersDiff<>(equalizer); | 195 | 197 | } | 196 | 198 | }; | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MyersDiffWithLinearSpace.java +8-7Lines changed: 8 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 32 | 32 | */ | 33 | 33 | public class MyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> { | 34 | 34 |
| 35 | | - private final BiPredicate<T, T> equalizer; | | 35 | + private final BiPredicate<? super T, ? super T> equalizer; | 36 | 36 |
| 37 | 37 | public MyersDiffWithLinearSpace() { | 38 | 38 | equalizer = Object::equals; | 39 | 39 | } | 40 | 40 |
| 41 | | - public MyersDiffWithLinearSpace(final BiPredicate<T, T> equalizer) { | | 41 | + public MyersDiffWithLinearSpace(final BiPredicate<? super T, ? super T> equalizer) { | 42 | 42 | Objects.requireNonNull(equalizer, "equalizer must not be null"); | 43 | 43 | this.equalizer = equalizer; | 44 | 44 | } | 45 | 45 |
| 46 | 46 | @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) { | 48 | 49 | Objects.requireNonNull(source, "source list must not be null"); | 49 | 50 | Objects.requireNonNull(target, "target list must not be null"); | 50 | 51 |
| @@ -200,10 +201,10 @@ private class DiffData { | 200 | 201 | final int[] vDown; | 201 | 202 | final int[] vUp; | 202 | 203 | 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; | 205 | 206 |
| 206 | | - public DiffData(List<T> source, List<T> target) { | | 207 | + public DiffData(List<? extends T> source, List<? extends T> target) { | 207 | 208 | this.source = source; | 208 | 209 | this.target = target; | 209 | 210 | size = source.size() + target.size() + 2; | @@ -237,7 +238,7 @@ public <T> DiffAlgorithmI<T> create() { | 237 | 238 | } | 238 | 239 |
| 239 | 240 | @Override | 240 | | - public <T> DiffAlgorithmI<T> create(BiPredicate<T, T> equalizer) { | | 241 | + public <T> DiffAlgorithmI<T> create(BiPredicate<? super T, ? super T> equalizer) { | 241 | 242 | return new MyersDiffWithLinearSpace<>(equalizer); | 242 | 243 | } | 243 | 244 | }; | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/patch/EqualDelta.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | import java.util.List; | 19 | 19 |
| 20 | 20 | /** | 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. | 22 | 22 | * @author tobens | 23 | 23 | */ | 24 | 24 | public class EqualDelta<T> extends AbstractDelta<T> { | @@ -49,6 +49,6 @@ public String toString() { | 49 | 49 |
| 50 | 50 | @Override | 51 | 51 | public AbstractDelta<T> withChunks(Chunk<T> original, Chunk<T> revised) { | 52 | | - return new EqualDelta<T>(original, revised); | | 52 | + return new EqualDelta<>(original, revised); | 53 | 53 | } | 54 | 54 | } |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/patch/Patch.java +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,7 +54,7 @@ public Patch(int estimatedPatchSize) { | 54 | 54 | * @return A new list containing the applied patch. | 55 | 55 | * @throws PatchFailedException if the patch cannot be applied | 56 | 56 | */ | 57 | | - public List<T> applyTo(List<T> target) throws PatchFailedException { | | 57 | + public List<T> applyTo(List<? extends T> target) throws PatchFailedException { | 58 | 58 | List<T> result = new ArrayList<>(target); | 59 | 59 | applyToExisting(result); | 60 | 60 | return result; | @@ -244,7 +244,7 @@ public Patch withConflictOutput(ConflictOutput<T> conflictOutput) { | 244 | 244 | * @param target The list to copy and apply changes to. | 245 | 245 | * @return A new list, containing the restored state. | 246 | 246 | */ | 247 | | - public List<T> restore(List<T> target) { | | 247 | + public List<T> restore(List<? extends T> target) { | 248 | 248 | List<T> result = new ArrayList<>(target); | 249 | 249 | restoreToExisting(result); | 250 | 250 | return result; | @@ -294,12 +294,12 @@ public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Chan | 294 | 294 | return generate(original, revised, changes, false); | 295 | 295 | } | 296 | 296 |
| 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) { | 298 | 298 | return new Chunk<>(start, new ArrayList<>(data.subList(start, end))); | 299 | 299 | } | 300 | 300 |
| 301 | 301 | 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) { | 303 | 303 | Patch<T> patch = new Patch<>(_changes.size()); | 304 | 304 | int startOriginal = 0; | 305 | 305 | int startRevised = 0; | |
Collapse file Copy file name to clipboardExpand all lines: pom.xml +20-20Lines changed: 20 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 132 | 132 | <sourceDirectories>${project.build.sourceDirectory}</sourceDirectories> | 133 | 133 | <checkstyleRules> | 134 | 134 | <module name="Checker"> | 135 | | - <module name="SuppressWarningsFilter" /> | | 135 | + <module name="SuppressWarningsFilter"/> | 136 | 136 | <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"/> | 148 | 148 |
| 149 | | - <module name="WhitespaceAfter" /> | | 149 | + <module name="WhitespaceAfter"/> | 150 | 150 |
| 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"/> | 155 | 155 |
| 156 | | - <module name="SuppressWarningsHolder" /> | | 156 | + <module name="SuppressWarningsHolder"/> | 157 | 157 | </module> | 158 | 158 | </module> | 159 | 159 | </checkstyleRules> | | 188 | 188 | <plugin> | 189 | 189 | <groupId>com.diffplug.spotless</groupId> | 190 | 190 | <artifactId>spotless-maven-plugin</artifactId> | 191 | | - <version>2.30.0</version> | | 191 | + <version>2.46.0</version> | 192 | 192 | <configuration> | 193 | 193 | <java> | 194 | | - <palantirJavaFormat /> | | 194 | + <palantirJavaFormat/> | 195 | 195 | <indent> | 196 | 196 | <tabs>true</tabs> | 197 | 197 | <spacesPerTab>2</spacesPerTab> | |
|