java.lang.Object
de.hamstersimulator.objectsfirst.internal.model.territory.TerritoryBuilder

public class TerritoryBuilder extends Object
Objects of this class can be used to define Hamster territories. The builder objects track all operations used to define the territory and finally create a large composite command that initializes the defined territory.
Author:
Steffen Becker
  • Method Details

    • getTerritoryBuilderForTerritory

      public static TerritoryBuilder getTerritoryBuilderForTerritory(EditorTerritory territory)
      Factory method to create new TerritoryBuilder objects which then can be used to defined the given territory.
      Parameters:
      territory - The territory which should be built.
      Returns:
      A TerritoryBuilder object for the given territory.
    • initializeTerritory

      public TerritoryBuilder initializeTerritory(Size size)
      Defines a new territory by deleting all elements of the territory defined so far and by creating a new, empty territory of the given size.
      Parameters:
      size - The size to which the territory should be initialized
      Returns:
      The builder again for a fluent API use case
    • wallAt

      public TerritoryBuilder wallAt(Location location)
      Place a wall at the given location. The location has to be empty before a wall can be placed.
      Parameters:
      location - The location of the new wall.
      Returns:
      The builder again for a fluent API use case.
    • defaultHamsterAt

      public TerritoryBuilder defaultHamsterAt(Location location, Direction direction, int grainCount)
      Puts the default hamster (paule) on the territory and initializes it. The location of the hamster must not be blocked by a wall.
      Parameters:
      location - Location where the default hamster will be placed.
      direction - The direction into which the default hamster will look.
      grainCount - The initial amount of grains the default hamster carries in his mouth.
      Returns:
      The builder again for a fluent API use case.
    • grainAt

      public TerritoryBuilder grainAt(Location location, int grainCount)
      Puts a number of grains at the given location. The location must not be blocked by a wall.
      Parameters:
      location - Location where the new grains will be put at.
      grainCount - The number of new grains to put.
      Returns:
      The builder again for a fluent API use case.
    • grainAt

      public TerritoryBuilder grainAt(Location location)
      Puts a single grain at the given location. The location must not be blocked by a wall.
      Parameters:
      location - Location where the new grain will be put at.
      Returns:
      The builder again for a fluent API use case.
    • build

      public Command build()
      Executing this command returns a composite command which initializes the territory according to all builder commands issued before. It has to be the last command used on this builder object. After calling build, this TerritoryBuilder should not be used any longer. Also applies all preconditions to this command
      Returns:
      A command which, when executed on an editable territory, initializes that territory.
    • addPreconditionCreator

      public void addPreconditionCreator(Consumer<CompositeCommand.PreconditionBuilder> preconditionCreator)
      Adds a Consumer which can add preconditions to a CompositeCommand via a PreconditionBuilder
      Parameters:
      preconditionCreator - the consumer which has to handle the PreconditionBuilder