Class State

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

public class State extends Object implements Described, Encoded
A state is an assignment of values to each variable in a story world.

State objects are unmodifiable. Calls to set(Assignment) create and return a new state and do not modify the object on which they are called.

Author:
Stephen G. Ware
  • Constructor Summary

    Constructors
    Constructor
    Description
    State(World world)
    Constructs a state that assigns default values to every variable in a story world.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object other)
     
    get(Variable variable)
    Returns the value assigned to the given variable, or null if the variable does not exist in this state or is assigned a null value.
    Returns an unmodifiable list of assignments of a value to each variable in the state.
    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
     
    set(Assignment assignment)
    Returns a new state object that is identical to this one, except with the variable in the given assignment set to the given value.
    protected State
    setDescription(String description)
    Returns a new state that is the same as this state, except this its description is the given value.
     

    Methods inherited from class Object

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

    • State

      public State(World world)
      Constructs a state that assigns default values to every variable in a story world.
      Parameters:
      world - the world whose variables will be assigned default values
  • 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
    • 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

      protected State setDescription(String description)
      Returns a new state that is the same as this state, except this its description is the given value.
      Parameters:
      description - the description the new state should have
      Returns:
      a state identical to this state, 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
    • getAssignments

      public List<Assignment> getAssignments()
      Returns an unmodifiable list of assignments of a value to each variable in the state.
      Returns:
      an unmodifiable list of variable assignments
    • get

      public Value get(Variable variable)
      Returns the value assigned to the given variable, or null if the variable does not exist in this state or is assigned a null value.
      Parameters:
      variable - a variable whose assigned value is desired
      Returns:
      the value assigned to the given variable in this state
    • set

      public State set(Assignment assignment)
      Returns a new state object that is identical to this one, except with the variable in the given assignment set to the given value.
      Parameters:
      assignment - an assignment the new state should contain
      Returns:
      a new state the reflects the given assignment