01: /*
02: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.mandarax.kernel;
19:
20: /**
21: * Replacement of terms.
22: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
23: * @version 3.4 <7 March 05>
24: * @since 1.0
25: */
26: public class Replacement extends LObject {
27:
28: public Term original;
29: public Term replacement;
30:
31: /**
32: * Constructor.
33: */
34: public Replacement() {
35: super ();
36: }
37:
38: /**
39: * Constructor.
40: * @param o the original term
41: * @param r the term replacing the original term
42: */
43: public Replacement(Term o, Term r) {
44: super ();
45:
46: original = o;
47: replacement = r;
48: }
49:
50: /**
51: * Compares two objects.
52: * @return true if the objects are equal, false otherwise
53: * @param obj the object to compare
54: */
55: public boolean equals(Object obj) {
56: if ((obj != null) && (obj instanceof Replacement)) {
57: Replacement r = (Replacement) obj;
58:
59: return (original == null) ? r.original == null
60: : (r.original.equals(original) && (replacement == null)) ? r.replacement == null
61: : r.replacement.equals(replacement);
62: }
63:
64: return false;
65: }
66:
67: /**
68: * Get the hashcode of the object.
69: * @return the hash value of this object
70: */
71: public int hashCode() {
72: if (replacement == null) {
73: return (original == null) ? 0 : original.hashCode();
74: }
75:
76: if (original == null) {
77: return replacement.hashCode();
78: }
79:
80: return replacement.hashCode() ^ original.hashCode() * 31;
81: }
82:
83: /**
84: * Convert the object to a string.
85: * @return the string representation of this object
86: */
87: public String toString() {
88: return original.toString() + " / " + replacement.toString();
89: }
90: }
|