Class Assignment

java.lang.Object
edu.uky.cs.nil.tt.world.Assignment
All Implemented Interfaces:
Described, Encoded, Logical

public class Assignment extends Object implements Described, Encoded, Logical
An assignment is a logical formula that asserts that some variable in a story world has a value.
Author:
Stephen G. Ware
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final Value
    The value assigned to the variable
    final Variable
    The variable that is being assigned a value
    final boolean
    Whether or not this assignment can currently be observed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Assignment(Variable variable, Value value)
    Constructs a new assignment from a variable and value which is visible and with a blank description.
    Assignment(Variable variable, Value value, boolean visible, String description)
    Constructs a new assignment from a variable, value, and description.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object other)
     
    Returns a string of 1's and 0's that uniquely represents this object among other objects of the same type in the same story world.
    Returns a human-readable natural language description of the object.
    int
     
    setDescription(String description)
    Returns a new assignment that is the same as this assignment, except that its description is the given value.
    setValue(Value value)
    Returns a new assignment that is the same as this assignment, except that its value is the given value.
    setVisible(boolean visible)
    Returns a new assignment that is the same as this assignment, except that its visibility is the given value.
    Returns a logical object identical to this one, except that its logical elements have been replaced according to the given substitution.
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • variable

      public final Variable variable
      The variable that is being assigned a value
    • value

      public final Value value
      The value assigned to the variable
    • visible

      public final boolean visible
      Whether or not this assignment can currently be observed. When an assignment can be observed, it is known to be the case. When it cannot be observed, it represents an assumed or last known value of the variable.
  • Constructor Details

    • Assignment

      public Assignment(Variable variable, Value value, boolean visible, String description)
      Constructs a new assignment from a variable, value, and description.
      Parameters:
      variable - the variable whose value is being assigned
      value - the value being assigned to the variable
      visible - whether this assignment is visible and is known (true) or whether it is invisible and represents an assumed or last known value (false)
      description - a natural language description of what it means for this variable to have this value
    • Assignment

      public Assignment(Variable variable, Value value)
      Constructs a new assignment from a variable and value which is visible and with a blank description.
      Parameters:
      variable - the variable whose value is being assigned
      value - the value being assigned to the variable
  • 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
    • setValue

      public Assignment setValue(Value value)
      Returns a new assignment that is the same as this assignment, except that its value is the given value.
      Parameters:
      value - the new value to be assigned to this assignment's variable
      Returns:
      an assignment identical to this assignment, except with the given value
    • setVisible

      public Assignment setVisible(boolean visible)
      Returns a new assignment that is the same as this assignment, except that its visibility is the given value.
      Parameters:
      visible - true if this assignment is visible and therefore known or false if this assignment is not visible and represents an assumed or last known value
      Returns:
      an assignment identical to this assignment, except with the given visibility
    • getDescription

      public String getDescription()
      Description copied from interface: Described
      Returns a human-readable natural language description of the object.
      Specified by:
      getDescription in interface Described
      Returns:
      a human-readable natural language description of the object
    • setDescription

      public Assignment setDescription(String description)
      Returns a new assignment that is the same as this assignment, except that its description is the given value.
      Parameters:
      description - the description the new assignment should have
      Returns:
      an assignment identical to this assignment, except with the given description
    • getCode

      public String getCode()
      Description copied from interface: Encoded
      Returns a string of 1's and 0's that uniquely represents this object among other objects of the same type in the same story world. Every encoded object of the same type should return a string of the same length, even if it must be padded with 0's.
      Specified by:
      getCode in interface Encoded
      Returns:
      a string of 1's and 0's
    • substitute

      public Assignment 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 Logical
      Parameters:
      substitution - a function which maps logical formulas that should be replaced to the formula they should be replaced with
      Returns:
      an identical object, except that its logical formulas have been replaced according to the substitution