gpsys.primitives
Class If

java.lang.Object
  |
  +--gpsys.Primitive
        |
        +--gpsys.Function
              |
              +--gpsys.primitives.If

public class If
extends Function

	<TypeX> if (BOOLEAN condition, <typeX> trueValue, <typeX> falseValue)
 
If is a generic function that conditionally evaluates one of two arguments. The function evaluates the first argument (which is of Type BOOLEAN). If the result is true, then the result of evaluating the second argument is returned, otherwise the result of evaluating the third argument is returned. The second and third arguments must be of the same type. If needs to be Type instantiated during construction to work with particular argument Types. The supported argument Types include BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, CHAR and BOOLEAN.

Version:
$Revision: 1.1 $, $Date: 2000/07/05 16:24:33 $
Author:
Adil Qureshi
Department of Computer Science,
University College London,
Gower St,
London WC1E 6BT,
UK.
See Also:
Type, Primitive, Function, Serialized Form

Fields inherited from class gpsys.Function
argTypes
 
Fields inherited from class gpsys.Primitive
type
 
Constructor Summary
If(Type returnType)
          Constructs an If Function that works with the specified Type.
 
Method Summary
 boolean evaluateBoolean(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of BOOLEAN Types.
 byte evaluateByte(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of BYTE Types.
 char evaluateChar(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of CHAR Types.
 double evaluateDouble(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of DOUBLE Types.
 float evaluateFloat(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of FLOAT Types.
 int evaluateInt(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of INT Types.
 long evaluateLong(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of LONG Types.
 java.lang.Object evaluateObject(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of OBJECT Types.
 short evaluateShort(Individual i, Gene[] arguments)
          Used to conditionally evaluate arguments of SHORT Types.
 Primitive instance()
          Creates an If Object of the same type.
 java.lang.String toString()
          Returns a String representation of this Function.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Constructor Detail

If

public If(Type returnType)
Constructs an If Function that works with the specified Type. The supported Types include BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, CHAR, BOOLEAN, and OBJECT.
Parameters:
type - The Type of this If Function.
Method Detail

evaluateObject

public final java.lang.Object evaluateObject(Individual i,
                                             Gene[] arguments)
                                      throws EvaluationException
Used to conditionally evaluate arguments of OBJECT Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
An Object reference representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateObject in class Function

evaluateByte

public final byte evaluateByte(Individual i,
                               Gene[] arguments)
                        throws EvaluationException
Used to conditionally evaluate arguments of BYTE Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
A byte representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateByte in class Function

evaluateShort

public final short evaluateShort(Individual i,
                                 Gene[] arguments)
                          throws EvaluationException
Used to conditionally evaluate arguments of SHORT Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
A short representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateShort in class Function

evaluateInt

public final int evaluateInt(Individual i,
                             Gene[] arguments)
                      throws EvaluationException
Used to conditionally evaluate arguments of INT Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
An int representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateInt in class Function

evaluateLong

public final long evaluateLong(Individual i,
                               Gene[] arguments)
                        throws EvaluationException
Used to conditionally evaluate arguments of LONG Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
A long representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateLong in class Function

evaluateFloat

public final float evaluateFloat(Individual i,
                                 Gene[] arguments)
                          throws EvaluationException
Used to conditionally evaluate arguments of FLOAT Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
A float representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateFloat in class Function

evaluateDouble

public final double evaluateDouble(Individual i,
                                   Gene[] arguments)
                            throws EvaluationException
Used to conditionally evaluate arguments of DOUBLE Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
A double representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateDouble in class Function

evaluateChar

public final char evaluateChar(Individual i,
                               Gene[] arguments)
                        throws EvaluationException
Used to conditionally evaluate arguments of CHAR Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
A char representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateChar in class Function

evaluateBoolean

public final boolean evaluateBoolean(Individual i,
                                     Gene[] arguments)
                              throws EvaluationException
Used to conditionally evaluate arguments of BOOLEAN Types.
Parameters:
i - The individual being evaluated.
arguments - The Gene trees representing the arguments to be conditionally evaluated.
Returns:
A boolean representing the result of the evaluation.
Throws:
EvaluationException - If there is an evaluation failure.
Overrides:
evaluateBoolean in class Function

instance

public final Primitive instance()
Creates an If Object of the same type.
Returns:
A reference to the same Object since no instance varaibles need to be changed.
Overrides:
instance in class Primitive

toString

public java.lang.String toString()
Returns a String representation of this Function.
Returns:
A String containing the name of the Function.
Overrides:
toString in class Primitive