Class Entity

java.lang.Object
edu.uky.cs.nil.sabre.Entity
All Implemented Interfaces:
Expression, Logical, Parameter, Simplifiable, Typed, Value, Unique, Serializable, Comparable<Logical>
Direct Known Subclasses:
Character

public class Entity extends Object implements Unique, Value
An entity represents a discrete object in a problem.

Entities are unique symbols defined in a universe, which means entity objects are only the same if they are from the same universe. Entities with the same ID number and name are different entities if they come from different universes. This means entities can be compared using ==. The ID number of an entity corresponds with its index in Universe.entities.

Entities should not be constructed directly. They should be defined by a UniverseBuilder.

Author:
Stephen G. Ware
See Also:
  • Field Details

    • universe

      public final Universe universe
      The universe in which this entity is defined
    • id

      public final int id
      The unique sequential ID number of this entity in its universe
    • name

      public final String name
      The unique name of this entity in this universe
    • types

      public final ImmutableSet<Type> types
      The direct parent types of this entity
    • comment

      public final String comment
      The comment associated with this entity from the problem definition
  • Method Details

    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Unique
      Overrides:
      hashCode in class Object
    • toString

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

      public int compareTo(Logical other)
      Specified by:
      compareTo in interface Comparable<Logical>
      Specified by:
      compareTo in interface Logical
    • apply

      public Entity apply(Function<Object,Object> function)
      Description copied from interface: Logical
      Applies a given function to every part of this logical formula and then creates a new logical formula of this same type using the results returned from the function. If, for every part of this formula, the function always returns its input as output with no changes, this method should return this object (not just any object that is equal to this object).
      Specified by:
      apply in interface Expression
      Specified by:
      apply in interface Logical
      Specified by:
      apply in interface Parameter
      Specified by:
      apply in interface Simplifiable
      Specified by:
      apply in interface Value
      Parameters:
      function - the function to apply to all parts of this formula
      Returns:
      a logical formula of the same type as this formula made from the returned objects, or this object if no parts were changed by the function
    • isBoolean

      public boolean isBoolean()
      Description copied from interface: Typed
      Tests whether this formula is of type boolean.
      Specified by:
      isBoolean in interface Typed
      Returns:
      true if the formula is Boolean, false otherwise
    • isNumber

      public boolean isNumber()
      Description copied from interface: Typed
      Tests whether this formula is of type number.
      Specified by:
      isNumber in interface Typed
      Returns:
      true if the formula is numeric, false otherwise
    • isEntity

      public boolean isEntity()
      Description copied from interface: Typed
      Tests whether this formula is of type entity.
      Specified by:
      isEntity in interface Typed
      Returns:
      true if the formula is of type entity, false otherwise
    • isCharacter

      public boolean isCharacter()
      Description copied from interface: Typed
      Tests whether this formula is of type character.
      Specified by:
      isCharacter in interface Typed
      Returns:
      true if the formula is of type character, false otherwise
    • is

      public boolean is(Type type)
      Description copied from interface: Typed
      Tests whether this formula is of a given type.
      Specified by:
      is in interface Typed
      Parameters:
      type - the type being tested
      Returns:
      true if the formula is of this type or one of its subtypes, false otherwise
    • simplify

      public Entity simplify()
      Description copied from interface: Simplifiable
      Returns a logically equivalent but smaller, simpler, or more convenient form of this logical formula.
      Specified by:
      simplify in interface Expression
      Specified by:
      simplify in interface Parameter
      Specified by:
      simplify in interface Simplifiable
      Specified by:
      simplify in interface Value
      Returns:
      a smaller, simpler, or more convenient logical formula which is equivalent to this formula
    • evaluate

      public Entity evaluate(State state)
      Description copied from interface: Expression
      Returns the value of this expression in a given state.
      Specified by:
      evaluate in interface Expression
      Specified by:
      evaluate in interface Value
      Parameters:
      state - the state in which this expression will be evaluated
      Returns:
      the value of this expression
    • prepend

      public Entity prepend(Parameter character)
      Description copied from interface: Expression
      Returns an expression which represents a character's beliefs about this expression.
      Specified by:
      prepend in interface Expression
      Specified by:
      prepend in interface Parameter
      Specified by:
      prepend in interface Value
      Parameters:
      character - the character whose beliefs will be represented
      Returns:
      an expression representing the character's beliefs about this expression