/* $Id: PropositionBo.java,v 1.4 2005/12/09 18:23:32 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.bo.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.Proof;
import org.qedeq.kernel.base.module.ProofList;
import org.qedeq.kernel.base.module.Proposition;
import org.qedeq.kernel.base.module.Rule;
import org.qedeq.kernel.utility.EqualsUtility;


/**
 * Proposition.
 *
 * @version $Revision: 1.4 $
 * @author  Michael Meyling
 */
public final class PropositionBo implements Proposition {

    /** Proposition formula. */
    private FormulaOrTerm formula;

    /** List of proofs. */
    private ProofListBo proofList;

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

    /**
     * Constructs a new proposition.
     */
    public PropositionBo() {
        // nothing to do
    }

    public Axiom getAxiom() {
        return null;
    }

    public Definition getDefinition() {
        return null;
    }

    public Proposition getProposition() {
        return this;
    }

    public Rule getRule() {
        return null;
    }

    /**
     * Set proposition formula.
     *
     * @param   formula Proposition formula.
     */
    public final void setFormula(final FormulaOrTerm formula) {
        this.formula = formula;
    }

    public final FormulaOrTerm getFormula() {
        return formula;
    }

    /**
     * Set proof list of this proposition.
     *
     * @param   proofList   Proof list.
     */
    public final void setProofList(final ProofListBo proofList) {
        this.proofList = proofList;
    }

    public final ProofList getProofList() {
        return proofList;
    }

    /**
     * Add proof for this proposition.
     *
     * @param   proof   Proof to add.
     */
    public final void addProof(final Proof proof) {
        if (proofList == null) {
            proofList = new ProofListBo();
        }
        proofList.add(proof);
    }

    /**
     * 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 PropositionBo)) {
            return false;
        }
        final PropositionBo other = (PropositionBo) obj;
        return  EqualsUtility.equals(getFormula(), other.getFormula())
                && EqualsUtility.equals(getDescription(), other.getDescription())
                && EqualsUtility.equals(getProofList(), other.getProofList());
    }

    public int hashCode() {
        return (getFormula() != null ? getFormula().hashCode() : 0)
            ^ (getDescription() != null ? 1 ^ getDescription().hashCode() : 0)
            ^ (getProofList() != null ? 2 ^ getProofList().hashCode() : 0);
    }

    public String toString() {
        final StringBuffer buffer = new StringBuffer();
        buffer.append("Proposition:\n");
        buffer.append(getFormula());
        buffer.append("Description:\n");
        buffer.append(getDescription());
        buffer.append("Proof:\n");
        buffer.append(getProofList());
        return buffer.toString();
    }

}
