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