/* $Id: DefinitionVo.java,v 1.7 2005/12/09 18:23:55 m31 Exp $
 *
 * This file is part of the project "Hilbert II" - http://www.qedeq.org
 *
 * Copyright 2000-2005,  Michael Meyling <mime@qedeq.org>.
 *
 * "Hilbert II" is free software; you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 */

package org.qedeq.kernel.dto.module;

import org.qedeq.kernel.base.module.Axiom;
import org.qedeq.kernel.base.module.Definition;
import org.qedeq.kernel.base.module.FormulaOrTerm;
import org.qedeq.kernel.base.module.LatexList;
import org.qedeq.kernel.base.module.Proposition;
import org.qedeq.kernel.base.module.Rule;
import org.qedeq.kernel.base.module.VariableList;
import org.qedeq.kernel.utility.EqualsUtility;


/**
 * Definition of operator. This might be a predicate or function constant. For example
 * the predicate "x is a set" could be defined in MK with the formulaOrTerm
 * <code>\exists y: x \in y</code>.
 * <p>
 * There must also be the possibility to define basic predicate constants like
 * "x is element of y".
 *
 * @version $Revision: 1.7 $
 * @author  Michael Meyling
 */
public final class DefinitionVo implements Definition {

    /** Definition type. For example: this a predicate definition, a function definition. */
    private String type;

    /** Carries information about the argument number the defined object needs.  */
    private String argumentNumber;

    /** LaTeX pattern for definition visualisation. The replaceable arguments must are
     * marked as <code>#1</code>, <code>#2</code> and so on. For example
     * <code>\mathfrak{M}(#1)</code> */
    private String latexPattern;

    /** List of formula or subject variables to be replaced in the LaTeX pattern.
     * Could be <code>null</code>.*/
    private VariableList variableList;

    /** Formula or term that defines the object. Could be <code>null</code>. */
    private FormulaOrTerm formulaOrTerm;

    /** Further proposition description. Normally <code>null</code>. */
    private LatexList description;

    /**
     * Constructs a new definition.
     */
    public DefinitionVo() {
        // nothing to do
    }

    public Axiom getAxiom() {
        return null;
    }

    public Definition getDefinition() {
        return this;
    }

    public Proposition getProposition() {
        return null;
    }

    public Rule getRule() {
        return null;
    }

    /**
     * Set definition type. For example: this a predicate definition, a function definition.
     *
     * @param   type    Definition type.
     */
    public final void setType(final String type) {
        this.type = type;
    }

    public final String getType() {
        return type;
    }

    /**
     * Set information about the argument number the defined object needs.
     *
     * @param   argumentNumber  Argument number information.
     */
    public final void setArgumentNumber(final String argumentNumber) {
        this.argumentNumber = argumentNumber;
    }

    public final String getArgumentNumber() {
        return argumentNumber;
    }

    /**
     * Set LaTeX pattern for definition visualisation. The replaceable arguments are
     * marked as <code>#1</code>, <code>#2</code> and so on. For example
     * <code>\mathfrak{M}(#1)</code>.
     *
     * @param   latexPattern    LaTeX pattern for definition visualisation.
     */
    public final void setLatexPattern(final String latexPattern) {
        this.latexPattern = latexPattern;
    }

    public final String getLatexPattern() {
        return latexPattern;
    }

    /**
     * Set list of formula or subject variables to be replaced in the LaTeX pattern.
     * Could be <code>null</code>.
     *
     * @param   variables   Variable list for replacement.
     */
    public final void setVariableList(final VariableList variables) {
        this.variableList = variables;
    }

    public final VariableList getVariableList() {
        return variableList;
    }

    /**
     * Set defining formula or term that defines the object. Could be <code>null</code>.
     *
     * @param   formulaOrTerm   Formula or term that defines the new operator.
     */
    public final void setFormulaOrTerm(final FormulaOrTerm formulaOrTerm) {
        this.formulaOrTerm = formulaOrTerm;
    }

    public final FormulaOrTerm getFormulaOrTerm() {
        return formulaOrTerm;
    }

    /**
     * Set description. Only necessary if formula is not self-explanatory.
     *
     * @param   description Description.
     */
    public final void setDescription(final LatexList description) {
        this.description = description;
    }

    public LatexList getDescription() {
        return description;
    }

    public boolean equals(final Object obj) {
        if (!(obj instanceof Definition)) {
            return false;
        }
        final Definition other = (Definition) obj;
        return  EqualsUtility.equals(getType(), other.getType())
            &&  EqualsUtility.equals(getArgumentNumber(), other.getArgumentNumber())
            &&  EqualsUtility.equals(getLatexPattern(), other.getLatexPattern())
            &&  EqualsUtility.equals(getVariableList(), other.getVariableList())
            &&  EqualsUtility.equals(getFormulaOrTerm(), other.getFormulaOrTerm())
            &&  EqualsUtility.equals(getDescription(), other.getDescription());
    }

    public int hashCode() {
        return (getType() != null ? getType().hashCode() : 0)
            ^ (getArgumentNumber() != null ? getArgumentNumber().hashCode() : 0)
            ^ (getLatexPattern() != null ? 1 ^ getLatexPattern().hashCode() : 0)
            ^ (getVariableList() != null ? 2 ^ getVariableList().hashCode() : 0)
            ^ (getFormulaOrTerm() != null ? 3 ^ getFormulaOrTerm().hashCode() : 0)
            ^ (getDescription() != null ? 4 ^ getDescription().hashCode() : 0);
    }

    public String toString() {
        final StringBuffer buffer = new StringBuffer();
        buffer.append("Definition Type=" + getType() + " arguments=" + getArgumentNumber() + "\n");
        buffer.append("\tpattern=" + getLatexPattern() + "\n");
        buffer.append("\tvariables=" + getVariableList() + "\n");
        buffer.append("\tformula/term:\n" + getFormulaOrTerm() + "\n");
        buffer.append("\tdescription:\n" + getDescription() + "\n");
        return buffer.toString();
    }

}
