/*
 * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.mandarax.kernel;


/**
 * Replacement of terms.
 * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
 * @version 3.3.1 <9 August 2004>
 * @since 1.0
 */
public class Replacement extends LObject {

    public Term original;
    public Term replacement;

    /**
     * Constructor.
     */
    public Replacement() {
        super ();
    }

    /**
     * Constructor.
     * @param o the original term
     * @param r the term replacing the original term
     */
    public Replacement(Term o, Term r) {
        super ();

        original    = o;
        replacement = r;
    }

    /**
     * Compares two objects.
     * @return true if the objects are equal, false otherwise
     * @param obj the object to compare
     */
    public boolean equals(Object obj) {
        if((obj != null) && (obj instanceof Replacement)) {
            Replacement r = (Replacement) obj;

            return(original == null)
                  ? r.original == null
                  : (r.original.equals (original) && (replacement == null))
                    ? r.replacement == null
                    : r.replacement.equals (replacement);
        }

        return false;
    }

    /**
     * Get the hashcode of the object.
     * @return the hash value of this object
     */
    public int hashCode() {
        if(replacement == null) {
            return(original == null)
                  ? 0
                  : original.hashCode ();
        }

        if(original == null) {
            return replacement.hashCode ();
        }

        return replacement.hashCode () ^ original.hashCode () * 31;
    }

    /**
     * Convert the object to a string.
     * @return the string representation of this object
     */
    public String toString() {
        return original.toString () + " / " + replacement.toString ();
    }
}
