45 |
* @see Predicate |
* @see Predicate |
46 |
*/ |
*/ |
47 |
public class Triple |
public class Triple |
48 |
implements Serializable |
implements Serializable, Cloneable |
49 |
{ |
{ |
50 |
|
|
51 |
/** |
/** |
109 |
"]"; |
"]"; |
110 |
} |
} |
111 |
|
|
112 |
|
/** |
113 |
|
* Returns a deep copy of this triple. |
114 |
|
* |
115 |
|
* @return a clone of the triple. |
116 |
|
*/ |
117 |
|
public Triple clone() |
118 |
|
{ |
119 |
|
try |
120 |
|
{ |
121 |
|
Object clonedObject = super.clone(); |
122 |
|
Triple clone = (Triple) clonedObject; |
123 |
|
clone.setSubject(subject.clone()); |
124 |
|
clone.setPredicate(predicate.clone()); |
125 |
|
clone.setObject(object.clone()); |
126 |
|
return clone; |
127 |
|
} |
128 |
|
catch (CloneNotSupportedException e) |
129 |
|
{ |
130 |
|
throw new IllegalStateException("Unexpected exception: " + e, e); |
131 |
|
} |
132 |
|
} |
133 |
|
|
134 |
|
/** |
135 |
|
* Sets the subject of this triple to that specified. |
136 |
|
* |
137 |
|
* @param subject the new subject for this triple. |
138 |
|
*/ |
139 |
|
public void setSubject(Subject subject) |
140 |
|
{ |
141 |
|
this.subject = subject; |
142 |
|
} |
143 |
|
|
144 |
|
/** |
145 |
|
* Sets the predicate of this triple to that specified. |
146 |
|
* |
147 |
|
* @param predicate the new predicate for this triple. |
148 |
|
*/ |
149 |
|
public void setPredicate(Predicate predicate) |
150 |
|
{ |
151 |
|
this.predicate = predicate; |
152 |
|
} |
153 |
|
|
154 |
|
/** |
155 |
|
* Sets the object of this triple to that specified. |
156 |
|
* |
157 |
|
* @param object the new object for this triple. |
158 |
|
*/ |
159 |
|
public void setObject(RDFObject object) |
160 |
|
{ |
161 |
|
this.object = object; |
162 |
|
} |
163 |
|
|
164 |
|
/** |
165 |
|
* Returns true if the specified triple is equal to this one. |
166 |
|
* |
167 |
|
* @param object the object to compare. |
168 |
|
*/ |
169 |
|
public boolean equals(Object obj) |
170 |
|
{ |
171 |
|
if (obj == null) |
172 |
|
return false; |
173 |
|
if (obj == this) |
174 |
|
return true; |
175 |
|
if (obj.getClass() == getClass()) |
176 |
|
{ |
177 |
|
Triple triple = (Triple) obj; |
178 |
|
return subject.equals(triple.getSubject()) |
179 |
|
&& predicate.equals(triple.getPredicate()) |
180 |
|
&& object.equals(triple.getObject()); |
181 |
|
} |
182 |
|
return false; |
183 |
|
} |
184 |
|
|
185 |
|
/** |
186 |
|
* Returns the hashcode of this triple. This is calculated using |
187 |
|
* the hash codes of the subject, predicate and object. |
188 |
|
* |
189 |
|
* @return the hashcode for the triple. |
190 |
|
*/ |
191 |
|
public int hashCode() |
192 |
|
{ |
193 |
|
return super.hashCode() |
194 |
|
+ 13 * subject.hashCode() |
195 |
|
+ 17 * predicate.hashCode() |
196 |
|
+ 19 * object.hashCode(); |
197 |
|
} |
198 |
|
|
199 |
|
/** |
200 |
|
* Returns a clone of the triple's subject. |
201 |
|
* |
202 |
|
* @return a clone of the subject. |
203 |
|
*/ |
204 |
|
public Subject getSubject() |
205 |
|
{ |
206 |
|
return subject.clone(); |
207 |
|
} |
208 |
|
|
209 |
|
/** |
210 |
|
* Returns a clone of the triple's predicate. |
211 |
|
* |
212 |
|
* @return a clone of the predicate. |
213 |
|
*/ |
214 |
|
public Predicate getPredicate() |
215 |
|
{ |
216 |
|
return predicate.clone(); |
217 |
|
} |
218 |
|
|
219 |
|
/** |
220 |
|
* Returns a clone of the triple's object. |
221 |
|
* |
222 |
|
* @return a clone of the object. |
223 |
|
*/ |
224 |
|
public RDFObject getObject() |
225 |
|
{ |
226 |
|
return object.clone(); |
227 |
|
} |
228 |
|
|
229 |
} |
} |