| Difference.java |
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 or later
5 * as published by the Free Software Foundation. This program is distributed
6 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7 * the 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 * © CrossWire Bible Society, 2007 - 2016
18 *
19 */
20 package org.crosswire.common.diff;
21
22 /**
23 *
24 * Represents a single difference, consisting of an EditType and associated
25 * text.
26 *
27 * @see gnu.lgpl.License The GNU Lesser General Public License for details.
28 * @author DM Smith
29 */
30 public class Difference {
31 public Difference(EditType edit, String text) {
32 this.editType = edit;
33 this.text = text;
34 }
35
36 /**
37 * @return the EditType
38 */
39 public EditType getEditType() {
40 return editType;
41 }
42
43 /**
44 * @param newEditType
45 * the EditType to set
46 */
47 public void setEditType(EditType newEditType) {
48 editType = newEditType;
49 }
50
51 /**
52 * @return the text
53 */
54 public String getText() {
55 return text;
56 }
57
58 /**
59 * @param newText
60 * the text to set
61 */
62 public void setText(String newText) {
63 text = newText;
64 }
65
66 /**
67 * @return the index
68 */
69 public int getIndex() {
70 return index;
71 }
72
73 /**
74 * @param newIndex
75 * the index to set
76 */
77 public void setIndex(int newIndex) {
78 index = newIndex;
79 }
80
81 /**
82 * @param addText
83 * the text to set
84 */
85 public void appendText(String addText) {
86 text += addText;
87 }
88
89 /**
90 * @param addText
91 * the text to set
92 */
93 public void appendText(char addText) {
94 text += addText;
95 }
96
97 /**
98 * @param addText
99 * the text to set
100 */
101 public void prependText(String addText) {
102 text = addText + text;
103 }
104
105 /**
106 * @param addText
107 * the text to set
108 */
109 public void prependText(char addText) {
110 text = addText + text;
111 }
112
113 /*
114 * (non-Javadoc)
115 *
116 * @see java.lang.Object#toString()
117 */
118 @Override
119 public String toString() {
120 return editType.toString() + ':' + text;
121 }
122
123 /*
124 * (non-Javadoc)
125 *
126 * @see java.lang.Object#hashCode()
127 */
128 @Override
129 public int hashCode() {
130 return 31 * editType.hashCode() + text.hashCode();
131 }
132
133 /*
134 * (non-Javadoc)
135 *
136 * @see java.lang.Object#equals(java.lang.Object)
137 */
138 @Override
139 public boolean equals(Object obj) {
140 if (this == obj) {
141 return true;
142 }
143
144 if (obj == null || getClass() != obj.getClass()) {
145 return false;
146 }
147
148 final Difference other = (Difference) obj;
149
150 return editType.equals(other.editType) && text.equals(other.text);
151 }
152
153 /**
154 * The edit to perform
155 */
156 private EditType editType;
157 private String text;
158 private int index;
159
160 }
161