/* $Id: SubsectionBo.java,v 1.2 2005/06/15 16:11:46 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.LatexList;
import org.qedeq.kernel.base.module.Subsection;
import org.qedeq.kernel.utility.EqualsUtility;


/**
 * Subsection of a qedeq file.
 *
 * @version $Revision: 1.2 $
 * @author  Michael Meyling
 */
public final class SubsectionBo implements Subsection {

    /** Label for referencing. */
    private String label;

    /** Level of that subsection. Higher levels contain additional informations. */
    private String level;

    /** Title of this subsection. */
    private LatexList title;

    /** LaTeX text.  */
    private LatexList latex;

    /**
     * Constructs a new empty subsection.
     */
    public SubsectionBo() {
        // nothing to do
    }

    /**
     * Set referencing label for this subsection.
     *
     * @param   label   Referencing label.
     */
    public final void setLabel(final String label) {
        this.label = label;
    }

    public final String getLabel() {
        return label;
    }

    /**
     * Set level of this section. Higher levels contain additional information.
     *
     * @param   level   Level.
     */
    public final void setLevel(final String level) {
        this.level = level;
    }

    public final String getLevel() {
        return level;
    }

    /**
     * Set title of this subsection.
     *
     * @param   title   Subsection title.
     */
    public final void setTitle(final LatexList title) {
        this.title = title;
    }

    public final LatexList getTitle() {
        return title;
    }

    /**
     * Set text of this subsection. This is the main content of the subsection.
     *
     * @param   latexText   Subsection text.
     */
    public final void setLatex(final LatexList latexText) {
        this.latex = latexText;
    }

    public final LatexList getLatex() {
        return latex;
    }

    public boolean equals(final Object obj) {
        if (!(obj instanceof SubsectionBo)) {
            return false;
        }
        final SubsectionBo subsection = (SubsectionBo) obj;
        return  EqualsUtility.equals(getLabel(), subsection.getLabel())
            &&  EqualsUtility.equals(getLevel(), subsection.getLevel())
            &&  EqualsUtility.equals(getTitle(), subsection.getTitle())
            &&  EqualsUtility.equals(getLatex(), subsection.getLatex());
    }

    public int hashCode() {
        return (getLabel() != null ? getLabel().hashCode() : 0)
            ^ (getLevel() != null ? 1 ^ getLevel().hashCode() : 0)
            ^ (getTitle() != null ? 2 ^ getTitle().hashCode() : 0)
            ^ (getLatex() != null ? 3 ^ getLatex().hashCode() : 0);
    }

    public String toString() {
        final StringBuffer buffer = new StringBuffer();
        buffer.append("Subsection\t");
        buffer.append("Label: " + getLabel());
        buffer.append("\tLevel: " + getLevel() + "\n");
        buffer.append("Title: ");
        buffer.append(getTitle() + "\n\n");
        buffer.append("Pre: ");
        buffer.append(getLatex() + "\n\n");
        return buffer.toString();
    }

}
