com.groovyj.jgprog.functions
Class Argument

java.lang.Object
  |
  +--com.groovyj.jgprog.Function
        |
        +--com.groovyj.jgprog.functions.Argument
All Implemented Interfaces:
java.io.Serializable

public class Argument
extends Function
implements java.io.Serializable

Represents an argument on a chromosome. World-creators should not use this class. Instances are generated automatically by chromosomes.

Copyright (c) 2000 Robert Baruch. This code is released under the GNU General Public License (GPL).

Version:
$Id: Argument.java,v 1.1 2000/10/12 15:19:39 groovyjava Exp $
Author:
Robert Baruch (jgprog@sourceforge.net)
See Also:
Serialized Form

Fields inherited from class com.groovyj.jgprog.Function
arity, individual, returnType
 
Method Summary
static Argument create(int num, int chromosomeNum, Type type)
          Creates an instance of an Argument.
 boolean execute_boolean(Chromosome c, int n)
          Executes this node as a boolean.
 double execute_double(Chromosome c, int n)
          Executes this node as a double.
 float execute_float(Chromosome c, int n)
          Executes this node as a float.
 int execute_int(Chromosome c, int n)
          Executes this node as an integer.
 long execute_long(Chromosome c, int n)
          Executes this node as a long.
 java.lang.Object execute_object(Chromosome c, int n)
          Executes this node as an object.
 java.lang.Object get()
          Gets the value of this argument.
static java.lang.Object get(int num)
          Gets the value of an argument without having to obtain a reference to the argument.
static Argument getArgument(int num, int chromosomeNum)
          Gets the one instance of a numbered argument.
 Type getChildType(int num)
          Gets the type of node allowed form the given child number.
 java.lang.String getName()
          Gets the name of this node.
 boolean isConstant()
           
static java.lang.Object[] newFrame(int n)
          Creates a new stack frame consisting of a number of arguments.
static void restoreFrame()
          Restores the previous stack frame.
static void set(int num, java.lang.Object value)
          Sets an argument without having to obtain a reference to the argument.
 void set(java.lang.Object value)
          Sets the value of this argument.
 
Methods inherited from class com.groovyj.jgprog.Function
execute_void, execute, getArity, getReturnType, setIndividual, setReturnType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static Argument create(int num,
                              int chromosomeNum,
                              Type type)
Creates an instance of an Argument. If an Argument of that name already exists, that is returned. Otherwise a new instance is created, and it is placed into the static hashtable for later retrieval by name via get or getArgument.
Parameters:
num - the number of the Argument to create
chromosomeNum - the number of chromosome this Argument belongs to
the - type of this Argument
Since:
1.0.1

getName

public java.lang.String getName()
Description copied from class: Function
Gets the name of this node. Must be overridden in subclasses.
Overrides:
getName in class Function
Following copied from class: com.groovyj.jgprog.Function
Returns:
the name of this node.

newFrame

public static java.lang.Object[] newFrame(int n)
Creates a new stack frame consisting of a number of arguments. Saves the original set of arguments and creates a new set of arguments. Used when calling chromosomes, where the previous argument values must be saved before the argument values are set.
Parameters:
n - the number of arguments the new frame should contain
Returns:
a reference to the new frame for convenience
Since:
1.0.1

restoreFrame

public static void restoreFrame()
Restores the previous stack frame. Used when returning from chromosomes, where the previous argument values must be restored.
Since:
1.0.1

set

public static void set(int num,
                       java.lang.Object value)
Sets an argument without having to obtain a reference to the argument.
Parameters:
num - the number of the argument to set
value - the value to set the argument with
Since:
1.0.1

get

public static java.lang.Object get(int num)
Gets the value of an argument without having to obtain a reference to the argument.
Parameters:
num - the number of the argument to get
Returns:
an Object representing the value of the argument
Since:
1.0.1

getArgument

public static Argument getArgument(int num,
                                   int chromosomeNum)
Gets the one instance of a numbered argument.
Parameters:
num - the number of the argument to get
chromosomeNum - the number of the chromosome from which to get the argument
Returns:
the argument, or null if that number wasn't found.
Since:
1.0.1

set

public void set(java.lang.Object value)
Sets the value of this argument.
Parameters:
value - the value to set this argument with
Since:
1.0.1

get

public java.lang.Object get()
Gets the value of this argument.
Returns:
an Object representing the value of this argument, or null if this argument has not yet been set.
Since:
1.0.1

execute_boolean

public boolean execute_boolean(Chromosome c,
                               int n)
Description copied from class: Function
Executes this node as a boolean.
Overrides:
execute_boolean in class Function
Following copied from class: com.groovyj.jgprog.Function
Returns:
the boolean return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not boolean

execute_int

public int execute_int(Chromosome c,
                       int n)
Description copied from class: Function
Executes this node as an integer.
Overrides:
execute_int in class Function
Following copied from class: com.groovyj.jgprog.Function
Returns:
the integer return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not integer

execute_long

public long execute_long(Chromosome c,
                         int n)
Description copied from class: Function
Executes this node as a long.
Overrides:
execute_long in class Function
Following copied from class: com.groovyj.jgprog.Function
Returns:
the long return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not long

execute_float

public float execute_float(Chromosome c,
                           int n)
Description copied from class: Function
Executes this node as a float.
Overrides:
execute_float in class Function
Following copied from class: com.groovyj.jgprog.Function
Returns:
the float return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not float

execute_double

public double execute_double(Chromosome c,
                             int n)
Description copied from class: Function
Executes this node as a double.
Overrides:
execute_double in class Function
Following copied from class: com.groovyj.jgprog.Function
Returns:
the double return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not double

execute_object

public java.lang.Object execute_object(Chromosome c,
                                       int n)
Description copied from class: Function
Executes this node as an object.
Overrides:
execute_object in class Function
Following copied from class: com.groovyj.jgprog.Function
Returns:
the object return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not object

getChildType

public Type getChildType(int num)
Description copied from class: Function
Gets the type of node allowed form the given child number. Must be overridden in subclasses.
Overrides:
getChildType in class Function
Following copied from class: com.groovyj.jgprog.Function
Parameters:
i - the child number
Returns:
the type of node allowed for that child

isConstant

public boolean isConstant()