Class Environment
- java.lang.Object
- 
- jadex.bdi.examples.garbagecollector_classic.Environment
 
- 
 public class Environment extends java.lang.ObjectThe environment.
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringBURNERThe world object/agent types.static java.lang.StringCOLLECTORstatic java.lang.StringDOWNstatic java.lang.StringGARBAGEprotected static Environmentinstancestatic java.lang.StringLEFTprotected java.util.Mapname_objectsThe agents (name -> agent info).SimplePropertyChangeSupportpcsThe helper object for bean events.protected MultiCollectionpos_objectsThe garbages.protected java.util.RandomrandgenThe random number generator.static java.lang.StringRIGHTprotected intsizeThe size.static java.lang.StringUPThe directions.
 - 
Constructor SummaryConstructors Constructor Description Environment(int size)Create an environment.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(PropertyChangeListener listener)Add a PropertyChangeListener to the listener list.voidaddWorldObject(java.lang.String type, java.lang.String name, Position pos)Add an object to the environment.voidburn(java.lang.String name)Burn a piece of garbage.static voidclearInstance()Clear the singleton instance.voiddrop(java.lang.String name)Drop a piece of garbage.PositiongetBurnerPosition()Get the position of a burner.protected PositiongetFreePosition()Get a free position on the map.jadex.bdi.examples.garbagecollector_classic.WorldObject[]getGarbages(Position pos)Get all world objects of a position.intgetGridSize()Get the grid size.static EnvironmentgetInstance(java.lang.String type, java.lang.String name)Get a singleton instance.PositiongetPosition(java.lang.String name)Get the position of an object.protected PositiongetRandomPosition()Get a free position on the map.protected jadex.bdi.examples.garbagecollector_classic.WorldObjectgetRobot(java.lang.String name)Get an robot for a name.protected jadex.bdi.examples.garbagecollector_classic.WorldObjectgetWorldObject(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.voidgo(java.lang.String name, java.lang.String dir)Go in a specific direction.booleanhasGarbage(java.lang.String name)Test if an agent has garbage.booleanisBurnerPresent(Position pos)Is a burner on the map.booleanisDirty(Position pos)Test if a position is dirty.protected booleanisFree(Position pos)Test if a position is free.booleanpickup(java.lang.String name)Pickup a piece of garbage.voidremovePropertyChangeListener(PropertyChangeListener listener)Remove a PropertyChangeListener from the listener list.voidsetWorldObjects(jadex.bdi.examples.garbagecollector_classic.WorldObject[] objects)Set the world objects.
 
- 
- 
- 
Field Detail- 
UPpublic static final java.lang.String UP The directions.- See Also:
- Constant Field Values
 
 - 
DOWNpublic static final java.lang.String DOWN - See Also:
- Constant Field Values
 
 - 
LEFTpublic static final java.lang.String LEFT - See Also:
- Constant Field Values
 
 - 
RIGHTpublic static final java.lang.String RIGHT - See Also:
- Constant Field Values
 
 - 
BURNERpublic static final java.lang.String BURNER The world object/agent types.- See Also:
- Constant Field Values
 
 - 
COLLECTORpublic static final java.lang.String COLLECTOR - See Also:
- Constant Field Values
 
 - 
GARBAGEpublic static final java.lang.String GARBAGE - See Also:
- Constant Field Values
 
 - 
sizeprotected int size The size.
 - 
name_objectsprotected java.util.Map name_objects The agents (name -> agent info).
 - 
pos_objectsprotected MultiCollection pos_objects The garbages.
 - 
randgenprotected java.util.Random randgen The random number generator.
 - 
pcspublic SimplePropertyChangeSupport pcs The helper object for bean events.
 - 
instanceprotected static volatile Environment instance 
 
- 
 - 
Method Detail- 
getInstancepublic static Environment getInstance(java.lang.String type, java.lang.String name) Get a singleton instance.
 - 
clearInstancepublic static void clearInstance() Clear the singleton instance.
 - 
addWorldObjectpublic void addWorldObject(java.lang.String type, java.lang.String name, Position pos)Add an object to the environment.
 - 
gopublic void go(java.lang.String name, java.lang.String dir)Go in a specific direction.
 - 
droppublic void drop(java.lang.String name) Drop a piece of garbage.- Parameters:
- name- The name of the agent that want to drop.
 
 - 
pickuppublic boolean pickup(java.lang.String name) Pickup a piece of garbage.- Parameters:
- name- The name of the agent that want to pick up.
 
 - 
burnpublic void burn(java.lang.String name) Burn a piece of garbage.- Parameters:
- name- The name of the agent that want to drop.
 
 - 
isDirtypublic 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.
 
 - 
hasGarbagepublic boolean hasGarbage(java.lang.String name) Test if an agent has garbage.- Parameters:
- name- The agent name.
- Returns:
- True, if has garbage.
 
 - 
getPositionpublic Position getPosition(java.lang.String name) Get the position of an object.- Parameters:
- name- The name of the agent.
- Returns:
- The position.
 
 - 
getGridSizepublic int getGridSize() Get the grid size.- Returns:
- The size of the grid.
 
 - 
getBurnerPositionpublic Position getBurnerPosition() Get the position of a burner.- Returns:
- The (first found, hack) position of a burner.
 
 - 
isBurnerPresentpublic boolean isBurnerPresent(Position pos) Is a burner on the map.- Parameters:
- pos- The position to test.
- Returns:
- True, if a burner is present.
 
 - 
getWorldObjectprotected 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.
 
 - 
getRobotprotected 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.
 
 - 
getWorldObjectsprotected 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.
 
 - 
getGarbagespublic 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.
 
 - 
getWorldObjectspublic jadex.bdi.examples.garbagecollector_classic.WorldObject[] getWorldObjects() Get the world objects.- Returns:
- Get all world objects (except pickuped garbage).
 
 - 
setWorldObjectspublic void setWorldObjects(jadex.bdi.examples.garbagecollector_classic.WorldObject[] objects) Set the world objects.
 - 
getFreePositionprotected Position getFreePosition() Get a free position on the map.- Returns:
- The next free position on the grid.
 
 - 
getRandomPositionprotected Position getRandomPosition() Get a free position on the map.- Returns:
- The next free position on the grid.
 
 - 
isFreeprotected boolean isFree(Position pos) Test if a position is free.- Returns:
- True, if a position is free.
 
 - 
addPropertyChangeListenerpublic 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.
 
 - 
removePropertyChangeListenerpublic 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.
 
 
- 
 
-