Class GreedyEntity
- java.lang.Object
-
- de.unistuttgart.informatik.fius.icge.simulation.entity.BasicEntity
-
- de.unistuttgart.informatik.fius.icge.simulation.entity.MovableEntity
-
- de.unistuttgart.informatik.fius.icge.simulation.entity.GreedyEntity
-
- All Implemented Interfaces:
Entity
,EntityCollector
public abstract class GreedyEntity extends MovableEntity implements EntityCollector
A movable entity collector.- Author:
- Tim Neumann
-
-
Field Summary
Fields Modifier and Type Field Description protected Object
inventoryOperationLock
A lock to synchronize all operations involving the entities inventory.-
Fields inherited from class de.unistuttgart.informatik.fius.icge.simulation.entity.BasicEntity
endOfLastEnqueuedOperation
-
-
Constructor Summary
Constructors Constructor Description GreedyEntity()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canCarry(Class<? extends CollectableEntity> type)
Check if this can collect and drop the given collectable entity type.void
collect(CollectableEntity entity)
Collect the given entity.void
drop(CollectableEntity entity)
Drop the given entity at the current position.void
drop(CollectableEntity entity, Position pos)
Drop the given entity.<T extends CollectableEntity>
List<T>getCurrentlyCollectableEntities(Class<T> type, boolean includeSubclasses)
Get all the currently collectable entities of the given type<T extends CollectableEntity>
List<T>getCurrentlyDroppableEntities(Class<T> type, boolean includeSubclasses)
Get all the currently droppable entities of the given typeInventory
getInventory()
-
Methods inherited from class de.unistuttgart.informatik.fius.icge.simulation.entity.MovableEntity
canMove, getDrawInformation, getLookingDirection, getLookingDirectionString, move, moveIfPossible, turnClockWise
-
Methods inherited from class de.unistuttgart.informatik.fius.icge.simulation.entity.BasicEntity
enqueueToPerformNewOperation, getPlayfield, getPosition, getSimulation, getTextureHandle, getZPosition, initOnPlayfield, isOnPlayfield, sleep, toString
-
-
-
-
Field Detail
-
inventoryOperationLock
protected final Object inventoryOperationLock
A lock to synchronize all operations involving the entities inventory.
-
-
Method Detail
-
getInventory
public Inventory getInventory()
- Returns:
- the inventory of this greedy entity
-
canCarry
public boolean canCarry(Class<? extends CollectableEntity> type)
Description copied from interface:EntityCollector
Check if this can collect and drop the given collectable entity type.- Specified by:
canCarry
in interfaceEntityCollector
- Parameters:
type
- The type to check; must not be null- Returns:
- true if this entity collector can collect or drop the given entity type
-
getCurrentlyCollectableEntities
public <T extends CollectableEntity> List<T> getCurrentlyCollectableEntities(Class<T> type, boolean includeSubclasses)
Get all the currently collectable entities of the given type- Type Parameters:
T
- The generic type to return the entities as- Parameters:
type
- The type of entity to get; must not be nullincludeSubclasses
- Whether to include the subclasses of the given type- Returns:
- A list of currently collectable entities matching the type
-
collect
public void collect(CollectableEntity entity)
Description copied from interface:EntityCollector
Collect the given entity.- Specified by:
collect
in interfaceEntityCollector
- Parameters:
entity
- The entity to collect; must not be null; must be collectable by this
-
getCurrentlyDroppableEntities
public <T extends CollectableEntity> List<T> getCurrentlyDroppableEntities(Class<T> type, boolean includeSubclasses)
Get all the currently droppable entities of the given type- Type Parameters:
T
- The generic type to return the entities as- Parameters:
type
- The type of entity to get; must not be nullincludeSubclasses
- Whether to include the subclasses of the given type- Returns:
- A list of currently collectable entities matching the type
-
drop
public void drop(CollectableEntity entity, Position pos)
Description copied from interface:EntityCollector
Drop the given entity.- Specified by:
drop
in interfaceEntityCollector
- Parameters:
entity
- The entity to drop;must not be null; must be droppable by thispos
- The position to drop the entity at; must not be null
-
drop
public void drop(CollectableEntity entity)
Drop the given entity at the current position.- Parameters:
entity
- The entity to drop;must not be null; must be droppable by this *- Throws:
CannotDropEntityException
- if the given entity cannot be dropped right now for any reasonIllegalArgumentException
- if an argument is null
-
-