Class World

java.lang.Object
edu.uky.cs.nil.tt.world.World
All Implemented Interfaces:
Named
Direct Known Subclasses:
WorldModel

public class World extends Object implements Named
A story world is a collection of assets needed for two partners in a session to tell a collaborative story.
Author:
Stephen G. Ware
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final String
    The unique name of this story world
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a story world from the assets defined in an asset builder.
    World(String name, Collection<Entity> entities, Collection<Variable> variables, Collection<Action> actions, Collection<Ending> endings)
    Constructs a story world from a unique name and sets of assets.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(Action action)
    Returns true if the given action is defined in this story world.
    boolean
    contains(Ending ending)
    Returns true if the given ending is defined in this story world.
    boolean
    contains(Entity entity)
    Returns true if the given entity is defined in this story world.
    boolean
    contains(Variable variable)
    Returns true if the given variable is defined in this story world.
    getAction(int id)
    Returns the action defined in this story world which has the given ID number.
    getAction(Signature signature)
    Returns the action defined in this story world which has the given signature.
    Returns the action defined in this story world which has the given name.
    Returns an unmodifiable list of all actions defined in this story world ordered by the ID numbers.
    getEnding(int id)
    Returns the ending defined in this story world which has the given ID number.
    getEnding(Signature signature)
    Returns the ending defined in this story world which has the given signature.
    Returns the ending defined in this story world which has the given name.
    Returns an unmodifiable list of all endings defined in this story world ordered by the ID numbers.
    Returns an unmodifiable list of all entities defined in this story world ordered by the ID numbers.
    getEntity(int id)
    Returns the entity defined in this story world which has the given ID number.
    Returns the entity defined in this story world which has the given name.
    Returns this object's unique name that distinguishes it from other objects of the same type in the same context.
    Returns the entity the represents the player character in this story world.
    getVariable(int id)
    Returns the variable defined in this story world which has the given ID number.
    Returns the variable defined in this story world which has the given signature.
    Returns the variable defined in this story world which has the given name.
    Returns an unmodifiable list of all variables defined in this story world ordered by the ID numbers.
    requireAction(int id)
    Returns the action defined in this story world which has the given ID number or throws an exception if it does not exist.
    Returns the action defined in this story world which has the given signature or throws an exception if it does not exist.
    Returns the action defined in this story world which has the given name or throws an exception if it does not exist.
    requireEnding(int id)
    Returns the ending defined in this story world which has the given ID number or throws an exception if it does not exist.
    Returns the ending defined in this story world which has the given signature or throws an exception if it does not exist.
    Returns the ending defined in this story world which has the given name or throws an exception if it does not exist.
    requireEntity(int id)
    Returns the entity defined in this story world which has the given ID number or throws an exception if it does not exist.
    Returns the entity defined in this story world which has the given name or throws an exception if it does not exist.
    Returns the variable defined in this story world which has the given ID number or throws an exception if it does not exist.
    Returns the variable defined in this story world which has the given signature or throws an exception if it does not exist.
    Returns the variable defined in this story world which has the given name or throws an exception if it does not exist.
     
    <A extends Asset>
    A
    validate(A asset)
    If this story world contains an asset matching the name of the given asset, the asset from this story world world with that name is returned; otherwise, an exception is thrown.
    validate(Action action)
    If this story world contains an action matching the name of the given action, the action from this story world world with that name is returned; otherwise, an exception is thrown.
    validate(Ending ending)
    If this story world contains an ending matching the name of the given ending, the ending from this story world world with that name is returned; otherwise, an exception is thrown.
    validate(Entity entity)
    If this story world contains an entity matching the name of the given entity, the entity from this story world world with that name is returned; otherwise, an exception is thrown.
    validate(Variable variable)
    If this story world contains a variable matching the name of the given variable, the variable from this story world world with that name is returned; otherwise, an exception is thrown.

    Methods inherited from class Object

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

    • name

      public final String name
      The unique name of this story world
  • Constructor Details

    • World

      public World(String name, Collection<Entity> entities, Collection<Variable> variables, Collection<Action> actions, Collection<Ending> endings)
      Constructs a story world from a unique name and sets of assets. During the construction process, the assets will be remade and given appropriate sequential unique ID numbers.
      Parameters:
      name - a unique name for the story world
      entities - a collection of objects that exist in the world
      variables - a collection of variables whose values can change and whose current values reflect the current state of the world
      actions - a collection of ways the world state can change
      endings - a collection of ways a story in this world can end
      Throws:
      IllegalArgumentException - if the provided assets do not meet the required format, such as two assets of the same type having the same name
    • World

      public World(AssetBuilder builder)
      Constructs a story world from the assets defined in an asset builder.
      Parameters:
      builder - the asset builder that defines the assets to be used in this story world
      Throws:
      IllegalArgumentException - if the provided assets do not meet the required format, such as two assets of the same type having the same name
  • Method Details

    • toString

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

      public String getName()
      Description copied from interface: Named
      Returns this object's unique name that distinguishes it from other objects of the same type in the same context.
      Specified by:
      getName in interface Named
      Returns:
      the object's unique name
    • getPlayer

      public Entity getPlayer()
      Returns the entity the represents the player character in this story world.
      Returns:
      the player character entity
    • contains

      public boolean contains(Entity entity)
      Returns true if the given entity is defined in this story world.
      Parameters:
      entity - an entity
      Returns:
      true if this entity is defined in this story world, false otherwise
    • validate

      public Entity validate(Entity entity)
      If this story world contains an entity matching the name of the given entity, the entity from this story world world with that name is returned; otherwise, an exception is thrown.
      Parameters:
      entity - an entity
      Returns:
      the entity from this story world with the same name as the given entity
      Throws:
      IllegalArgumentException - if this story world does not define an entity with that name
    • getEntities

      public List<Entity> getEntities()
      Returns an unmodifiable list of all entities defined in this story world ordered by the ID numbers.
      Returns:
      a list of entities defined in this story world
    • getEntity

      public Entity getEntity(int id)
      Returns the entity defined in this story world which has the given ID number.
      Parameters:
      id - the ID number of the desired entity
      Returns:
      the entity with that ID number
      Throws:
      IndexOutOfBoundsException - if there is no entity in this story world with that ID number
    • getEntity

      public Entity getEntity(String name)
      Returns the entity defined in this story world which has the given name.
      Parameters:
      name - the name of the desired entity
      Returns:
      the entity with that name, or null if no entity has that name
    • requireEntity

      public Entity requireEntity(int id)
      Returns the entity defined in this story world which has the given ID number or throws an exception if it does not exist.
      Parameters:
      id - the ID number of the desired entity
      Returns:
      the entity with that ID number
      Throws:
      IllegalArgumentException - if no entity exists with that ID number
    • requireEntity

      public Entity requireEntity(String name)
      Returns the entity defined in this story world which has the given name or throws an exception if it does not exist.
      Parameters:
      name - the name of the desired entity
      Returns:
      the entity with that name
      Throws:
      IllegalArgumentException - if no entity exists with that name
    • contains

      public boolean contains(Variable variable)
      Returns true if the given variable is defined in this story world.
      Parameters:
      variable - a variable
      Returns:
      true if this variable is defined in this story world, false otherwise
    • validate

      public Variable validate(Variable variable)
      If this story world contains a variable matching the name of the given variable, the variable from this story world world with that name is returned; otherwise, an exception is thrown.
      Parameters:
      variable - a variable
      Returns:
      the variable from this story world with the same name as the given variable
      Throws:
      IllegalArgumentException - if this story world does not define a variable with that name
    • getVariables

      public List<Variable> getVariables()
      Returns an unmodifiable list of all variables defined in this story world ordered by the ID numbers.
      Returns:
      a list of variables defined in this story world
    • getVariable

      public Variable getVariable(int id)
      Returns the variable defined in this story world which has the given ID number.
      Parameters:
      id - the ID number of the desired variable
      Returns:
      the variable with that ID number
      Throws:
      IndexOutOfBoundsException - if there is no variables in this story world with that ID number
    • getVariable

      public Variable getVariable(String name)
      Returns the variable defined in this story world which has the given name.
      Parameters:
      name - the name of the desired variable
      Returns:
      the variable with that name, or null if no variable has that name
    • getVariable

      public Variable getVariable(Signature signature)
      Returns the variable defined in this story world which has the given signature.
      Parameters:
      signature - the signature of the desired variable
      Returns:
      the variable with that signature, or null if no variable has that signature
    • requireVariable

      public Variable requireVariable(int id)
      Returns the variable defined in this story world which has the given ID number or throws an exception if it does not exist.
      Parameters:
      id - the ID number of the desired variable
      Returns:
      the variable with that ID number
      Throws:
      IllegalArgumentException - if no variable exists with that ID number
    • requireVariable

      public Variable requireVariable(String name)
      Returns the variable defined in this story world which has the given name or throws an exception if it does not exist.
      Parameters:
      name - the name of the desired variable
      Returns:
      the variable with that name
      Throws:
      IllegalArgumentException - if no variable exists with that name
    • requireVariable

      public Variable requireVariable(Signature signature)
      Returns the variable defined in this story world which has the given signature or throws an exception if it does not exist.
      Parameters:
      signature - the signature of the desired variable
      Returns:
      the variable with that signature
      Throws:
      IllegalArgumentException - if no variable exists with that signature
    • contains

      public boolean contains(Action action)
      Returns true if the given action is defined in this story world.
      Parameters:
      action - an action
      Returns:
      true if this action is defined in this story world, false otherwise
    • validate

      public Action validate(Action action)
      If this story world contains an action matching the name of the given action, the action from this story world world with that name is returned; otherwise, an exception is thrown.
      Parameters:
      action - an action
      Returns:
      the action from this story world with the same name as the given action
      Throws:
      IllegalArgumentException - if this story world does not define an action with that name
    • getActions

      public List<Action> getActions()
      Returns an unmodifiable list of all actions defined in this story world ordered by the ID numbers.
      Returns:
      a list of actions defined in this story world
    • getAction

      public Action getAction(int id)
      Returns the action defined in this story world which has the given ID number.
      Parameters:
      id - the ID number of the desired action
      Returns:
      the action with that ID number
      Throws:
      IndexOutOfBoundsException - if there is no action in this story world with that ID number
    • getAction

      public Action getAction(String name)
      Returns the action defined in this story world which has the given name.
      Parameters:
      name - the name of the desired action
      Returns:
      the action with that name, or null if no action has that name
    • getAction

      public Action getAction(Signature signature)
      Returns the action defined in this story world which has the given signature.
      Parameters:
      signature - the signature of the desired action
      Returns:
      the action with that signature, or null if no action has that signature
    • requireAction

      public Action requireAction(int id)
      Returns the action defined in this story world which has the given ID number or throws an exception if it does not exist.
      Parameters:
      id - the ID number of the desired action
      Returns:
      the action with that ID number
      Throws:
      IllegalArgumentException - if no action exists with that ID number
    • requireAction

      public Action requireAction(String name)
      Returns the action defined in this story world which has the given name or throws an exception if it does not exist.
      Parameters:
      name - the name of the desired action
      Returns:
      the action with that name
      Throws:
      IllegalArgumentException - if no action exists with that name
    • requireAction

      public Action requireAction(Signature signature)
      Returns the action defined in this story world which has the given signature or throws an exception if it does not exist.
      Parameters:
      signature - the signature of the desired action
      Returns:
      the action with that signature
      Throws:
      IllegalArgumentException - if no action exists with that signature
    • contains

      public boolean contains(Ending ending)
      Returns true if the given ending is defined in this story world.
      Parameters:
      ending - an ending
      Returns:
      true if this ending is defined in this story world, false otherwise
    • validate

      public Ending validate(Ending ending)
      If this story world contains an ending matching the name of the given ending, the ending from this story world world with that name is returned; otherwise, an exception is thrown.
      Parameters:
      ending - an ending
      Returns:
      the ending from this story world with the same name as the given ending
      Throws:
      IllegalArgumentException - if this story world does not define an ending with that name
    • getEndings

      public List<Ending> getEndings()
      Returns an unmodifiable list of all endings defined in this story world ordered by the ID numbers.
      Returns:
      a list of endings defined in this story world
    • getEnding

      public Ending getEnding(int id)
      Returns the ending defined in this story world which has the given ID number.
      Parameters:
      id - the ID number of the desired ending
      Returns:
      the ending with that ID number
      Throws:
      IndexOutOfBoundsException - if there is no ending in this story world with that ID number
    • getEnding

      public Ending getEnding(String name)
      Returns the ending defined in this story world which has the given name.
      Parameters:
      name - the name of the desired ending
      Returns:
      the ending with that name, or null if no ending has that name
    • getEnding

      public Ending getEnding(Signature signature)
      Returns the ending defined in this story world which has the given signature.
      Parameters:
      signature - the signature of the desired ending
      Returns:
      the ending with that signature, or null if no ending has that signature
    • requireEnding

      public Ending requireEnding(int id)
      Returns the ending defined in this story world which has the given ID number or throws an exception if it does not exist.
      Parameters:
      id - the ID number of the desired ending
      Returns:
      the ending with that ID number
      Throws:
      IllegalArgumentException - if no ending exists with that ID number
    • requireEnding

      public Ending requireEnding(String name)
      Returns the ending defined in this story world which has the given name or throws an exception if it does not exist.
      Parameters:
      name - the name of the desired ending
      Returns:
      the ending with that name
      Throws:
      IllegalArgumentException - if no ending exists with that name
    • requireEnding

      public Ending requireEnding(Signature signature)
      Returns the ending defined in this story world which has the given signature or throws an exception if it does not exist.
      Parameters:
      signature - the signature of the desired ending
      Returns:
      the ending with that signature
      Throws:
      IllegalArgumentException - if no ending exists with that signature
    • validate

      public <A extends Asset> A validate(A asset)
      If this story world contains an asset matching the name of the given asset, the asset from this story world world with that name is returned; otherwise, an exception is thrown.
      Type Parameters:
      A - the type of asset being validated
      Parameters:
      asset - the asset
      Returns:
      the asset from this story world of the given type with the same name
      Throws:
      IllegalArgumentException - if this story world does not define an asset with that name