4 Commits

Author SHA1 Message Date
Tobias Warneke
1ec708fe30 [maven-release-plugin] prepare release java-diff-utils-parent-4.9 2020-11-01 21:32:21 +01:00
Tobias Warneke
fcf83e918f 2020-11-01 20:03:18 +01:00
Alon Harel
4ee56d2554 make patch serializable (#101) 2020-10-26 13:34:23 +01:00
Tobias Warneke
21f9e9d415 [maven-release-plugin] prepare for next development iteration 2020-09-27 22:08:04 +02:00
8 changed files with 47 additions and 10 deletions

View File

@@ -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

View File

@@ -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>

View File

@@ -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>

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

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

View File

@@ -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>