Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4ee56d2

Browse files
authored
make patch serializable (#101)
1 parent21f9e9d commit4ee56d2

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

‎java-diff-utils/src/main/java/com/github/difflib/patch/AbstractDelta.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*/
1616
packagecom.github.difflib.patch;
1717

18+
importjava.io.Serializable;
1819
importjava.util.List;
1920
importjava.util.Objects;
2021

2122
/**
2223
* Abstract delta between a source and a target.
2324
* @author Tobias Warneke (t.warneke@gmx.net)
2425
*/
25-
publicabstractclassAbstractDelta<T> {
26+
publicabstractclassAbstractDelta<T>implementsSerializable{
2627
privatefinalChunk<T>source;
2728
privatefinalChunk<T>target;
2829
privatefinalDeltaTypetype;

‎java-diff-utils/src/main/java/com/github/difflib/patch/Chunk.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
packagecom.github.difflib.patch;
1717

18+
importjava.io.Serializable;
1819
importjava.util.ArrayList;
1920
importjava.util.Arrays;
2021
importjava.util.List;
@@ -33,7 +34,7 @@
3334
* @author <a href="dm.naumenko@gmail.com>Dmitry Naumenko</a>
3435
* @param <T> The type of the compared elements in the 'lines'.
3536
*/
36-
publicfinalclassChunk<T> {
37+
publicfinalclassChunk<T>implementsSerializable{
3738

3839
privatefinalintposition;
3940
privateList<T>lines;

‎java-diff-utils/src/main/java/com/github/difflib/patch/Patch.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
importstaticjava.util.Comparator.comparing;
2323
importcom.github.difflib.algorithm.Change;
24+
25+
importjava.io.Serializable;
2426
importjava.util.ArrayList;
2527
importjava.util.Collections;
2628
importjava.util.List;
@@ -32,7 +34,7 @@
3234
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
3335
* @param <T> The type of the compared elements in the 'lines'.
3436
*/
35-
publicfinalclassPatch<T> {
37+
publicfinalclassPatch<T>implementsSerializable{
3638

3739
privatefinalList<AbstractDelta<T>>deltas;
3840

‎java-diff-utils/src/test/java/com/github/difflib/patch/PatchTest.java‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
packagecom.github.difflib.patch;
22

3-
importcom.github.difflib.DiffUtils;
4-
importjava.util.Arrays;
5-
importjava.util.List;
63
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
74
importstaticorg.junit.jupiter.api.Assertions.fail;
5+
6+
importjava.io.ByteArrayInputStream;
7+
importjava.io.ByteArrayOutputStream;
8+
importjava.io.IOException;
9+
importjava.io.ObjectInputStream;
10+
importjava.io.ObjectOutputStream;
11+
importjava.util.Arrays;
12+
importjava.util.List;
13+
814
importorg.junit.jupiter.api.Test;
915

16+
importcom.github.difflib.DiffUtils;
17+
1018
publicclassPatchTest {
1119

1220
@Test
@@ -47,4 +55,27 @@ public void testPatch_Change() {
4755
fail(e.getMessage());
4856
}
4957
}
58+
59+
@Test
60+
publicvoidtestPatch_Serializable()throwsIOException,ClassNotFoundException {
61+
finalList<String>changeTest_from =Arrays.asList("aaa","bbb","ccc","ddd");
62+
finalList<String>changeTest_to =Arrays.asList("aaa","bxb","cxc","ddd");
63+
64+
finalPatch<String>patch =DiffUtils.diff(changeTest_from,changeTest_to);
65+
ByteArrayOutputStreambaos =newByteArrayOutputStream();
66+
ObjectOutputStreamout =newObjectOutputStream(baos);
67+
out.writeObject(patch);
68+
out.close();
69+
ByteArrayInputStreambais =newByteArrayInputStream(baos.toByteArray());
70+
ObjectInputStreamin =newObjectInputStream(bais);
71+
Patch<String>result = (Patch<String>)in.readObject();
72+
in.close();
73+
74+
try {
75+
assertEquals(changeTest_to,DiffUtils.patch(changeTest_from,result));
76+
}catch (PatchFailedExceptione) {
77+
fail(e.getMessage());
78+
}
79+
80+
}
5081
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp