ptolemy.data
Class BooleanToken

java.lang.Object
  extended byptolemy.data.Token
      extended byptolemy.data.AbstractConvertibleToken
          extended byptolemy.data.BooleanToken
All Implemented Interfaces:
BitwiseOperationToken, java.io.Serializable

public class BooleanToken
extends AbstractConvertibleToken
implements BitwiseOperationToken

See Also:
Serialized Form

Field Summary
static BooleanToken FALSE
          False-valued token.
static BooleanToken TRUE
          True-valued token.
 
Constructor Summary
BooleanToken()
          Construct a token with value false
BooleanToken(boolean b)
          Construct a token with the specified value.
BooleanToken(java.lang.String init)
          Construct a token with the specified string.
 
Method Summary
protected  Token _add(Token rightArgument)
          Return a new token whose value is the value of the argument Token added to the value of this Token.
protected  Token _divide(Token rightArgument)
          Return a new token whose value is the value of the argument Token added to the value of this Token.
protected  BooleanToken _isCloseTo(Token token, double epsilon)
          Return a true-valued token if the first argument is close to this token, where in this class, "close" means "identical to."
protected  BooleanToken _isEqualTo(Token token)
          Test for equality of the values of this token and the argument.
protected  Token _modulo(Token rightArgument)
          Return a new token whose value is the value of this token modulo the value of the argument token.
protected  Token _multiply(Token rightArgument)
          Return a new token whose value is the value of this token multiplied by the value of the argument token.
protected  Token _subtract(Token rightArgument)
          Subtraction is not supported in Boolean algebras.
 BooleanToken and(BooleanToken rightArgument)
          Return a new token whose value is the logical AND of the value of this token and the the value of the argument token.
 BitwiseOperationToken bitwiseAnd(Token rightArgument)
          Returns a token representing the bitwise AND of this token and the given token.
 BitwiseOperationToken bitwiseNot()
          Returns a token representing the bitwise NOT of this token.
 BitwiseOperationToken bitwiseOr(Token rightArgument)
          Returns a token representing the bitwise OR of this token and the given token.
 BitwiseOperationToken bitwiseXor(Token rightArgument)
          Returns a token representing the bitwise XOR of this token and the given token.
 boolean booleanValue()
          Return the value as a boolean.
static BooleanToken convert(Token token)
          Convert the specified token into an instance of BooleanToken.
 boolean equals(java.lang.Object object)
          Return true if the argument's class is BooleanToken and it has the same values as this token.
static BooleanToken getInstance(boolean value)
          Return the instance of this class corresponding to the given boolean value.
 Type getType()
          Return the type of this token.
 int hashCode()
          Return a hash code value for this token.
 BooleanToken not()
          Return a new BooleanToken with the logical not of the value stored in this token.
 Token one()
          Returns a token representing the multiplicative identity.
 BooleanToken or(BooleanToken rightArgument)
          Return a new token whose value is the logical OR of the value of this token and the the value of the argument token.
 java.lang.String toString()
          Return the value of this token as a string that can be parsed by the expression language to recover a token with the same value.
 BooleanToken xor(BooleanToken rightArgument)
          Return a new token whose value is the logical XOR of the value of this token and the the value of the argument token.
 Token zero()
          Returns a token representing the additive identity.
 
Methods inherited from class ptolemy.data.AbstractConvertibleToken
add, addReverse, divide, divideReverse, isCloseTo, isEqualTo, modulo, moduloReverse, multiply, multiplyReverse, subtract, subtractReverse
 
Methods inherited from class ptolemy.data.Token
isCloseTo, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, pow, zeroReturnType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE

public static BooleanToken TRUE
True-valued token.


FALSE

public static BooleanToken FALSE
False-valued token.

Constructor Detail

BooleanToken

public BooleanToken()
Construct a token with value false


BooleanToken

public BooleanToken(boolean b)
Construct a token with the specified value.


BooleanToken

public BooleanToken(java.lang.String init)
             throws IllegalActionException
Construct a token with the specified string.

Throws:
IllegalActionException - If the token could not be created with the given String.
Method Detail

and

public BooleanToken and(BooleanToken rightArgument)
Return a new token whose value is the logical AND of the value of this token and the the value of the argument token.

Parameters:
rightArgument - The BooleanToken to OR with this one.
Returns:
A new BooleanToken containing the result.

bitwiseAnd

public BitwiseOperationToken bitwiseAnd(Token rightArgument)
                                 throws IllegalActionException
Returns a token representing the bitwise AND of this token and the given token.

Specified by:
bitwiseAnd in interface BitwiseOperationToken
Returns:
The boolean AND.
Throws:
IllegalActionException - If the given token is not compatible for this operation, or the operation does not make sense for this type.

bitwiseNot

public BitwiseOperationToken bitwiseNot()
Returns a token representing the bitwise NOT of this token.

Specified by:
bitwiseNot in interface BitwiseOperationToken
Returns:
The boolean negation.

bitwiseOr

public BitwiseOperationToken bitwiseOr(Token rightArgument)
                                throws IllegalActionException
Returns a token representing the bitwise OR of this token and the given token.

Specified by:
bitwiseOr in interface BitwiseOperationToken
Returns:
The boolean OR.
Throws:
IllegalActionException - If the given token is not compatible for this operation, or the operation does not make sense for this type.

bitwiseXor

public BitwiseOperationToken bitwiseXor(Token rightArgument)
                                 throws IllegalActionException
Returns a token representing the bitwise XOR of this token and the given token.

Specified by:
bitwiseXor in interface BitwiseOperationToken
Returns:
The boolean XOR.
Throws:
IllegalActionException - If the given token is not compatible for this operation, or the operation does not make sense for this type.

booleanValue

public boolean booleanValue()
Return the value as a boolean.

Returns:
The value.

convert

public static BooleanToken convert(Token token)
                            throws IllegalActionException
Convert the specified token into an instance of BooleanToken. This method does lossless conversion, which in the case of booleans, means that the argument can only be already an instance of BooleanToken. It is returned unchanged.

Parameters:
token - The token to be converted to a BooleanToken.
Returns:
A BooleanToken.
Throws:
IllegalActionException - If the argument is not a BooleanToken.

equals

public boolean equals(java.lang.Object object)
Return true if the argument's class is BooleanToken and it has the same values as this token.

Parameters:
object - An instance of Object.
Returns:
True if the argument is a BooleanToken with the same value.

getInstance

public static BooleanToken getInstance(boolean value)
Return the instance of this class corresponding to the given boolean value.

Returns:
BooleanToken.TRUE if the argument is true, or BooleanToken.FALSE otherwise.

getType

public Type getType()
Return the type of this token.

Overrides:
getType in class Token
Returns:
BaseType.BOOLEAN

hashCode

public int hashCode()
Return a hash code value for this token. This method returns 1 if this token has value true, and 0 if this token has value false.

Returns:
A hash code value for this token.

not

public BooleanToken not()
Return a new BooleanToken with the logical not of the value stored in this token.

Returns:
The logical converse of this token.

one

public Token one()
Returns a token representing the multiplicative identity.

Overrides:
one in class Token
Returns:
TRUE.

or

public BooleanToken or(BooleanToken rightArgument)
Return a new token whose value is the logical OR of the value of this token and the the value of the argument token.

Parameters:
rightArgument - The BooleanToken to OR with this one.
Returns:
A new BooleanToken containing the result.

toString

public java.lang.String toString()
Return the value of this token as a string that can be parsed by the expression language to recover a token with the same value.

Overrides:
toString in class Token
Returns:
The string "true" if this token represents true, or the string "false" if it represents false.

xor

public BooleanToken xor(BooleanToken rightArgument)
Return a new token whose value is the logical XOR of the value of this token and the the value of the argument token.

Parameters:
rightArgument - The BooleanToken to XOR with this one.
Returns:
A new BooleanToken containing the result.

zero

public Token zero()
Returns a token representing the additive identity.

Overrides:
zero in class Token
Returns:
FALSE.

_add

protected Token _add(Token rightArgument)
Return a new token whose value is the value of the argument Token added to the value of this Token. It is assumed that the type of the argument is an BooleanToken.

Specified by:
_add in class AbstractConvertibleToken
Parameters:
rightArgument - The token to add to this token.
Returns:
A new BooleanToken containing the result.

_divide

protected Token _divide(Token rightArgument)
                 throws IllegalActionException
Return a new token whose value is the value of the argument Token added to the value of this Token. It is assumed that the type of the argument is an BooleanToken. For booleans, division is defined by multiplication (which is logical and). Thus, if c = a/b then c is defined so that cb = a. If b is false then this result is not well defined, so this method will throw an exception. Specifically, if the argument is true, then this method returns this token. Otherwise it throws an exception.

Specified by:
_divide in class AbstractConvertibleToken
Parameters:
rightArgument - The token to divide this token by
Returns:
A new BooleanToken containing the result.
Throws:
IllegalActionException - If the argument token is FALSE.

_isCloseTo

protected BooleanToken _isCloseTo(Token token,
                                  double epsilon)
Return a true-valued token if the first argument is close to this token, where in this class, "close" means "identical to." It is assumed that the type of the argument is BooleanToken.

Specified by:
_isCloseTo in class AbstractConvertibleToken
Parameters:
token - The token to compare to this token.
Returns:
A token containing the result.

_isEqualTo

protected BooleanToken _isEqualTo(Token token)
Test for equality of the values of this token and the argument. It is assumed that the type of the argument is BooleanToken.

Specified by:
_isEqualTo in class AbstractConvertibleToken
Parameters:
token - The token to compare to this token.
Returns:
A token containing the result.

_modulo

protected Token _modulo(Token rightArgument)
                 throws IllegalActionException
Return a new token whose value is the value of this token modulo the value of the argument token. It is assumed that the type of the argument is BooleanToken.

Specified by:
_modulo in class AbstractConvertibleToken
Parameters:
rightArgument - The token to modulo this token by.
Returns:
A new Token containing the result that is of the same class as this token.
Throws:
IllegalActionException - If this method is not supported by the derived class.

_multiply

protected Token _multiply(Token rightArgument)
                   throws IllegalActionException
Return a new token whose value is the value of this token multiplied by the value of the argument token. It is assumed that the type of the argument is an BooleanToken. For booleans, this corresponds to the logical AND.

Specified by:
_multiply in class AbstractConvertibleToken
Parameters:
rightArgument - The token to multiply this token by.
Returns:
A new BooleanToken containing the result.
Throws:
IllegalActionException - If this method is not supported by the derived class.

_subtract

protected Token _subtract(Token rightArgument)
                   throws IllegalActionException
Subtraction is not supported in Boolean algebras.

Specified by:
_subtract in class AbstractConvertibleToken
Parameters:
rightArgument - The token to subtract from this token.
Returns:
A new Token containing the result that is of the same class as this token.
Throws:
IllegalActionException - If this method is not supported by the derived class.