Class Environment


  • public class Environment
    extends java.lang.Object
    The environment.
    • Constructor Summary

      Constructors 
      Constructor Description
      Environment​(int size)
      Create an environment.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPropertyChangeListener​(PropertyChangeListener listener)
      Add a PropertyChangeListener to the listener list.
      void addWorldObject​(java.lang.String type, java.lang.String name, Position pos)
      Add an object to the environment.
      void burn​(java.lang.String name)
      Burn a piece of garbage.
      static void clearInstance()
      Clear the singleton instance.
      void drop​(java.lang.String name)
      Drop a piece of garbage.
      Position getBurnerPosition()
      Get the position of a burner.
      protected Position getFreePosition()
      Get a free position on the map.
      jadex.bdi.examples.garbagecollector_classic.WorldObject[] getGarbages​(Position pos)
      Get all world objects of a position.
      int getGridSize()
      Get the grid size.
      static Environment getInstance​(java.lang.String type, java.lang.String name)
      Get a singleton instance.
      Position getPosition​(java.lang.String name)
      Get the position of an object.
      protected Position getRandomPosition()
      Get a free position on the map.
      protected jadex.bdi.examples.garbagecollector_classic.WorldObject getRobot​(java.lang.String name)
      Get an robot for a name.
      protected jadex.bdi.examples.garbagecollector_classic.WorldObject getWorldObject​(java.lang.String name)
      Get an world object for a name.
      jadex.bdi.examples.garbagecollector_classic.WorldObject[] getWorldObjects()
      Get the world objects.
      protected jadex.bdi.examples.garbagecollector_classic.WorldObject[] getWorldObjects​(Position pos)
      Get all world objects of a position.
      void go​(java.lang.String name, java.lang.String dir)
      Go in a specific direction.
      boolean hasGarbage​(java.lang.String name)
      Test if an agent has garbage.
      boolean isBurnerPresent​(Position pos)
      Is a burner on the map.
      boolean isDirty​(Position pos)
      Test if a position is dirty.
      protected boolean isFree​(Position pos)
      Test if a position is free.
      boolean pickup​(java.lang.String name)
      Pickup a piece of garbage.
      void removePropertyChangeListener​(PropertyChangeListener listener)
      Remove a PropertyChangeListener from the listener list.
      void setWorldObjects​(jadex.bdi.examples.garbagecollector_classic.WorldObject[] objects)
      Set the world objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Environment

        public Environment​(int size)
        Create an environment.
    • Method Detail

      • getInstance

        public static Environment getInstance​(java.lang.String type,
                                              java.lang.String name)
        Get a singleton instance.
      • clearInstance

        public static void clearInstance()
        Clear the singleton instance.
      • addWorldObject

        public void addWorldObject​(java.lang.String type,
                                   java.lang.String name,
                                   Position pos)
        Add an object to the environment.
      • go

        public void go​(java.lang.String name,
                       java.lang.String dir)
        Go in a specific direction.
      • drop

        public void drop​(java.lang.String name)
        Drop a piece of garbage.
        Parameters:
        name - The name of the agent that want to drop.
      • pickup

        public boolean pickup​(java.lang.String name)
        Pickup a piece of garbage.
        Parameters:
        name - The name of the agent that want to pick up.
      • burn

        public void burn​(java.lang.String name)
        Burn a piece of garbage.
        Parameters:
        name - The name of the agent that want to drop.
      • isDirty

        public boolean isDirty​(Position pos)
        Test if a position is dirty.
        Parameters:
        pos - The position.
        Returns:
        True, if one or more pieces of garbage are present.
      • hasGarbage

        public boolean hasGarbage​(java.lang.String name)
        Test if an agent has garbage.
        Parameters:
        name - The agent name.
        Returns:
        True, if has garbage.
      • getPosition

        public Position getPosition​(java.lang.String name)
        Get the position of an object.
        Parameters:
        name - The name of the agent.
        Returns:
        The position.
      • getGridSize

        public int getGridSize()
        Get the grid size.
        Returns:
        The size of the grid.
      • getBurnerPosition

        public Position getBurnerPosition()
        Get the position of a burner.
        Returns:
        The (first found, hack) position of a burner.
      • isBurnerPresent

        public boolean isBurnerPresent​(Position pos)
        Is a burner on the map.
        Parameters:
        pos - The position to test.
        Returns:
        True, if a burner is present.
      • getWorldObject

        protected jadex.bdi.examples.garbagecollector_classic.WorldObject getWorldObject​(java.lang.String name)
        Get an world object for a name.
        Parameters:
        name - The name of the world object.
        Returns:
        The world object.
      • getRobot

        protected jadex.bdi.examples.garbagecollector_classic.WorldObject getRobot​(java.lang.String name)
        Get an robot for a name.
        Parameters:
        name - The agents name.
        Returns:
        The agent.
      • getWorldObjects

        protected jadex.bdi.examples.garbagecollector_classic.WorldObject[] getWorldObjects​(Position pos)
        Get all world objects of a position.
        Parameters:
        pos - The position.
        Returns:
        All objects at the position.
      • getGarbages

        public jadex.bdi.examples.garbagecollector_classic.WorldObject[] getGarbages​(Position pos)
        Get all world objects of a position.
        Parameters:
        pos - The position.
        Returns:
        All objects at the position.
      • getWorldObjects

        public jadex.bdi.examples.garbagecollector_classic.WorldObject[] getWorldObjects()
        Get the world objects.
        Returns:
        Get all world objects (except pickuped garbage).
      • setWorldObjects

        public void setWorldObjects​(jadex.bdi.examples.garbagecollector_classic.WorldObject[] objects)
        Set the world objects.
      • getFreePosition

        protected Position getFreePosition()
        Get a free position on the map.
        Returns:
        The next free position on the grid.
      • getRandomPosition

        protected Position getRandomPosition()
        Get a free position on the map.
        Returns:
        The next free position on the grid.
      • isFree

        protected boolean isFree​(Position pos)
        Test if a position is free.
        Returns:
        True, if a position is free.
      • addPropertyChangeListener

        public void addPropertyChangeListener​(PropertyChangeListener listener)
        Add a PropertyChangeListener to the listener list. The listener is registered for all properties.
        Parameters:
        listener - The PropertyChangeListener to be added.
      • removePropertyChangeListener

        public void removePropertyChangeListener​(PropertyChangeListener listener)
        Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.
        Parameters:
        listener - The PropertyChangeListener to be removed.