1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2007
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: Difference.java 2050 2010-12-09 15:31:45Z dmsmith $
21   */
22  package org.crosswire.common.diff;
23  
24  /**
25   * 
26   * Represents a single difference, consisting of an EditType and associated
27   * text.
28   * 
29   * @see gnu.lgpl.License for license details.<br>
30   *      The copyright to this program is held by it's authors.
31   * @author DM Smith [dmsmith555 at yahoo dot com]
32   */
33  public class Difference {
34      public Difference(EditType edit, String text) {
35          this.editType = edit;
36          this.text = text;
37      }
38  
39      /**
40       * @return the EditType
41       */
42      public EditType getEditType() {
43          return editType;
44      }
45  
46      /**
47       * @param newEditType
48       *            the EditType to set
49       */
50      public void setEditType(EditType newEditType) {
51          editType = newEditType;
52      }
53  
54      /**
55       * @return the text
56       */
57      public String getText() {
58          return text;
59      }
60  
61      /**
62       * @param newText
63       *            the text to set
64       */
65      public void setText(String newText) {
66          text = newText;
67      }
68  
69      /**
70       * @return the index
71       */
72      public int getIndex() {
73          return index;
74      }
75  
76      /**
77       * @param newIndex
78       *            the index to set
79       */
80      public void setIndex(int newIndex) {
81          index = newIndex;
82      }
83  
84      /**
85       * @param addText
86       *            the text to set
87       */
88      public void appendText(String addText) {
89          text += addText;
90      }
91  
92      /**
93       * @param addText
94       *            the text to set
95       */
96      public void appendText(char addText) {
97          text += addText;
98      }
99  
100     /**
101      * @param addText
102      *            the text to set
103      */
104     public void prependText(String addText) {
105         text = addText + text;
106     }
107 
108     /**
109      * @param addText
110      *            the text to set
111      */
112     public void prependText(char addText) {
113         text = addText + text;
114     }
115 
116     /*
117      * (non-Javadoc)
118      * 
119      * @see java.lang.Object#toString()
120      */
121     @Override
122     public String toString() {
123         return editType.toString() + ':' + text;
124     }
125 
126     /*
127      * (non-Javadoc)
128      * 
129      * @see java.lang.Object#hashCode()
130      */
131     @Override
132     public int hashCode() {
133         return 31 * editType.hashCode() + text.hashCode();
134     }
135 
136     /*
137      * (non-Javadoc)
138      * 
139      * @see java.lang.Object#equals(java.lang.Object)
140      */
141     @Override
142     public boolean equals(Object obj) {
143         if (this == obj) {
144             return true;
145         }
146 
147         if (obj == null || getClass() != obj.getClass()) {
148             return false;
149         }
150 
151         final Difference other = (Difference) obj;
152 
153         return editType.equals(other.editType) && text.equals(other.text);
154     }
155 
156     /**
157      * The edit to perform
158      */
159     private EditType editType;
160     private String text;
161     private int index;
162 
163 }
164