GeezerVison is showing github.com — fixes #208 - reformatted source code · 10280506/java-diff-utils@c7f4dfb
File treeExpand file treeCollapse file tree Open diff view settings main/java/com/github/difflib/algorithm/jgit test/java/com/github/difflib/algorithm/jgit
main/java/com/github/difflib test/java/com/github/difflib
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +55-55Lines changed: 55 additions & 55 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> | 2 | 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | 3 | | - <modelVersion>4.0.0</modelVersion> | 4 | | - <parent> | 5 | | - <groupId>io.github.java-diff-utils</groupId> | 6 | | - <artifactId>java-diff-utils-parent</artifactId> | 7 | | - <version>4.16-SNAPSHOT</version> | 8 | | - </parent> | 9 | | - <artifactId>java-diff-utils-jgit</artifactId> | 10 | | - <name>java-diff-utils-jgit</name> | 11 | | - <packaging>jar</packaging> | 12 | | - <description>This is an extension of java-diff-utils using jgit to use its implementation of | | 3 | + <modelVersion>4.0.0</modelVersion> | | 4 | + <parent> | | 5 | + <groupId>io.github.java-diff-utils</groupId> | | 6 | + <artifactId>java-diff-utils-parent</artifactId> | | 7 | + <version>4.16-SNAPSHOT</version> | | 8 | + </parent> | | 9 | + <artifactId>java-diff-utils-jgit</artifactId> | | 10 | + <packaging>jar</packaging> | | 11 | + <name>java-diff-utils-jgit</name> | | 12 | + <description>This is an extension of java-diff-utils using jgit to use its implementation of | 13 | 13 | some difference algorithms.</description> | 14 | | - <dependencies> | 15 | | - <dependency> | 16 | | - <groupId>org.junit.jupiter</groupId> | 17 | | - <artifactId>junit-jupiter</artifactId> | 18 | | - <scope>test</scope> | 19 | | - </dependency> | 20 | | - <dependency> | 21 | | - <!-- no upgrade possible till base JDK upgrade to 17 --> | 22 | | - <groupId>org.eclipse.jgit</groupId> | 23 | | - <artifactId>org.eclipse.jgit</artifactId> | 24 | | - <version>5.13.3.202401111512-r</version> | 25 | | - <exclusions> | 26 | | - <exclusion> | 27 | | - <groupId>com.googlecode.javaewah</groupId> | 28 | | - <artifactId>JavaEWAH</artifactId> | 29 | | - </exclusion> | 30 | | - <exclusion> | 31 | | - <groupId>commons-codec</groupId> | 32 | | - <artifactId>commons-codec</artifactId> | 33 | | - </exclusion> | 34 | | - <exclusion> | 35 | | - <groupId>commons-logging</groupId> | 36 | | - <artifactId>commons-logging</artifactId> | 37 | | - </exclusion> | 38 | | - <exclusion> | 39 | | - <groupId>org.apache.httpcomponents</groupId> | 40 | | - <artifactId>httpclient</artifactId> | 41 | | - </exclusion> | 42 | | - <exclusion> | 43 | | - <groupId>com.jcraft</groupId> | 44 | | - <artifactId>jsch</artifactId> | 45 | | - </exclusion> | 46 | | - <exclusion> | 47 | | - <groupId>org.slf4j</groupId> | 48 | | - <artifactId>slf4j-api</artifactId> | 49 | | - </exclusion> | 50 | | - </exclusions> | 51 | | - </dependency> | 52 | | - <dependency> | 53 | | - <groupId>${project.groupId}</groupId> | 54 | | - <artifactId>java-diff-utils</artifactId> | 55 | | - <version>${project.version}</version> | 56 | | - </dependency> | 57 | | - </dependencies> | 58 | | -</project> | | 14 | + <dependencies> | | 15 | + <dependency> | | 16 | + <groupId>org.junit.jupiter</groupId> | | 17 | + <artifactId>junit-jupiter</artifactId> | | 18 | + <scope>test</scope> | | 19 | + </dependency> | | 20 | + <dependency> | | 21 | + <!-- no upgrade possible till base JDK upgrade to 17 --> | | 22 | + <groupId>org.eclipse.jgit</groupId> | | 23 | + <artifactId>org.eclipse.jgit</artifactId> | | 24 | + <version>5.13.3.202401111512-r</version> | | 25 | + <exclusions> | | 26 | + <exclusion> | | 27 | + <groupId>com.googlecode.javaewah</groupId> | | 28 | + <artifactId>JavaEWAH</artifactId> | | 29 | + </exclusion> | | 30 | + <exclusion> | | 31 | + <groupId>commons-codec</groupId> | | 32 | + <artifactId>commons-codec</artifactId> | | 33 | + </exclusion> | | 34 | + <exclusion> | | 35 | + <groupId>commons-logging</groupId> | | 36 | + <artifactId>commons-logging</artifactId> | | 37 | + </exclusion> | | 38 | + <exclusion> | | 39 | + <groupId>org.apache.httpcomponents</groupId> | | 40 | + <artifactId>httpclient</artifactId> | | 41 | + </exclusion> | | 42 | + <exclusion> | | 43 | + <groupId>com.jcraft</groupId> | | 44 | + <artifactId>jsch</artifactId> | | 45 | + </exclusion> | | 46 | + <exclusion> | | 47 | + <groupId>org.slf4j</groupId> | | 48 | + <artifactId>slf4j-api</artifactId> | | 49 | + </exclusion> | | 50 | + </exclusions> | | 51 | + </dependency> | | 52 | + <dependency> | | 53 | + <groupId>${project.groupId}</groupId> | | 54 | + <artifactId>java-diff-utils</artifactId> | | 55 | + <version>${project.version}</version> | | 56 | + </dependency> | | 57 | + </dependencies> | | 58 | +</project> |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils-jgit/src/main/java/com/github/difflib/algorithm/jgit/HistogramDiff.java +54-54Lines changed: 54 additions & 54 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 35 | 35 | */ | 36 | 36 | public class HistogramDiff<T> implements DiffAlgorithmI<T> { | 37 | 37 |
| 38 | | - @Override | 39 | | - public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) { | 40 | | - Objects.requireNonNull(source, "source list must not be null"); | 41 | | - Objects.requireNonNull(target, "target list must not be null"); | 42 | | - if (progress != null) { | 43 | | - progress.diffStart(); | 44 | | - } | 45 | | - EditList diffList = new EditList(); | 46 | | - diffList.addAll(new org.eclipse.jgit.diff.HistogramDiff().diff(new DataListComparator<>(progress), new DataList<>(source), new DataList<>(target))); | 47 | | - List<Change> patch = new ArrayList<>(); | 48 | | - for (Edit edit : diffList) { | 49 | | - DeltaType type = DeltaType.EQUAL; | 50 | | - switch (edit.getType()) { | 51 | | - case DELETE: | 52 | | - type = DeltaType.DELETE; | 53 | | - break; | 54 | | - case INSERT: | 55 | | - type = DeltaType.INSERT; | 56 | | - break; | 57 | | - case REPLACE: | 58 | | - type = DeltaType.CHANGE; | 59 | | - break; | 60 | | - } | 61 | | - patch.add(new Change(type, edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB())); | 62 | | - } | 63 | | - if (progress != null) { | 64 | | - progress.diffEnd(); | 65 | | - } | 66 | | - return patch; | 67 | | - } | | 38 | + @Override | | 39 | + public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) { | | 40 | + Objects.requireNonNull(source, "source list must not be null"); | | 41 | + Objects.requireNonNull(target, "target list must not be null"); | | 42 | + if (progress != null) { | | 43 | + progress.diffStart(); | | 44 | + } | | 45 | + EditList diffList = new EditList(); | | 46 | + diffList.addAll(new org.eclipse.jgit.diff.HistogramDiff() | | 47 | + .diff(new DataListComparator<>(progress), new DataList<>(source), new DataList<>(target))); | | 48 | + List<Change> patch = new ArrayList<>(); | | 49 | + for (Edit edit : diffList) { | | 50 | + DeltaType type = DeltaType.EQUAL; | | 51 | + switch (edit.getType()) { | | 52 | + case DELETE: | | 53 | + type = DeltaType.DELETE; | | 54 | + break; | | 55 | + case INSERT: | | 56 | + type = DeltaType.INSERT; | | 57 | + break; | | 58 | + case REPLACE: | | 59 | + type = DeltaType.CHANGE; | | 60 | + break; | | 61 | + } | | 62 | + patch.add(new Change(type, edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB())); | | 63 | + } | | 64 | + if (progress != null) { | | 65 | + progress.diffEnd(); | | 66 | + } | | 67 | + return patch; | | 68 | + } | 68 | 69 | } | 69 | 70 |
| 70 | 71 | class DataListComparator<T> extends SequenceComparator<DataList<T>> { | 71 | 72 |
| 72 | | - private final DiffAlgorithmListener progress; | | 73 | + private final DiffAlgorithmListener progress; | 73 | 74 |
| 74 | | - public DataListComparator(DiffAlgorithmListener progress) { | 75 | | - this.progress = progress; | 76 | | - } | | 75 | + public DataListComparator(DiffAlgorithmListener progress) { | | 76 | + this.progress = progress; | | 77 | + } | 77 | 78 |
| 78 | | - @Override | 79 | | - public boolean equals(DataList<T> original, int orgIdx, DataList<T> revised, int revIdx) { | 80 | | - if (progress != null) { | 81 | | - progress.diffStep(orgIdx + revIdx, original.size() + revised.size()); | 82 | | - } | 83 | | - return original.data.get(orgIdx).equals(revised.data.get(revIdx)); | 84 | | - } | 85 | | - | 86 | | - @Override | 87 | | - public int hash(DataList<T> s, int i) { | 88 | | - return s.data.get(i).hashCode(); | 89 | | - } | | 79 | + @Override | | 80 | + public boolean equals(DataList<T> original, int orgIdx, DataList<T> revised, int revIdx) { | | 81 | + if (progress != null) { | | 82 | + progress.diffStep(orgIdx + revIdx, original.size() + revised.size()); | | 83 | + } | | 84 | + return original.data.get(orgIdx).equals(revised.data.get(revIdx)); | | 85 | + } | 90 | 86 |
| | 87 | + @Override | | 88 | + public int hash(DataList<T> s, int i) { | | 89 | + return s.data.get(i).hashCode(); | | 90 | + } | 91 | 91 | } | 92 | 92 |
| 93 | 93 | class DataList<T> extends Sequence { | 94 | 94 |
| 95 | | - final List<T> data; | | 95 | + final List<T> data; | 96 | 96 |
| 97 | | - public DataList(List<T> data) { | 98 | | - this.data = data; | 99 | | - } | | 97 | + public DataList(List<T> data) { | | 98 | + this.data = data; | | 99 | + } | 100 | 100 |
| 101 | | - @Override | 102 | | - public int size() { | 103 | | - return data.size(); | 104 | | - } | | 101 | + @Override | | 102 | + public int size() { | | 103 | + return data.size(); | | 104 | + } | 105 | 105 | } |
Collapse file Copy file name to clipboardExpand all lines: java-diff-utils-jgit/src/test/java/com/github/difflib/algorithm/jgit/HistogramDiffTest.java +58-50Lines changed: 58 additions & 50 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | */ | 16 | 16 | package com.github.difflib.algorithm.jgit; | 17 | 17 |
| | 18 | +import static org.junit.jupiter.api.Assertions.assertEquals; | | 19 | +import static org.junit.jupiter.api.Assertions.assertNotNull; | | 20 | + | 18 | 21 | import com.github.difflib.algorithm.DiffAlgorithmListener; | 19 | 22 | import com.github.difflib.patch.Patch; | 20 | 23 | import com.github.difflib.patch.PatchFailedException; | 21 | 24 | import java.util.ArrayList; | 22 | 25 | import java.util.Arrays; | 23 | 26 | import java.util.List; | 24 | | -import static org.junit.jupiter.api.Assertions.assertEquals; | 25 | | -import static org.junit.jupiter.api.Assertions.assertNotNull; | 26 | 27 | import org.junit.jupiter.api.Test; | 27 | 28 |
| 28 | 29 | /** | | 31 | 32 | */ | 32 | 33 | public class HistogramDiffTest { | 33 | 34 |
| 34 | | - public HistogramDiffTest() { | 35 | | - } | | 35 | + public HistogramDiffTest() {} | | 36 | + | | 37 | + /** | | 38 | + * Test of diff method, of class HistogramDiff. | | 39 | + */ | | 40 | + @Test | | 41 | + public void testDiff() throws PatchFailedException { | | 42 | + List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A"); | | 43 | + List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C"); | | 44 | + final Patch<String> patch = | | 45 | + Patch.generate(orgList, revList, new HistogramDiff<String>().computeDiff(orgList, revList, null)); | | 46 | + System.out.println(patch); | | 47 | + assertNotNull(patch); | | 48 | + assertEquals(3, patch.getDeltas().size()); | | 49 | + assertEquals( | | 50 | + "Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}", | | 51 | + patch.toString()); | | 52 | + | | 53 | + List<String> patched = patch.applyTo(orgList); | | 54 | + assertEquals(revList, patched); | | 55 | + } | | 56 | + | | 57 | + @Test | | 58 | + public void testDiffWithListener() throws PatchFailedException { | | 59 | + List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A"); | | 60 | + List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C"); | 36 | 61 |
| 37 | | - /** | 38 | | - * Test of diff method, of class HistogramDiff. | 39 | | - */ | 40 | | - @Test | 41 | | - public void testDiff() throws PatchFailedException { | 42 | | - List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A"); | 43 | | - List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C"); | 44 | | - final Patch<String> patch = Patch.generate(orgList, revList, new HistogramDiff<String>().computeDiff(orgList, revList, null)); | 45 | | - System.out.println(patch); | 46 | | - assertNotNull(patch); | 47 | | - assertEquals(3, patch.getDeltas().size()); | 48 | | - assertEquals("Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}", patch.toString()); | | 62 | + List<String> logdata = new ArrayList<>(); | | 63 | + final Patch<String> patch = Patch.generate( | | 64 | + orgList, | | 65 | + revList, | | 66 | + new HistogramDiff<String>().computeDiff(orgList, revList, new DiffAlgorithmListener() { | | 67 | + @Override | | 68 | + public void diffStart() { | | 69 | + logdata.add("start"); | | 70 | + } | 49 | 71 |
| 50 | | - List<String> patched = patch.applyTo(orgList); | 51 | | - assertEquals(revList, patched); | 52 | | - } | 53 | | - | 54 | | - @Test | 55 | | - public void testDiffWithListener() throws PatchFailedException { | 56 | | - List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A"); | 57 | | - List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C"); | 58 | | - | 59 | | - List<String> logdata = new ArrayList<>(); | 60 | | - final Patch<String> patch = Patch.generate(orgList, revList, new HistogramDiff<String>().computeDiff(orgList, revList, new DiffAlgorithmListener() { | 61 | | - @Override | 62 | | - public void diffStart() { | 63 | | - logdata.add("start"); | 64 | | - } | | 72 | + @Override | | 73 | + public void diffStep(int value, int max) { | | 74 | + logdata.add(value + " - " + max); | | 75 | + } | 65 | 76 |
| 66 | | - @Override | 67 | | - public void diffStep(int value, int max) { | 68 | | - logdata.add(value + " - " + max); | 69 | | - } | | 77 | + @Override | | 78 | + public void diffEnd() { | | 79 | + logdata.add("end"); | | 80 | + } | | 81 | + })); | | 82 | + System.out.println(patch); | | 83 | + assertNotNull(patch); | | 84 | + assertEquals(3, patch.getDeltas().size()); | | 85 | + assertEquals( | | 86 | + "Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}", | | 87 | + patch.toString()); | 70 | 88 |
| 71 | | - @Override | 72 | | - public void diffEnd() { | 73 | | - logdata.add("end"); | 74 | | - } | 75 | | - })); | 76 | | - System.out.println(patch); | 77 | | - assertNotNull(patch); | 78 | | - assertEquals(3, patch.getDeltas().size()); | 79 | | - assertEquals("Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}", patch.toString()); | | 89 | + List<String> patched = patch.applyTo(orgList); | | 90 | + assertEquals(revList, patched); | 80 | 91 |
| 81 | | - List<String> patched = patch.applyTo(orgList); | 82 | | - assertEquals(revList, patched); | 83 | | - | 84 | | - System.out.println(logdata); | 85 | | - assertEquals(19, logdata.size()); | 86 | | - } | | 92 | + System.out.println(logdata); | | 93 | + assertEquals(19, logdata.size()); | | 94 | + } | 87 | 95 | } |
|