Skip to content

Commit 23539d9

Browse files
committed
refactored some packages
1 parent 3363b2c commit 23539d9

File tree

7 files changed

+33
-59
lines changed

7 files changed

+33
-59
lines changed

src/main/java/difflib/ChangeDelta.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
2424
* @param T The type of the compared elements in the 'lines'.
2525
*/
26-
public class ChangeDelta<T> extends Delta<T> {
26+
public final class ChangeDelta<T> extends Delta<T> {
2727

2828
/**
2929
* Creates a change delta with the two given chunks.
@@ -32,7 +32,7 @@ public class ChangeDelta<T> extends Delta<T> {
3232
* @param revised The original chunk. Must not be {@code null}.
3333
*/
3434
public ChangeDelta(Chunk<T> original, Chunk<T> revised) {
35-
super(original, revised);
35+
super(TYPE.CHANGE, original, revised);
3636
}
3737

3838
/**
@@ -89,9 +89,4 @@ public String toString() {
8989
return "[ChangeDelta, position: " + getOriginal().getPosition() + ", lines: "
9090
+ getOriginal().getLines() + " to " + getRevised().getLines() + "]";
9191
}
92-
93-
@Override
94-
public TYPE getType() {
95-
return Delta.TYPE.CHANGE;
96-
}
9792
}

src/main/java/difflib/DeleteDelta.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
2424
* @param T The type of the compared elements in the 'lines'.
2525
*/
26-
public class DeleteDelta<T> extends Delta<T> {
26+
public final class DeleteDelta<T> extends Delta<T> {
2727

2828
/**
2929
* Creates a change delta with the two given chunks.
@@ -32,7 +32,7 @@ public class DeleteDelta<T> extends Delta<T> {
3232
* @param revised The original chunk. Must not be {@code null}.
3333
*/
3434
public DeleteDelta(Chunk<T> original, Chunk<T> revised) {
35-
super(original, revised);
35+
super(TYPE.DELETE, original, revised);
3636
}
3737

3838
/**
@@ -62,11 +62,6 @@ public void restore(List<T> target) {
6262
}
6363
}
6464

65-
@Override
66-
public TYPE getType() {
67-
return Delta.TYPE.DELETE;
68-
}
69-
7065
@Override
7166
public void verify(List<T> target) throws PatchFailedException {
7267
getOriginal().verify(target);

src/main/java/difflib/Delta.java

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,15 @@
2525
*/
2626
public abstract class Delta<T> {
2727

28-
/**
29-
* The original chunk.
30-
*/
31-
private Chunk<T> original;
32-
33-
/**
34-
* The revised chunk.
35-
*/
36-
private Chunk<T> revised;
28+
private final TYPE deltaType;
29+
private final Chunk<T> original;
30+
private final Chunk<T> revised;
3731

3832
/**
3933
* Specifies the type of the delta.
4034
*
4135
*/
42-
public enum TYPE {
36+
public static enum TYPE {
4337
/**
4438
* A change in the original.
4539
*/
@@ -60,13 +54,17 @@ public enum TYPE {
6054
* @param original Chunk describing the original text. Must not be {@code null}.
6155
* @param revised Chunk describing the revised text. Must not be {@code null}.
6256
*/
63-
public Delta(Chunk<T> original, Chunk<T> revised) {
57+
public Delta(TYPE deltaType, Chunk<T> original, Chunk<T> revised) {
58+
if (deltaType == null) {
59+
throw new IllegalArgumentException("deltaType must not be null");
60+
}
6461
if (original == null) {
6562
throw new IllegalArgumentException("original must not be null");
6663
}
6764
if (revised == null) {
6865
throw new IllegalArgumentException("revised must not be null");
6966
}
67+
this.deltaType = deltaType;
7068
this.original = original;
7169
this.revised = revised;
7270
}
@@ -94,12 +92,9 @@ public Delta(Chunk<T> original, Chunk<T> revised) {
9492
*/
9593
public abstract void restore(List<T> target);
9694

97-
/**
98-
* Returns the type of delta
99-
*
100-
* @return the type enum
101-
*/
102-
public abstract TYPE getType();
95+
public final TYPE getType() {
96+
return deltaType;
97+
}
10398

10499
/**
105100
* @return The Chunk describing the original text.
@@ -108,27 +103,13 @@ public Chunk<T> getOriginal() {
108103
return original;
109104
}
110105

111-
/**
112-
* @param original The Chunk describing the original text to set.
113-
*/
114-
public void setOriginal(Chunk<T> original) {
115-
this.original = original;
116-
}
117-
118106
/**
119107
* @return The Chunk describing the revised text.
120108
*/
121109
public Chunk<T> getRevised() {
122110
return revised;
123111
}
124112

125-
/**
126-
* @param revised The Chunk describing the revised text to set.
127-
*/
128-
public void setRevised(Chunk<T> revised) {
129-
this.revised = revised;
130-
}
131-
132113
@Override
133114
public int hashCode() {
134115
final int prime = 31;

src/main/java/difflib/InsertDelta.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
2424
* @param T The type of the compared elements in the 'lines'.
2525
*/
26-
public class InsertDelta<T> extends Delta<T> {
26+
public final class InsertDelta<T> extends Delta<T> {
2727

2828
/**
2929
* Creates an insert delta with the two given chunks.
@@ -32,7 +32,7 @@ public class InsertDelta<T> extends Delta<T> {
3232
* @param revised The original chunk. Must not be {@code null}.
3333
*/
3434
public InsertDelta(Chunk<T> original, Chunk<T> revised) {
35-
super(original, revised);
35+
super(TYPE.INSERT, original, revised);
3636
}
3737

3838
/**
@@ -71,11 +71,6 @@ public void verify(List<T> target) throws PatchFailedException {
7171

7272
}
7373

74-
@Override
75-
public TYPE getType() {
76-
return Delta.TYPE.INSERT;
77-
}
78-
7974
@Override
8075
public String toString() {
8176
return "[InsertDelta, position: " + getOriginal().getPosition()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
package difflib;
16+
package difflib.rows;
1717

1818
/**
1919
* Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two

src/main/java/difflib/DiffRowGenerator.java renamed to src/main/java/difflib/rows/DiffRowGenerator.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
package difflib;
17-
18-
import difflib.DiffRow.Tag;
16+
package difflib.rows;
17+
18+
import difflib.ChangeDelta;
19+
import difflib.Chunk;
20+
import difflib.DeleteDelta;
21+
import difflib.Delta;
22+
import difflib.rows.DiffRow.Tag;
23+
import difflib.DiffUtils;
24+
import difflib.InsertDelta;
25+
import difflib.Patch;
26+
import difflib.StringUtils;
1927
import difflib.myers.Equalizer;
2028
import java.util.*;
2129

src/test/java/diffutils/DiffRowGeneratorTest.java renamed to src/test/java/diffutils/rows/DiffRowGeneratorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package diffutils;
1+
package diffutils.rows;
22

3-
import difflib.DiffRow;
4-
import difflib.DiffRowGenerator;
3+
import difflib.rows.DiffRow;
4+
import difflib.rows.DiffRowGenerator;
55
import java.util.Arrays;
66
import java.util.List;
77
import static org.junit.Assert.assertEquals;

0 commit comments

Comments
 (0)