2121 * Describes the delta between original and revised texts.
2222 *
2323 * @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
24+ * @param T The type of the compared elements in the 'lines'.
2425 */
25- public abstract class Delta {
26- private Chunk original ;
27- private Chunk revised ;
26+ public abstract class Delta <T > {
27+
28+ /** The original chunk. */
29+ private Chunk <T > original ;
2830
31+ /** The revised chunk. */
32+ private Chunk <T > revised ;
33+
34+ /**
35+ * Specifies the type of the delta.
36+ *
37+ */
2938 public enum TYPE {
30- CHANGE , DELETE , INSERT
39+ /** A change in the original. */
40+ CHANGE ,
41+ /** A delete from the original. */
42+ DELETE ,
43+ /** An insert into the original. */
44+ INSERT
3145 }
3246
3347 /**
3448 * Construct the delta for original and revised chunks
3549 *
36- * @param original chunk describes the original text
37- * @param revised chunk describes the revised text
50+ * @param original Chunk describing the original text. Must not be {@code null}.
51+ * @param revised Chunk describing the revised text. Must not be {@code null}.
3852 */
39- public Delta (Chunk original , Chunk revised ) {
53+ public Delta (Chunk <T > original , Chunk <T > revised ) {
54+ if (original == null ) {
55+ throw new IllegalArgumentException ("original must not be null" );
56+ }
57+ if (revised == null ) {
58+ throw new IllegalArgumentException ("revised must not be null" );
59+ }
4060 this .original = original ;
4161 this .revised = revised ;
4262 }
@@ -47,23 +67,23 @@ public Delta(Chunk original, Chunk revised) {
4767 * @param target the text to patch.
4868 * @throws PatchFailedException if the patch cannot be applied.
4969 */
50- public abstract void verify (List <? > target ) throws PatchFailedException ;
70+ public abstract void verify (List <T > target ) throws PatchFailedException ;
5171
5272 /**
5373 * Applies this delta as the patch for a given target
5474 *
5575 * @param target the given target
5676 * @throws PatchFailedException
5777 */
58- public abstract void applyTo (List <Object > target ) throws PatchFailedException ;
78+ public abstract void applyTo (List <T > target ) throws PatchFailedException ;
5979
6080 /**
6181 * Cancel this delta for a given revised text. The action is opposite to
6282 * patch.
6383 *
6484 * @param target the given revised text
6585 */
66- public abstract void restore (List <Object > target );
86+ public abstract void restore (List <T > target );
6787
6888 /**
6989 * Returns the type of delta
@@ -72,38 +92,33 @@ public Delta(Chunk original, Chunk revised) {
7292 public abstract TYPE getType ();
7393
7494 /**
75- * @return the Chunk describing the original text
95+ * @return The Chunk describing the original text.
7696 */
77- public Chunk getOriginal () {
97+ public Chunk < T > getOriginal () {
7898 return original ;
7999 }
80100
81101 /**
82- * @param original the Chunk describing the original text to set
102+ * @param original The Chunk describing the original text to set.
83103 */
84- public void setOriginal (Chunk original ) {
104+ public void setOriginal (Chunk < T > original ) {
85105 this .original = original ;
86106 }
87107
88108 /**
89- * @return the Chunk describing the revised text
109+ * @return The Chunk describing the revised text.
90110 */
91- public Chunk getRevised () {
111+ public Chunk < T > getRevised () {
92112 return revised ;
93113 }
94114
95115 /**
96- * @param revised the Chunk describing the revised text to set
116+ * @param revised The Chunk describing the revised text to set.
97117 */
98- public void setRevised (Chunk revised ) {
118+ public void setRevised (Chunk < T > revised ) {
99119 this .revised = revised ;
100120 }
101121
102- /*
103- * (non-Javadoc)
104- *
105- * @see java.lang.Object#hashCode()
106- */
107122 @ Override
108123 public int hashCode () {
109124 final int prime = 31 ;
@@ -113,11 +128,6 @@ public int hashCode() {
113128 return result ;
114129 }
115130
116- /*
117- * (non-Javadoc)
118- *
119- * @see java.lang.Object#equals(java.lang.Object)
120- */
121131 @ Override
122132 public boolean equals (Object obj ) {
123133 if (this == obj )
@@ -126,7 +136,7 @@ public boolean equals(Object obj) {
126136 return false ;
127137 if (getClass () != obj .getClass ())
128138 return false ;
129- Delta other = (Delta ) obj ;
139+ Delta < T > other = (Delta ) obj ;
130140 if (original == null ) {
131141 if (other .original != null )
132142 return false ;
0 commit comments