// $Id: ProofLine.java,v 1.5 2004/02/27 16:30:00 m31 Exp $
//
// This file is part of the program suite "Principia Mathematica II"
// which is a working prototype for the main project:
// "Hilbert II" - http://www.qedeq.org
//
// Copyright 2001-2004  Michael Meyling <mime@qedeq.org>.
//
// "Principia Mathematica 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 com.meyling.principia.logic.paragraph;


import com.meyling.principia.argument.AbstractArgumentList;
import com.meyling.principia.argument.Argument;
import com.meyling.principia.argument.ArgumentException;
import com.meyling.principia.logic.basic.Formula;
import com.meyling.principia.logic.rule.Rule;
import com.meyling.principia.module.ModuleCreator;


/**
 * A proof line of a mathematical proof.
 *
 * @version $Revision: 1.5 $
 * @author  Michael Meyling
 */
public class ProofLine extends AbstractArgumentList
        implements Argument {

    /**
     * Constructs a proof line made of a formula and a rule.
     *
     * @param   arguments    list of arguments
     * @throws  ArgumentException    if there are not exactly two
     *          arguments that are instances of
     *          {@link com.meyling.principia.logic.basic.Formula} and
     *          {@link Rule}.
     */
    public ProofLine(final Argument[] arguments)
            throws ArgumentException {
        super(arguments);
        if (arguments.length != 2) {
            throw new ArgumentException(
                ParagraphConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_NUMBER,
                ModuleCreator.getName(this.getClass())
                + ParagraphConstants.OPERATOR_WITH_TWO_ARGUMENTS);
        }
        if (!(arguments[0] instanceof Formula)) {
            throw new ArgumentException(
                ParagraphConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                ModuleCreator.getName(this.getClass())
                + ParagraphConstants.FIRST_ARGUMENT_TYPE
                + ParagraphConstants.FORMULA,
                arguments[0]);
        }
        if (arguments[0].containsPatternVariables()) {
            throw new ArgumentException(
                ParagraphConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                ModuleCreator.getName(this.getClass())
                + ParagraphConstants.FIRST_ARGUMENT
                + ParagraphConstants.MUST_NOT_CONTAIN_PATTERN_VARIABLE,
                arguments[0]);
        }
        if (!(arguments[1] instanceof Rule)) {
            throw new ArgumentException(
                ParagraphConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                ModuleCreator.getName(this.getClass())
                + ParagraphConstants.SECOND_ARGUMENT_TYPE
                + ParagraphConstants.RULE,
                arguments[1]);
        }
    }


    /** @inherited */
    public final Argument create(final Argument[] arguments)
            throws ArgumentException {
        return new ProofLine(arguments);
    }



    /** @inherited */
    public final String toString() {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < getArgumentSize(); i++) {
            if (i != 0) {
                buffer.append(", ");
            };
            buffer.append(getArgument(i));
        }
        return buffer.toString();
    }


}
