Class Entity

java.lang.Object
edu.uky.cs.nil.tt.world.Asset
edu.uky.cs.nil.tt.world.Entity
All Implemented Interfaces:
Named, Described, Encoded, Expression, Logical, Unique, Value, Comparable<Entity>

public final class Entity extends Asset implements Comparable<Entity>, Named, Encoded, Value
An entity is an asset that represents a character, object, place, or idea in a story world.
Author:
Stephen G. Ware
  • Constructor Details

    • Entity

      public Entity(int id, String name, String description, String code)
      Constructs a new entity.
      Parameters:
      id - the entity's unique ID number
      name - the entity's unique name
      description - the entity's description
      code - the entity's code
  • Method Details

    • compareTo

      public int compareTo(Entity other)
      Specified by:
      compareTo in interface Comparable<Entity>
    • setID

      protected Entity setID(int id)
      Description copied from class: Asset
      Returns a new asset that is the same as this asset, except that its ID number is the given value.
      Specified by:
      setID in class Asset
      Parameters:
      id - the ID number the new asset should have
      Returns:
      an asset identical to this asset, except with the given ID number
    • setDescription

      public Entity setDescription(String description)
      Description copied from class: Asset
      Returns a new asset that is the same as this asset, except that its description is the given value.
      Specified by:
      setDescription in class Asset
      Parameters:
      description - the description the new asset should have
      Returns:
      an asset identical to this asset, 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
    • setCode

      protected Entity setCode(String code)
      Returns a new entity that is the same as this entity, except this its code is the given value.
      Parameters:
      code - the code the new entity should have
      Returns:
      an entity identical to this entity, except with the given code
    • substitute

      public Entity 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
      Specified by:
      substitute in class Asset
      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

      public Entity evaluate(State state)
      Description copied from interface: Value
      Returns the value of this logical expression in the given state.

      A logical value evaluates to itself.

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

      public Entity toEntity()
      Description copied from interface: Value
      If this value represents an Entity, this method returns that entity; all other values are converted to {code null}.
      Specified by:
      toEntity in interface Value
      Returns:
      an entity, or null if this value is not an entity
    • isPlayer

      public boolean isPlayer()
      Returns true if this entity represents the player character in its story world.

      By default, the entity with ID number 0 is assumed to be the player character.

      Returns:
      true if this entity represents the player character, false otherwise