1+ /*
2+ Copyright 2009 Dmitry Naumenko (dm.naumenko@gmail.com)
3+
4+ This file is part of Java Diff Utills Library.
5+
6+ Java Diff Utills Library is free software: you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation, either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ Java Diff Utills Library is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ You should have received a copy of the GNU General Public License
17+ along with Java Diff Utills Library. If not, see <http://www.gnu.org/licenses/>.
18+ */
119package difflib ;
220
321import java .util .*;
@@ -22,12 +40,27 @@ public Delta(Chunk original, Chunk revised) {
2240 this .revised = revised ;
2341 }
2442
43+ /**
44+ * Verifies that this delta can be used to patch the given text.
45+ * @param target the text to patch.
46+ * @throws PatchFailedException if the patch cannot be applied.
47+ */
48+ public abstract void verify (List <?> target ) throws PatchFailedException ;
49+
2550 /**
2651 * Applies this delta as the patch for a given target
2752 *
28- * @param target the given target
53+ * @param target the given target
54+ * @throws PatchFailedException
55+ */
56+ public abstract void applyTo (List <Object > target ) throws PatchFailedException ;
57+
58+ /**
59+ * Cancel this delta for a given revised text. The action is opposite to patch.
60+ *
61+ * @param target the given revised text
2962 */
30- public abstract void applyTo (List <Object > target );
63+ public abstract void restore (List <Object > target );
3164
3265 /**
3366 * @return the Chunk describing the original text
@@ -54,4 +87,44 @@ public Chunk getRevised() {
5487 public void setRevised (Chunk revised ) {
5588 this .revised = revised ;
5689 }
90+
91+ /* (non-Javadoc)
92+ * @see java.lang.Object#hashCode()
93+ */
94+ @ Override
95+ public int hashCode () {
96+ final int prime = 31 ;
97+ int result = 1 ;
98+ result = prime * result
99+ + ((original == null ) ? 0 : original .hashCode ());
100+ result = prime * result + ((revised == null ) ? 0 : revised .hashCode ());
101+ return result ;
102+ }
103+
104+ /* (non-Javadoc)
105+ * @see java.lang.Object#equals(java.lang.Object)
106+ */
107+ @ Override
108+ public boolean equals (Object obj ) {
109+ if (this == obj )
110+ return true ;
111+ if (obj == null )
112+ return false ;
113+ if (getClass () != obj .getClass ())
114+ return false ;
115+ Delta other = (Delta ) obj ;
116+ if (original == null ) {
117+ if (other .original != null )
118+ return false ;
119+ } else if (!original .equals (other .original ))
120+ return false ;
121+ if (revised == null ) {
122+ if (other .revised != null )
123+ return false ;
124+ } else if (!revised .equals (other .revised ))
125+ return false ;
126+ return true ;
127+ }
128+
129+
57130}
0 commit comments