Interface Value

All Superinterfaces:
Expression, Logical
All Known Implementing Classes:
Constant, Entity

public interface Value extends Expression
A value is a logical expression which evaluates to itself.
Author:
Stephen G. Ware
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    configure(com.google.gson.GsonBuilder builder)
    Configures a GsonBuilder to encode and decode Value objects as JSON.
    default Value
    evaluate(State state)
    Returns the value of this logical expression in the given state.
    default Value
    Returns a logical object identical to this one, except that its logical elements have been replaced according to the given substitution.
    default boolean
    If this value represents a Boolean, this method convert it into a Java boolean; all other values are converted to false.
    default Entity
    If this value represents an Entity, this method returns that entity; all other values are converted to {code null}.
    default double
    If this value represents a number, this method convert it into a Java double; all other values are converted to Double.NaN.
  • Method Details

    • configure

      static void configure(com.google.gson.GsonBuilder builder)
      Configures a GsonBuilder to encode and decode Value objects as JSON.
      Parameters:
      builder - the GSON builder to configure
    • substitute

      default Value 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
      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
    • evaluate

      default Value evaluate(State state)
      Returns the value of this logical expression in the given state.

      A logical value evaluates to itself.

      Specified by:
      evaluate in interface Expression
      Parameters:
      state - a mapping of values to all of a story world's variables
      Returns:
      the value of the expression in the given state
    • toBoolean

      default boolean toBoolean()
      If this value represents a Boolean, this method convert it into a Java boolean; all other values are converted to false.
      Returns:
      a Java boolean, or false if this value does not represent a Boolean value
    • toNumber

      default double toNumber()
      If this value represents a number, this method convert it into a Java double; all other values are converted to Double.NaN.
      Returns:
      a Java double, or NaN if this value represents NaN or is not a number
    • toEntity

      default Entity toEntity()
      If this value represents an Entity, this method returns that entity; all other values are converted to {code null}.
      Returns:
      an entity, or null if this value is not an entity