| CommonMiddle.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 * A CommonMiddle represents an overlap between a baseline/source text and a
24 * changed/target text.
25 *
26 * @see gnu.lgpl.License The GNU Lesser General Public License for details.
27 * @author DM Smith
28 */
29 public class CommonMiddle {
30 /**
31 * A CommonMiddle represents an overlap between a baseline/source text and a
32 * changed/target text.
33 *
34 * @param sourcePrefix
35 * The text before the commonality form the source
36 * @param sourceSuffix
37 * The text after the commonality form the source
38 * @param targetPrefix
39 * The text before the commonality form the target
40 * @param targetSuffix
41 * The text after the commonality form the target
42 * @param commonality
43 * The text in common
44 */
45 public CommonMiddle(String sourcePrefix, String sourceSuffix, String targetPrefix, String targetSuffix, String commonality) {
46 this.sourcePrefix = sourcePrefix;
47 this.sourceSuffix = sourceSuffix;
48 this.targetPrefix = targetPrefix;
49 this.targetSuffix = targetSuffix;
50 this.commonality = commonality;
51 }
52
53 /**
54 * @return the source start
55 */
56 public String getSourcePrefix() {
57 return sourcePrefix;
58 }
59
60 /**
61 * @return the target start
62 */
63 public String getTargetPrefix() {
64 return targetPrefix;
65 }
66
67 /**
68 * @return the commonality
69 */
70 public String getCommonality() {
71 return commonality;
72 }
73
74 /**
75 * @return the source end
76 */
77 public String getSourceSuffix() {
78 return sourceSuffix;
79 }
80
81 /**
82 * @return the target end
83 */
84 public String getTargetSuffix() {
85 return targetSuffix;
86 }
87
88 /*
89 * (non-Javadoc)
90 *
91 * @see java.lang.Object#toString()
92 */
93 @Override
94 public String toString() {
95 StringBuilder buf = new StringBuilder();
96 buf.append(sourcePrefix);
97 buf.append(',');
98 buf.append(sourceSuffix);
99 buf.append(',');
100 buf.append(targetPrefix);
101 buf.append(',');
102 buf.append(targetSuffix);
103 buf.append(',');
104 buf.append(commonality);
105 return buf.toString();
106 }
107
108 /*
109 * (non-Javadoc)
110 *
111 * @see java.lang.Object#hashCode()
112 */
113 @Override
114 public int hashCode() {
115 int result = 31 + ((sourcePrefix == null) ? 0 : sourcePrefix.hashCode());
116 result = 31 * result + ((sourceSuffix == null) ? 0 : sourceSuffix.hashCode());
117 result = 31 * result + ((targetPrefix == null) ? 0 : targetPrefix.hashCode());
118 result = 31 * result + ((targetSuffix == null) ? 0 : targetSuffix.hashCode());
119 return 31 * result + ((commonality == null) ? 0 : commonality.hashCode());
120 }
121
122 /*
123 * (non-Javadoc)
124 *
125 * @see java.lang.Object#equals(java.lang.Object)
126 */
127 @Override
128 public boolean equals(Object obj) {
129 if (this == obj) {
130 return true;
131 }
132
133 if (obj == null || getClass() != obj.getClass()) {
134 return false;
135 }
136
137 final CommonMiddle other = (CommonMiddle) obj;
138
139 return sourcePrefix.equals(other.sourcePrefix) && sourceSuffix.equals(other.sourceSuffix) && targetPrefix.equals(other.targetPrefix)
140 && targetSuffix.equals(other.targetSuffix) && commonality.equals(other.commonality);
141 }
142
143 private String sourcePrefix;
144 private String sourceSuffix;
145 private String targetPrefix;
146 private String targetSuffix;
147 private String commonality;
148 }
149