com.groovyj.jgprog.functions
Class Variable

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

public class Variable
extends Function
implements java.io.Serializable

A node representing a named variable. Allowed to be of type boolean, int, long, float, or double.

A named variable is created by constructing an instance of the Variable, giving it a name and type. From that point on, all references to that particular variable should be through either the instance initially created, or looked up via the getVariable method.

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

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

Field Summary
 java.lang.Object value
           
 
Fields inherited from class com.groovyj.jgprog.Function
arity, individual, returnType
 
Method Summary
static Variable create(java.lang.String name, Type type)
          Creates an instance of a Variable.
 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 named variable.
static java.lang.Object get(java.lang.String name)
          Gets the value of a named variable without having to obtain a reference to the named variable.
 Type getChildType(int i)
          Gets the type of node allowed form the given child number.
 java.lang.String getName()
          Gets the name of this node.
static Variable getVariable(java.lang.String name)
          Gets the one instance of a named variable.
 boolean isConstant()
           
 void set(java.lang.Object value)
          Sets the value of this named variable.
static void set(java.lang.String name, java.lang.Object value)
          Sets a named variable without having to obtain a reference to the named variable.
 
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
 

Field Detail

value

public java.lang.Object value
Method Detail

create

public static Variable create(java.lang.String name,
                              Type type)
Creates an instance of a Variable. If a Variable of that name already exists, that is returned. Otherwise a new instance is created, its value is initialized to null, and it is placed into the static hashtable for later retrieval by name via get or getVariable.
Parameters:
name - the name of the Variable to create
type - the type of the Variable to create
Since:
1.0

set

public static void set(java.lang.String name,
                       java.lang.Object value)
Sets a named variable without having to obtain a reference to the named variable.
Parameters:
name - the name of the variable to set
value - the value to set the variable with
Since:
1.0

get

public static java.lang.Object get(java.lang.String name)
Gets the value of a named variable without having to obtain a reference to the named variable.
Parameters:
name - the name of the variable to get
Returns:
an Object representing the value of the named variable, or null if that name wasn't found.
Since:
1.0

getVariable

public static Variable getVariable(java.lang.String name)
Gets the one instance of a named variable.
Parameters:
name - the name of the variable to get
Returns:
the named variable, or null if that name wasn't found.
Since:
1.0

set

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

get

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

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.

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 i)
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()