GeezerVison is showing github.com — fixes #159 · Global-localhost/java-diff-utils@dc5ecb8
File treeExpand file treeCollapse file tree Open diff view settings main/java/com/github/difflib test/java/com/github/difflib
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: CHANGELOG.md +3-1Lines changed: 3 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file. | 5 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). | 6 | 6 | This project uses a custom versioning scheme (and not [Semantic Versioning](https://semver.org/spec/v2.0.0.html)). | 7 | 7 |
| 8 | | -## [unreleased] | | 8 | +## [4.13] | | 9 | + | | 10 | +* API change: due to Issue #159: the author of the algorithm is Eugene Myers, therefore classes and methods were renamed accordingly | 9 | 11 |
| 10 | 12 | ### Changed | 11 | 13 |
| |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/DiffUtils.java +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | import com.github.difflib.algorithm.DiffAlgorithmFactory; | 19 | 19 | import com.github.difflib.algorithm.DiffAlgorithmI; | 20 | 20 | import com.github.difflib.algorithm.DiffAlgorithmListener; | 21 | | -import com.github.difflib.algorithm.myers.MeyersDiff; | | 21 | +import com.github.difflib.algorithm.myers.MyersDiff; | 22 | 22 | import com.github.difflib.patch.AbstractDelta; | 23 | 23 | import com.github.difflib.patch.Patch; | 24 | 24 | import com.github.difflib.patch.PatchFailedException; | @@ -37,7 +37,7 @@ public final class DiffUtils { | 37 | 37 | /** | 38 | 38 | * This factory generates the DEFAULT_DIFF algorithm for all these routines. | 39 | 39 | */ | 40 | | - static DiffAlgorithmFactory DEFAULT_DIFF = MeyersDiff.factory(); | | 40 | + static DiffAlgorithmFactory DEFAULT_DIFF = MyersDiff.factory(); | 41 | 41 |
| 42 | 42 | public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory) { | 43 | 43 | DEFAULT_DIFF = factory; | @@ -95,7 +95,7 @@ public static <T> Patch<T> diff(List<T> source, List<T> target, | 95 | 95 | return DiffUtils.diff(source, target, | 96 | 96 | DEFAULT_DIFF.create(equalizer)); | 97 | 97 | } | 98 | | - return DiffUtils.diff(source, target, new MeyersDiff<>()); | | 98 | + return DiffUtils.diff(source, target, new MyersDiff<>()); | 99 | 99 | } | 100 | 100 |
| 101 | 101 | public static <T> Patch<T> diff(List<T> original, List<T> revised, | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MyersDiff.java +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | import java.util.function.BiPredicate; | 28 | 28 |
| 29 | 29 | /** | 30 | | - * A clean-room implementation of Eugene Meyers greedy differencing algorithm. | | 30 | + * A clean-room implementation of Eugene Myers greedy differencing algorithm. | 31 | 31 | */ | 32 | | -public final class MeyersDiff<T> implements DiffAlgorithmI<T> { | | 32 | +public final class MyersDiff<T> implements DiffAlgorithmI<T> { | 33 | 33 |
| 34 | 34 | private final BiPredicate<T, T> equalizer; | 35 | 35 |
| 36 | | - public MeyersDiff() { | | 36 | + public MyersDiff() { | 37 | 37 | equalizer = Object::equals; | 38 | 38 | } | 39 | 39 |
| 40 | | - public MeyersDiff(final BiPredicate<T, T> equalizer) { | | 40 | + public MyersDiff(final BiPredicate<T, T> equalizer) { | 41 | 41 | Objects.requireNonNull(equalizer, "equalizer must not be null"); | 42 | 42 | this.equalizer = equalizer; | 43 | 43 | } | @@ -187,13 +187,13 @@ public static DiffAlgorithmFactory factory() { | 187 | 187 | @Override | 188 | 188 | public <T> DiffAlgorithmI<T> | 189 | 189 | create() { | 190 | | - return new MeyersDiff<T>(); | | 190 | + return new MyersDiff<T>(); | 191 | 191 | } | 192 | 192 |
| 193 | 193 | @Override | 194 | 194 | public <T> DiffAlgorithmI<T> | 195 | 195 | create(BiPredicate < T, T > equalizer) { | 196 | | - return new MeyersDiff<T>(equalizer); | | 196 | + return new MyersDiff<T>(equalizer); | 197 | 197 | } | 198 | 198 | }; | 199 | 199 | } | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MyersDiffWithLinearSpace.java +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | * | 31 | 31 | * @author tw | 32 | 32 | */ | 33 | | -public class MeyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> { | | 33 | +public class MyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> { | 34 | 34 |
| 35 | 35 | private final BiPredicate<T, T> equalizer; | 36 | 36 |
| 37 | | - public MeyersDiffWithLinearSpace() { | | 37 | + public MyersDiffWithLinearSpace() { | 38 | 38 | equalizer = Object::equals; | 39 | 39 | } | 40 | 40 |
| 41 | | - public MeyersDiffWithLinearSpace(final BiPredicate<T, T> equalizer) { | | 41 | + public MyersDiffWithLinearSpace(final BiPredicate<T, T> equalizer) { | 42 | 42 | Objects.requireNonNull(equalizer, "equalizer must not be null"); | 43 | 43 | this.equalizer = equalizer; | 44 | 44 | } | @@ -231,13 +231,13 @@ public static DiffAlgorithmFactory factory() { | 231 | 231 | @Override | 232 | 232 | public <T> DiffAlgorithmI<T> | 233 | 233 | create() { | 234 | | - return new MeyersDiffWithLinearSpace<T>(); | | 234 | + return new MyersDiffWithLinearSpace<T>(); | 235 | 235 | } | 236 | 236 |
| 237 | 237 | @Override | 238 | 238 | public <T> DiffAlgorithmI<T> | 239 | 239 | create(BiPredicate < T, T > equalizer) { | 240 | | - return new MeyersDiffWithLinearSpace<T>(equalizer); | | 240 | + return new MyersDiffWithLinearSpace<T>(equalizer); | 241 | 241 | } | 242 | 242 | }; | 243 | 243 | } | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/test/java/com/github/difflib/DiffUtilsTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -132,7 +132,7 @@ public void testDiffMissesChangeForkDnaumenkoIssue31() { | 132 | 132 | } | 133 | 133 |
| 134 | 134 | /** | 135 | | - * To test this, the greedy meyer algorithm is not suitable. | | 135 | + * To test this, the greedy Myer algorithm is not suitable. | 136 | 136 | */ | 137 | 137 | @Test | 138 | 138 | @Disabled | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/test/java/com/github/difflib/algorithm/myers/MyersDiffTest.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,7 +34,7 @@ public class MyersDiffTest { | 34 | 34 | public void testDiffMyersExample1Forward() { | 35 | 35 | List<String> original = Arrays.asList("A", "B", "C", "A", "B", "B", "A"); | 36 | 36 | List<String> revised = Arrays.asList("C", "B", "A", "B", "A", "C"); | 37 | | - final Patch<String> patch = Patch.generate(original, revised, new MeyersDiff<String>().computeDiff(original, revised, null)); | | 37 | + final Patch<String> patch = Patch.generate(original, revised, new MyersDiff<String>().computeDiff(original, revised, null)); | 38 | 38 | assertNotNull(patch); | 39 | 39 | assertEquals(4, patch.getDeltas().size()); | 40 | 40 | assertEquals("Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [InsertDelta, position: 3, lines: [B]], [DeleteDelta, position: 5, lines: [B]], [InsertDelta, position: 7, lines: [C]]]}", patch.toString()); | @@ -47,7 +47,7 @@ public void testDiffMyersExample1ForwardWithListener() { | 47 | 47 |
| 48 | 48 | List<String> logdata = new ArrayList<>(); | 49 | 49 | final Patch<String> patch = Patch.generate(original, revised, | 50 | | - new MeyersDiff<String>().computeDiff(original, revised, new DiffAlgorithmListener() { | | 50 | + new MyersDiff<String>().computeDiff(original, revised, new DiffAlgorithmListener() { | 51 | 51 | @Override | 52 | 52 | public void diffStart() { | 53 | 53 | logdata.add("start"); | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/test/java/com/github/difflib/algorithm/myers/MyersDiffWithLinearSpaceTest.java +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | * | 31 | 31 | * @author tw | 32 | 32 | */ | 33 | | -public class MeyersDiffWithLinearSpaceTest { | | 33 | +public class MyersDiffWithLinearSpaceTest { | 34 | 34 |
| 35 | 35 | @Test | 36 | 36 | public void testDiffMyersExample1Forward() { | 37 | 37 | List<String> original = Arrays.asList("A", "B", "C", "A", "B", "B", "A"); | 38 | 38 | List<String> revised = Arrays.asList("C", "B", "A", "B", "A", "C"); | 39 | | - final Patch<String> patch = Patch.generate(original, revised, new MeyersDiffWithLinearSpace<String>().computeDiff(original, revised, null)); | | 39 | + final Patch<String> patch = Patch.generate(original, revised, new MyersDiffWithLinearSpace<String>().computeDiff(original, revised, null)); | 40 | 40 | assertNotNull(patch); | 41 | 41 | System.out.println(patch); | 42 | 42 | assertEquals(5, patch.getDeltas().size()); | @@ -50,7 +50,7 @@ public void testDiffMyersExample1ForwardWithListener() { | 50 | 50 |
| 51 | 51 | List<String> logdata = new ArrayList<>(); | 52 | 52 | final Patch<String> patch = Patch.generate(original, revised, | 53 | | - new MeyersDiffWithLinearSpace<String>().computeDiff(original, revised, new DiffAlgorithmListener() { | | 53 | + new MyersDiffWithLinearSpace<String>().computeDiff(original, revised, new DiffAlgorithmListener() { | 54 | 54 | @Override | 55 | 55 | public void diffStart() { | 56 | 56 | logdata.add("start"); | @@ -84,7 +84,7 @@ public void testPerformanceProblemsIssue124() { | 84 | 84 | .collect(toList()); | 85 | 85 |
| 86 | 86 | long start = System.currentTimeMillis(); | 87 | | - Patch<String> diff = DiffUtils.diff(old, newl, new MeyersDiffWithLinearSpace<String>()); | | 87 | + Patch<String> diff = DiffUtils.diff(old, newl, new MyersDiffWithLinearSpace<String>()); | 88 | 88 | long end = System.currentTimeMillis(); | 89 | 89 | System.out.println("Finished in " + (end - start) + "ms and resulted " + diff.getDeltas().size() + " deltas"); | 90 | 90 | } | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/test/java/com/github/difflib/algorithm/myers/WithMyersDiffWithLinearSpacePatchTest.java +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 |
| 23 | 23 | import com.github.difflib.DiffUtils; | 24 | 24 |
| 25 | | -public class WithMeyersDiffWithLinearSpacePatchTest { | | 25 | +public class WithMyersDiffWithLinearSpacePatchTest { | 26 | 26 |
| 27 | 27 | @Test | 28 | 28 | public void testPatch_Insert() { | 29 | 29 | final List<String> insertTest_from = Arrays.asList("hhh"); | 30 | 30 | final List<String> insertTest_to = Arrays.asList("hhh", "jjj", "kkk", "lll"); | 31 | 31 |
| 32 | | - final Patch<String> patch = DiffUtils.diff(insertTest_from, insertTest_to, new MeyersDiffWithLinearSpace<String>()); | | 32 | + final Patch<String> patch = DiffUtils.diff(insertTest_from, insertTest_to, new MyersDiffWithLinearSpace<String>()); | 33 | 33 | try { | 34 | 34 | assertEquals(insertTest_to, DiffUtils.patch(insertTest_from, patch)); | 35 | 35 | } catch (PatchFailedException e) { | @@ -42,7 +42,7 @@ public void testPatch_Delete() { | 42 | 42 | final List<String> deleteTest_from = Arrays.asList("ddd", "fff", "ggg", "hhh"); | 43 | 43 | final List<String> deleteTest_to = Arrays.asList("ggg"); | 44 | 44 |
| 45 | | - final Patch<String> patch = DiffUtils.diff(deleteTest_from, deleteTest_to, new MeyersDiffWithLinearSpace<String>()); | | 45 | + final Patch<String> patch = DiffUtils.diff(deleteTest_from, deleteTest_to, new MyersDiffWithLinearSpace<String>()); | 46 | 46 | try { | 47 | 47 | assertEquals(deleteTest_to, DiffUtils.patch(deleteTest_from, patch)); | 48 | 48 | } catch (PatchFailedException e) { | @@ -55,7 +55,7 @@ public void testPatch_Change() { | 55 | 55 | final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd"); | 56 | 56 | final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd"); | 57 | 57 |
| 58 | | - final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MeyersDiffWithLinearSpace<String>()); | | 58 | + final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MyersDiffWithLinearSpace<String>()); | 59 | 59 | try { | 60 | 60 | assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, patch)); | 61 | 61 | } catch (PatchFailedException e) { | @@ -166,7 +166,7 @@ public void testPatch_Serializable() throws IOException, ClassNotFoundException | 166 | 166 | final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd"); | 167 | 167 | final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd"); | 168 | 168 |
| 169 | | - final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MeyersDiffWithLinearSpace<String>()); | | 169 | + final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MyersDiffWithLinearSpace<String>()); | 170 | 170 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); | 171 | 171 | ObjectOutputStream out = new ObjectOutputStream(baos); | 172 | 172 | out.writeObject(patch); | @@ -189,7 +189,7 @@ public void testPatch_Change_withExceptionProcessor() { | 189 | 189 | final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd"); | 190 | 190 | final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd"); | 191 | 191 |
| 192 | | - final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MeyersDiffWithLinearSpace<String>()); | | 192 | + final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MyersDiffWithLinearSpace<String>()); | 193 | 193 |
| 194 | 194 | changeTest_from.set(2, "CDC"); | 195 | 195 |
| |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/test/java/com/github/difflib/patch/PatchWithAllDiffAlgorithmsTest.java +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | import com.github.difflib.DiffUtils; | 16 | 16 | import com.github.difflib.algorithm.DiffAlgorithmFactory; | 17 | | -import com.github.difflib.algorithm.myers.MeyersDiff; | 18 | | -import com.github.difflib.algorithm.myers.MeyersDiffWithLinearSpace; | | 17 | +import com.github.difflib.algorithm.myers.MyersDiff; | | 18 | +import com.github.difflib.algorithm.myers.MyersDiffWithLinearSpace; | 19 | 19 | import java.util.stream.Stream; | 20 | 20 | import org.junit.jupiter.api.AfterAll; | 21 | 21 | import org.junit.jupiter.params.ParameterizedTest; | | 25 | 25 | public class PatchWithAllDiffAlgorithmsTest { | 26 | 26 |
| 27 | 27 | private static Stream<Arguments> provideAlgorithms() { | 28 | | - return Stream.of( | 29 | | - Arguments.of(MeyersDiff.factory()), | 30 | | - Arguments.of(MeyersDiffWithLinearSpace.factory())); | | 28 | + return Stream.of(Arguments.of(MyersDiff.factory()), | | 29 | + Arguments.of(MyersDiffWithLinearSpace.factory())); | 31 | 30 | } | 32 | 31 |
| 33 | 32 | @AfterAll | 34 | 33 | public static void afterAll() { | 35 | | - DiffUtils.withDefaultDiffAlgorithmFactory(MeyersDiff.factory()); | | 34 | + DiffUtils.withDefaultDiffAlgorithmFactory(MyersDiff.factory()); | 36 | 35 | } | 37 | 36 |
| 38 | 37 | @ParameterizedTest | |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils/src/test/java/com/github/difflib/patch/PatchWithMyerDiffTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 28 | 28 | * | 29 | 29 | * @author tw | 30 | 30 | */ | 31 | | -public class PatchWithMeyerDiffTest { | | 31 | +public class PatchWithMyerDiffTest { | 32 | 32 |
| 33 | 33 | @Test | 34 | 34 | public void testPatch_Change_withExceptionProcessor() { | |
|