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