// (c) MIT 2003.  All rights reserved.

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	Parameter.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	July, 1998
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:     Support for variable argument functions
//
////////////////////////////////////////////////////////////////////////////////

package rec.util;

import java.util.*;

/**
 * Parameter provides support for variable argument functions.
 *
 * For example,
 *
 * Parameter.add( 2.0 ).add( 2.0 )
 *
 *     would allow function to take in the doubles 2.0 and 1.0.
 *
 * The parameters method is then used by the function to
 *     traverse through the arguments.  Primitive types have
 *     all been converted to their corresponding object types.
 *
 * Functions that accept variable argument lists accept a
 *     argument of type Parameters.
 *
 * There is some function call overhead, but it should not
 *     matter unless speed is absolutely critical.
 */
public final class Parameter
{
  /**
   * Provides support for objects (Object), strings (String),
   *     and nulls (null).
   */
  public static Parameters add( Object o )
  {
    return( new Parameters( o ) );
  }

  public static Parameters add( boolean b )
  {
    return( new Parameters( new Boolean( b ) ) );
  }

  public static Parameters add( byte b )
  {
    return( new Parameters( new Byte( b ) ) );
  }

  public static Parameters add( char c )
  {
    return( new Parameters( new Character( c ) ) );
  }

  public static Parameters add( short s )
  {
    return( new Parameters( new Short( s ) ) );
  }

  public static Parameters add( int i )
  {
    return( new Parameters( new Integer( i ) ) );
  }

  public static Parameters add( long l )
  {
    return( new Parameters( new Long( l ) ) );
  }

  public static Parameters add( float f )
  {
    return( new Parameters( new Float( f ) ) );
  }

  public static Parameters add( double d )
  {
    return( new Parameters( new Double( d ) ) );
  }
}

final class Parameters
{
  public Parameters( Object o )
  {
    m_Vector = new Vector();

    m_Vector.addElement( o );
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
   * Provides support for objects (Object), strings (String),
   *     and nulls (null).
   */
  public Parameters add( Object o )
  {
    return( append( o ) );
  }

  public Parameters add( boolean b )
  {
    return( append( new Boolean( b ) ) );
  }

  public Parameters add( byte b )
  {
    return( append( new Byte( b ) ) );
  }

  public Parameters add( char c )
  {
    return( append( new Character( c ) ) );
  }

  public Parameters add( short s )
  {
    return( append( new Short( s ) ) );
  }

  public Parameters add( int i )
  {
    return( append( new Integer( i ) ) );
  }

  public Parameters add( long l )
  {
    return( append( new Long( l ) ) );
  }

  public Parameters add( float f )
  {
    return( append( new Float( f ) ) );
  }

  public Parameters add( double d )
  {
    return( append( new Double( d ) ) );
  }

  //////////////////////////////////////////////////////////////////////////////

  public int getLength()
  {
    return( m_Vector.size() );
  }

  public Iterator parameters()
  {
    return( m_Vector.iterator() );
  }

  //////////////////////////////////////////////////////////////////////////////

  private Parameters append( Object o )
  {
    m_Vector.addElement( o );

    return( this );
  }

  //////////////////////////////////////////////////////////////////////////////

  private Vector m_Vector;
}

////////////////////////////////////////////////////////////////////////////////
