/* $Id: RuleBo.java,v 1.3 2005/12/10 08:10:56 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.LatexList;
import org.qedeq.kernel.base.module.LinkList;
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;


/**
 * Rule declaration.
 *
 * @version $Revision: 1.3 $
 * @author  Michael Meyling
 */
public final class RuleBo implements Rule {

    /** Rule name. */
    private String name;

    /** List of necessary ids. */
    private LinkListBo linkList;

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

    /** Proofs for this rule. */
    private ProofList proofList;

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

    public Axiom getAxiom() {
        return null;
    }

    public Definition getDefinition() {
        return null;
    }

    public Proposition getProposition() {
        return null;
    }

    public Rule getRule() {
        return this;
    }

    /**
     * Set id list.
     *
     * @param   linkList   Link list.
     */
    public final void setLinkList(final LinkListBo linkList) {
        this.linkList = linkList;
    }

    public final LinkList getLinkList() {
        return linkList;
    }

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

    public final ProofList getProofList() {
        return proofList;
    }

    /**
     * Set rule name.
     *
     * @param   name    Rule name.
     */
    public final void setName(final String name) {
        this.name = name;
    }

    public final String getName() {
        return name;
    }

    /**
     * Add link for this rule.
     *
     * @param   id  Id to add.
     */
    public final void addLink(final String id) {
        if (linkList == null) {
            linkList = new LinkListBo();
        }
        linkList.add(id);
    }

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

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

    public String toString() {
        final StringBuffer buffer = new StringBuffer();
        buffer.append("Rule: " + getName() + "\n");
        buffer.append("Links:\n");
        buffer.append(getLinkList());
        buffer.append("Description:\n");
        buffer.append(getDescription());
        buffer.append("Proofs:\n");
        buffer.append(getProofList());
        return buffer.toString();
    }

}
