Class Constant

java.lang.Object
edu.uky.cs.nil.tt.world.Constant
All Implemented Interfaces:
Expression, Logical, Value

public class Constant extends Object implements Value
A constant is a logical value that always exists in all story worlds, such a the Boolean concepts of True and False, numbers, and so on.
Author:
Stephen G. Ware
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Constant
    A constant representing Boolean false
    static final Constant
    A constant representing nothing or the absence of a value
    static final Constant
    A constant representing Boolean true
    final Object
    The Java object associated with this constant
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constant(boolean value)
    Constructs a new constant that represents a Boolean value.
    Constant(float value)
    Constructs a new constant that represents a decimal number.
    Constant(int value)
    Constructs a new constant that represents an integer.
    Constant(Void value)
    Constructs a new constant equivalent to NULL.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object other)
     
    int
     
    Returns a logical object identical to this one, except that its logical elements have been replaced according to the given substitution.
    boolean
    If this value represents a Boolean, this method convert it into a Java boolean; all other values are converted to false.
    double
    If this value represents a number, this method convert it into a Java double; all other values are converted to Double.NaN.
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface Value

    evaluate, toEntity
  • Field Details

    • NULL

      public static final Constant NULL
      A constant representing nothing or the absence of a value
    • TRUE

      public static final Constant TRUE
      A constant representing Boolean true
    • FALSE

      public static final Constant FALSE
      A constant representing Boolean false
    • value

      public final Object value
      The Java object associated with this constant
  • Constructor Details

    • Constant

      public Constant(Void value)
      Constructs a new constant equivalent to NULL.
      Parameters:
      value - no value
    • Constant

      public Constant(boolean value)
      Constructs a new constant that represents a Boolean value.
      Parameters:
      value - the boolean value
    • Constant

      public Constant(int value)
      Constructs a new constant that represents an integer.
      Parameters:
      value - the integer value
    • Constant

      public Constant(float value)
      Constructs a new constant that represents a decimal number.
      Parameters:
      value - the decimal value
  • Method Details

    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • substitute

      public Constant substitute(Function<Object,Object> substitution)
      Description copied from interface: Logical
      Returns a logical object identical to this one, except that its logical elements have been replaced according to the given substitution. A substitution defines how some logical formula (the input to the function) should be replaced with a different formula (the output of the function).
      Specified by:
      substitute in interface Expression
      Specified by:
      substitute in interface Logical
      Specified by:
      substitute in interface Value
      Parameters:
      substitution - a function which maps logical formula that should be replaced to the formula they should be replaced with
      Returns:
      an identical object, except that its logical formula have been replaced according to the substitution
    • toBoolean

      public boolean toBoolean()
      Description copied from interface: Value
      If this value represents a Boolean, this method convert it into a Java boolean; all other values are converted to false.
      Specified by:
      toBoolean in interface Value
      Returns:
      a Java boolean, or false if this value does not represent a Boolean value
    • toNumber

      public double toNumber()
      Description copied from interface: Value
      If this value represents a number, this method convert it into a Java double; all other values are converted to Double.NaN.
      Specified by:
      toNumber in interface Value
      Returns:
      a Java double, or NaN if this value represents NaN or is not a number