Class Environment
- java.lang.Object
-
- jadex.bdi.examples.garbagecollector_classic.Environment
-
public class Environment extends java.lang.ObjectThe environment.
-
-
Field Summary
Fields 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 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 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
-
UP
public static final java.lang.String UP
The directions.- See Also:
- Constant Field Values
-
DOWN
public static final java.lang.String DOWN
- See Also:
- Constant Field Values
-
LEFT
public static final java.lang.String LEFT
- See Also:
- Constant Field Values
-
RIGHT
public static final java.lang.String RIGHT
- See Also:
- Constant Field Values
-
BURNER
public static final java.lang.String BURNER
The world object/agent types.- See Also:
- Constant Field Values
-
COLLECTOR
public static final java.lang.String COLLECTOR
- See Also:
- Constant Field Values
-
GARBAGE
public static final java.lang.String GARBAGE
- See Also:
- Constant Field Values
-
size
protected int size
The size.
-
name_objects
protected java.util.Map name_objects
The agents (name -> agent info).
-
pos_objects
protected MultiCollection pos_objects
The garbages.
-
randgen
protected java.util.Random randgen
The random number generator.
-
pcs
public SimplePropertyChangeSupport pcs
The helper object for bean events.
-
instance
protected static volatile Environment instance
-
-
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.
-
-