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 ObjectinventoryOperationLockA 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 booleancanCarry(Class<? extends CollectableEntity> type)Check if this can collect and drop the given collectable entity type.voidcollect(CollectableEntity entity)Collect the given entity.voiddrop(CollectableEntity entity)Drop the given entity at the current position.voiddrop(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 typeInventorygetInventory()-
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:EntityCollectorCheck if this can collect and drop the given collectable entity type.- Specified by:
canCarryin 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:EntityCollectorCollect the given entity.- Specified by:
collectin 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:EntityCollectorDrop the given entity.- Specified by:
dropin 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
-
-