mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
Compare commits
4 Commits
java-diff-
...
java-diff-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ec708fe30 | ||
|
|
fcf83e918f | ||
|
|
4ee56d2554 | ||
|
|
21f9e9d415 |
@@ -9,6 +9,8 @@ This project uses a custom versioning scheme (and not [Semantic Versioning](http
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
* make patch serializable
|
||||||
|
|
||||||
## [4.8]
|
## [4.8]
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.github.java-diff-utils</groupId>
|
<groupId>io.github.java-diff-utils</groupId>
|
||||||
<artifactId>java-diff-utils-parent</artifactId>
|
<artifactId>java-diff-utils-parent</artifactId>
|
||||||
<version>4.8</version>
|
<version>4.9</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>java-diff-utils-jgit</artifactId>
|
<artifactId>java-diff-utils-jgit</artifactId>
|
||||||
<name>java-diff-utils-jgit</name>
|
<name>java-diff-utils-jgit</name>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.github.java-diff-utils</groupId>
|
<groupId>io.github.java-diff-utils</groupId>
|
||||||
<artifactId>java-diff-utils-parent</artifactId>
|
<artifactId>java-diff-utils-parent</artifactId>
|
||||||
<version>4.8</version>
|
<version>4.9</version>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.github.difflib.patch;
|
package com.github.difflib.patch;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ import java.util.Objects;
|
|||||||
* Abstract delta between a source and a target.
|
* Abstract delta between a source and a target.
|
||||||
* @author Tobias Warneke (t.warneke@gmx.net)
|
* @author Tobias Warneke (t.warneke@gmx.net)
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractDelta<T> {
|
public abstract class AbstractDelta<T> implements Serializable {
|
||||||
private final Chunk<T> source;
|
private final Chunk<T> source;
|
||||||
private final Chunk<T> target;
|
private final Chunk<T> target;
|
||||||
private final DeltaType type;
|
private final DeltaType type;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.github.difflib.patch;
|
package com.github.difflib.patch;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,7 +34,7 @@ import java.util.Objects;
|
|||||||
* @author <a href="dm.naumenko@gmail.com>Dmitry Naumenko</a>
|
* @author <a href="dm.naumenko@gmail.com>Dmitry Naumenko</a>
|
||||||
* @param <T> The type of the compared elements in the 'lines'.
|
* @param <T> The type of the compared elements in the 'lines'.
|
||||||
*/
|
*/
|
||||||
public final class Chunk<T> {
|
public final class Chunk<T> implements Serializable {
|
||||||
|
|
||||||
private final int position;
|
private final int position;
|
||||||
private List<T> lines;
|
private List<T> lines;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ package com.github.difflib.patch;
|
|||||||
|
|
||||||
import static java.util.Comparator.comparing;
|
import static java.util.Comparator.comparing;
|
||||||
import com.github.difflib.algorithm.Change;
|
import com.github.difflib.algorithm.Change;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -32,7 +34,7 @@ import java.util.ListIterator;
|
|||||||
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
|
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
|
||||||
* @param <T> The type of the compared elements in the 'lines'.
|
* @param <T> The type of the compared elements in the 'lines'.
|
||||||
*/
|
*/
|
||||||
public final class Patch<T> {
|
public final class Patch<T> implements Serializable {
|
||||||
|
|
||||||
private final List<AbstractDelta<T>> deltas;
|
private final List<AbstractDelta<T>> deltas;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
package com.github.difflib.patch;
|
package com.github.difflib.patch;
|
||||||
|
|
||||||
import com.github.difflib.DiffUtils;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.github.difflib.DiffUtils;
|
||||||
|
|
||||||
public class PatchTest {
|
public class PatchTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -47,4 +55,27 @@ public class PatchTest {
|
|||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatch_Serializable() throws IOException, ClassNotFoundException {
|
||||||
|
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||||
|
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
|
||||||
|
|
||||||
|
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to);
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream out = new ObjectOutputStream(baos);
|
||||||
|
out.writeObject(patch);
|
||||||
|
out.close();
|
||||||
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
|
ObjectInputStream in = new ObjectInputStream(bais);
|
||||||
|
Patch<String> result = (Patch<String>) in.readObject();
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, result));
|
||||||
|
} catch (PatchFailedException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>io.github.java-diff-utils</groupId>
|
<groupId>io.github.java-diff-utils</groupId>
|
||||||
<artifactId>java-diff-utils-parent</artifactId>
|
<artifactId>java-diff-utils-parent</artifactId>
|
||||||
<version>4.8</version>
|
<version>4.9</version>
|
||||||
<name>java-diff-utils-parent</name>
|
<name>java-diff-utils-parent</name>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
<connection>scm:git:https://github.com/java-diff-utils/java-diff-utils.git</connection>
|
<connection>scm:git:https://github.com/java-diff-utils/java-diff-utils.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@github.com:java-diff-utils/java-diff-utils.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@github.com:java-diff-utils/java-diff-utils.git</developerConnection>
|
||||||
<url>https://github.com/java-diff-utils/java-diff-utils.git</url>
|
<url>https://github.com/java-diff-utils/java-diff-utils.git</url>
|
||||||
<tag>java-diff-utils-parent-4.8</tag>
|
<tag>java-diff-utils-parent-4.9</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<issueManagement>
|
<issueManagement>
|
||||||
<system>GitHub Issues</system>
|
<system>GitHub Issues</system>
|
||||||
|
|||||||
Reference in New Issue
Block a user