// $Id: AbstractArgumentList.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.argument;



/**
 * Every Operator must inherit from this class. Its main function is to
 * provide the standard implemention of {@link #equals}, {@link #matches}
 * and {@link #hashCode}.
 *
 * @version $Revision: 1.5 $
 * @author  Michael Meyling
 */
public abstract class AbstractArgumentList
        extends AbstractArgument implements Argument {

    /** remember constructor argument */
    private Argument arguments[] = null;


    /**
     * Constructs an argument list.
     *
     * @param  arguments the arguments to make a list of
     * @throws IllegalArgumentException if the argument was a
     *         nullpointer
     */
    public AbstractArgumentList(final Argument[] arguments) {
        if (arguments == null) {
            throw new IllegalArgumentException(
                ArgumentConstants.NULLPOINTER_PARAMETER);
        }
        this.arguments = arguments;
    }


    /** @inherited */
    public final int getArgumentSize() {
        return arguments.length;
    };


    /** @inherited */
    public final Argument getArgument(final int i)
            throws IllegalArgumentException {
        if (i >= 0 && i < arguments.length) {
            return arguments[i];
        } else {
            if (arguments.length == 0)  {
                throw new IllegalArgumentException(
                    ArgumentConstants.NO_ARGUMENT_NUMBER);
            } else {
                throw new IllegalArgumentException(
                    ArgumentConstants.WRONG_ARGUMENT_NUMBER + "{0"
                    + (arguments.length > 1 ? ", .. "
                    + (arguments.length - 1) : "")
                    + "}");
            }
        }
    }


    /** @inherited */
    public final Argument copy() {
        return this;    // TODO no deep copy ok???
/*
        final Argument[] copied = new Argument[argument.length];
        for (int i = 0; i < argument.length; i++) {
            copied[i] = argument[i].copy();
        }
        return create(copied);
*/
    }


    /** @inherited */
    public abstract Argument create(final Argument[] arguments)
        throws ArgumentException;


    /** @inherited */
    public abstract String toString();

}
