// $Id: PropositionVariable.java,v 1.6 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.basic;


import com.meyling.principia.argument.Argument;
import com.meyling.principia.argument.ArgumentException;
import com.meyling.principia.argument.Counter;
import com.meyling.principia.argument.CounterMarker;


/**
 * Represents an arbitrary logical proposition.
 *
 * @version $Revision: 1.6 $
 * @author  Michael Meyling
 */
public class PropositionVariable extends AbstractFormula
        implements Argument, Formula {

    /** number of proposition variable */
    private CounterMarker number;


    /**
     * Constructs a proposition variable.
     *
     * @param   arguments  first argument is number of this proposition
     *          variable
     * @throws  ArgumentException    if there is not exactly one
     *          argument that is an instance of {@link Counter}
     */
    public PropositionVariable(final Argument[] arguments)
            throws ArgumentException {
        super(arguments);
        if (arguments.length != 1) {
            throw new ArgumentException(
                BasicConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_NUMBER,
                BasicCreator.getName(PropositionVariable.class)
                + BasicConstants.OPERATOR_WITH_ONE_ARGUMENT);
        }
        if (!(arguments[0] instanceof CounterMarker)) {
            throw new ArgumentException(
                BasicConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                BasicCreator.getName(PropositionVariable.class)
                + BasicConstants.FIRST_ARGUMENT_TYPE
                + BasicConstants.COUNTER_OR_PATTERN,
                arguments[0]);
        }
        this.number = (CounterMarker) arguments[0];
    }


    /**
     * Constructs certain proposition variable.
     *
     * @param   number  number of proposition variable
     * @throws  ArgumentException    if Counter couldn't be created
     */
    public PropositionVariable(final int number)
            throws ArgumentException {
        this(new Argument[] { new Counter(number) } );
    }


    /**
     * Get the identity number of this proposition variable.
     *
     * @return  identity number
     */
    public int getNumber() {
        return number.getNumber();
    }


    /**
     * @inherited
     * @return  always 0
     */
    public final int getPartFormulaSize() {
        return 0;
    }


    /**
     * @inherited
     * @return  will never occur
     * @throw   IllegalArgumentException    always thrown
     */
    public final Formula getPartFormula(final int i) {
        throw new IllegalArgumentException(
            BasicConstants.NO_ARGUMENT_NUMBER);
    }


    /** @inherited */
    public final SubjectVariables getFreeSubjectVariables() {
        return new SubjectVariables();
    };


    /** @inherited */
    public final SubjectVariables getBoundSubjectVariables() {
        return new SubjectVariables();
    }


    /** @inherited */
    public final SubjectVariables getSubjectVariables() {
        return new SubjectVariables();
    }


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


    /** @inherited */
    public final String toString() {
        return "A" + number.toString();
    }


}
