unsw.cse.framescript
Class FSNumber

java.lang.Object
  extended by unsw.cse.framescript.Term
      extended by unsw.cse.framescript.FSNumber
Direct Known Subclasses:
FSDouble, FSInteger

public abstract class FSNumber
extends Term

This is the super class for all of the numerical types used is FrameScript.

Author:
mmcgill

Constructor Summary
FSNumber()
           
 
Method Summary
abstract  FSNumber add(FSNumber n)
          Adds two numbers.
abstract  FSNumber divide(FSNumber n)
          Divides two numbers.
abstract  boolean eq(FSNumber n)
          Compares two numbers for equality.
 boolean equals(Term t)
          Compares two Terms for equality.
 Term eval(Instance currentObject, StackFrame stackframe)
          Evaluates a Term.
abstract  boolean ge(FSNumber n)
          Greater than or equal to comparison of two numbers.
static FSNumber getNumber(double d)
          Creates the appropriate FrameScript number for a double.
abstract  double getValue()
          Gets the value of the number as a double.
abstract  boolean gt(FSNumber n)
          Greater than comparison of two numbers.
abstract  boolean le(FSNumber n)
          Less than or equal to comparison of two numbers.
abstract  boolean lt(FSNumber n)
          Less than comparison of two numbers.
abstract  FSNumber mod(FSNumber n)
          Gets the modular of two numbers.
abstract  FSNumber multiply(FSNumber n)
          Multiplies two numbers.
abstract  FSNumber negate()
          Gets the negative of a number.
abstract  FSNumber subtract(FSNumber n)
          Subtracts two numbers.
 
Methods inherited from class unsw.cse.framescript.Term
assign, asString, fullMatch, indents, mapVars, match, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FSNumber

public FSNumber()
Method Detail

eval

public Term eval(Instance currentObject,
                 StackFrame stackframe)
          throws FSException
Description copied from class: Term
Evaluates a Term. For many Terms the result is to return itself.

Specified by:
eval in class Term
Parameters:
currentObject - the enclosing instance frame for the code being evaluated
stackframe - StackFrame that holds the values for any variables
Returns:
the result of the evaluation
Throws:
FSException - if any errors occur in performing the evaluation

getValue

public abstract double getValue()
Gets the value of the number as a double.

Returns:
the value of the number

negate

public abstract FSNumber negate()
Gets the negative of a number.

Returns:
a number whose value is the negative of this

add

public abstract FSNumber add(FSNumber n)
Adds two numbers.

Parameters:
n - the number being added to this
Returns:
a number whose value is the sum of this and n

subtract

public abstract FSNumber subtract(FSNumber n)
Subtracts two numbers.

Parameters:
n - the number being subtracted from this
Returns:
a number whose value is this minus n

multiply

public abstract FSNumber multiply(FSNumber n)
Multiplies two numbers.

Parameters:
n - the number this is being multiplied by
Returns:
a number whose value is the product of this and n

divide

public abstract FSNumber divide(FSNumber n)
                         throws FSException
Divides two numbers.

Parameters:
n - the number this is being divided by
Returns:
a number whose value is this divided by n
Throws:
FSException - if n is 0

mod

public abstract FSNumber mod(FSNumber n)
                      throws FSException
Gets the modular of two numbers.

Parameters:
n - the modular number
Returns:
a number whose value is this mod n
Throws:
FSException - if this or n is not an integer or n is 0

lt

public abstract boolean lt(FSNumber n)
Less than comparison of two numbers.

Parameters:
n - the potentially larger number
Returns:
true if this is smaller than n, else false

le

public abstract boolean le(FSNumber n)
Less than or equal to comparison of two numbers.

Parameters:
n - the potentially larger number
Returns:
true if this is smaller than or equal to n, else false

gt

public abstract boolean gt(FSNumber n)
Greater than comparison of two numbers.

Parameters:
n - the potentially smaller number
Returns:
true if this is greater than n, else false

ge

public abstract boolean ge(FSNumber n)
Greater than or equal to comparison of two numbers.

Parameters:
n - the potentially smaller number
Returns:
true if this is greater than or equal to n, else false

eq

public abstract boolean eq(FSNumber n)
Compares two numbers for equality.

Parameters:
n - number this is being compared to
Returns:
true if they are equal, false otherwise

equals

public boolean equals(Term t)
Description copied from class: Term
Compares two Terms for equality.

Specified by:
equals in class Term
Parameters:
t - Term to be compared to
Returns:
true if the Terms are equal, false otherwise

getNumber

public static FSNumber getNumber(double d)
Creates the appropriate FrameScript number for a double.

Parameters:
d - the value of the number
Returns:
a number whose value is d