Package ptolemy.data

Class BooleanToken

  • All Implemented Interfaces:
    BitwiseOperationToken, PartiallyOrderedToken

    public class BooleanToken
    extends ScalarToken
    A token that contains a boolean variable. Arithmetic on booleans is that of a two-element Galois field (modulo two arithmetic). Thus, add() is logical xor, multiply() is logical and, zero() is false, one() is true.

    In order to reduce the number of instances of this object that are created, it is highly recommended that the getInstance() method be used, instead of the constructor that takes a boolean argument.

    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Neil Smyth, Yuhong Xiong, Edward A. Lee, Steve Neuendorffer, Christopher Brooks
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (cxh) nil token
    • Field Detail

      • TRUE

        public static final BooleanToken TRUE
        True-valued token.
      • NIL

        public static final BooleanToken NIL
        A token that represents a missing value. Null or missing tokens are common in analytical systems like R and SAS where they are used to handle sparsely populated data sources. In database parlance, missing tokens are sometimes called null tokens. Since null is a Java keyword, we use the term "nil". The toString() method on a nil token returns the string "nil".
      • FALSE

        public static final 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.
        Parameters:
        b - The boolean value.
      • BooleanToken

        public BooleanToken​(java.lang.String init)
                     throws IllegalActionException
        Construct a token with the specified string. The initialization string is converted to lower case and compared to the string "true".
        Parameters:
        init - The initialization 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. If this token is nil, or the argument is nil, then NIL is returned.
        Parameters:
        rightArgument - The BooleanToken to OR with this one.
        Returns:
        A new BooleanToken containing the result.
      • 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. If the argument is a nil token, then NIL is returned.
        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.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - An instance of Object.
        Returns:
        True if the argument is a BooleanToken with the same value. If either this object or the argument is a nil Token, return false.
      • getInstance

        public static BooleanToken getInstance​(boolean value)
        Return the instance of this class corresponding to the given boolean value.
        Parameters:
        value - The given value.
        Returns:
        BooleanToken.TRUE if the argument is true, or BooleanToken.FALSE otherwise.
      • getType

        public Type getType()
        Return the type of this token.
        Specified by:
        getType in class ScalarToken
        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.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code value for this token.
      • isNil

        public boolean isNil()
        Return true if the token is nil, (aka null or missing). Nil or missing tokens occur when a data source is sparsely populated.
        Overrides:
        isNil in class Token
        Returns:
        True if the token is the NIL 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. If this token is nil, or the argument is nil, then NIL is returned.
        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. If this token is nil, or the argument is nil, then NIL is returned.
        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 ScalarToken _add​(ScalarToken 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 ScalarToken
        Parameters:
        rightArgument - The token to add to this token.
        Returns:
        A new BooleanToken containing the result.
      • _divide

        protected ScalarToken _divide​(ScalarToken rightArgument)
                               throws IllegalActionException
        Return a new token whose value is the value of this token divided by 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 ScalarToken
        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​(ScalarToken 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 ScalarToken
        Parameters:
        token - The token to compare to this token.
        epsilon - Ignored in this method.
        Returns:
        A token containing the result.
      • _isEqualTo

        protected BooleanToken _isEqualTo​(ScalarToken token)
        Test for equality of the values of this token and the argument. This is the same as equals(), except that it returns a BooleanToken instead of a boolean.
        Overrides:
        _isEqualTo in class ScalarToken
        Parameters:
        token - The token to compare to this token.
        Returns:
        A token containing the result. If either this object or the argument is a nil Token, return false.
      • _multiply

        protected ScalarToken _multiply​(ScalarToken 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 ScalarToken
        Parameters:
        rightArgument - The token to multiply this token by.
        Returns:
        A new BooleanToken containing the result.
        Throws:
        IllegalActionException - If ANDing the argument and the token throws it.