Package jsl.modeling.elements.entity
Class Entity
- java.lang.Object
-
- jsl.modeling.queue.QObject
-
- jsl.modeling.elements.entity.Entity
-
- All Implemented Interfaces:
java.lang.Comparable<QObject>
,java.lang.Iterable<Entity>
,java.util.Collection<Entity>
,java.util.List<Entity>
,EntityReceiverIteratorIfc
,GetNameIfc
public class Entity extends QObject implements EntityReceiverIteratorIfc, java.util.List<Entity>
-
-
Field Summary
-
Fields inherited from class jsl.modeling.queue.QObject
myTimeStamp, myValue
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Entity(EntityType entityType, java.lang.String name)
Creates an Entity with the given name and the creation time set to the current simulation time
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int i, Entity e)
Adds an entity to the entity's group Preconditions: e must not be null, e must not already be in groupboolean
add(Entity e)
Adds an entity to the entity's group Preconditions: e must not be null, e must not already be in groupboolean
addAll(int i, java.util.Collection<? extends Entity> clctn)
The collection must not have any null elements or any elements that are already part of the entity's groupboolean
addAll(java.util.Collection<? extends Entity> clctn)
The collection must not have any null elements or any elements that are already part of the entity's groupvoid
addAttribute(java.lang.String attributeName, AttributeIfc attribute)
Adds the named attribute to the entity as a valid attribute Arguments must be non-null, or exceptions will be thrown.void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> clctn)
boolean
containsAllocation(Allocation a)
Checks if the entity has the supplied allocationboolean
containsAllocation(Resource r)
Checks of the entity has an allocation for the supplied resourceboolean
containsAttribute(java.lang.String attributeName)
Returns whether or not the attribute has been named for this entityvoid
dispose()
Causes the entity to be disposed.Entity
get(int i)
Allocation
getAllocation(Resource r)
Gets the allocation for the supplied resource or null if no allocation existsint
getAmount()
This can be used by clients to set an amount, generally used when seizing resources.double
getAttributeValue(java.lang.String attributeName)
Gets the value of the attribute using the GetValueIfcEntityReceiverAbstract
getCurrentReceiver()
Gets the receiver that most recently received the entity This may be null if the entity has never been receiveddouble
getDurationTime()
Returns the duration time.EntityReceiverAbstract
getEntityReceiverAt(int index)
Returns the EntityReceiver at the supplied index for the EntityType.java.lang.Object
getMessage()
ProcessExecutor
getProcessExecutor()
Gets a reference to the process executor that is currently executing with the entity.java.util.SortedSet<ReleaseRequirement>
getReleaseRequirements()
java.util.List<SeizeRequirement>
getSeizeRequirements()
double
getTimeEnteredReceiver()
Returns the time that the entity was last received by a receiver.EntityType
getType()
boolean
getUseAmountFlag()
This can be used by clients to indicate whether they should used getAmount().boolean
getUseDurationFlag()
This can be used by clients to indicate whether they should use getDurationTime().boolean
hasAllocations()
Checks if the entity has any allocations from resourcesboolean
hasNextEntityReceiver()
Checks if there is a next entity receiver for this entity Returns false if no next receiverboolean
hasPreviousEntityReceiver()
Checks if there is a previous entity receiver for this entity Returns false if no previous receiverboolean
hasReceiverSequence()
Returns true if the entity was supplied a receiver sequence from its entity typeint
indexOf(java.lang.Object o)
boolean
isEmpty()
java.util.Iterator<Entity>
iterator()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<Entity>
listIterator()
java.util.ListIterator<Entity>
listIterator(int i)
EntityReceiverAbstract
nextEntityReceiver()
Gets the next receiver for this entity Returns null if no next receiverint
nextEntityReceiverIndex()
Returns the index of the next entity receiver in the iterator sequence.void
nullify()
Causes all references to objects from this QObject to be set to null and all internal objects to be set to null including State informationEntityReceiverAbstract
peekNextEntityReceiver()
Peeks at the next receiver, without advancing to the next receiver Returns null if no receiver is nextEntityReceiverAbstract
peekPreviousEntityReceiver()
Peeks at the previous receiver, without moving to the previous Returns null if no previous receiver is availableEntityReceiverAbstract
previousEntityReceiver()
Gets the previous receiver for this entity Returns null if no previous receiverint
previousEntityReceiverIndex()
Returns the index of the next entity receiver in the iterator sequence.void
release(Resource resource)
A convenience method that allows an entity to release a resource that it has previously had allocated.Entity
remove(int i)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> clctn)
protected void
requestFullyAllocated(Request request)
This method can be overridden to react to the request receiving its full allocation of the desired resourceprotected void
requestReleased(Request request)
This method can be overridden to react to the request releasing its associated resourceboolean
resetReceiverSequence()
Resets the entity's receiver sequence to the beginning Returns true if a receiver sequence existsboolean
retainAll(java.util.Collection<?> clctn)
void
sendViaEntityType()
Causes the entity to be sent to a destination (receiver) as specified by its EntityType based on its current location (receiver)void
sendViaReceiver(EntityReceiverAbstract receiver)
Causes the entity to be sent to the receiver.void
sendViaReceiver(EntityReceiverAbstract receiver, double time)
Causes the entity to be sent to the receiver.void
sendViaReceiver(EntityReceiverAbstract receiver, GetValueIfc time)
Causes the entity to be sent to the receiver.void
sendViaSequence()
Causes the entity to be sent to the next receiver in its sequence (i.e.void
sendViaSequence(double time)
Causes the entity to be sent to the next receiver in its sequence (i.e.Entity
set(int i, Entity e)
Preconditions: e must not be null, and must not already be in the groupvoid
setAmount(int amount)
This can be used by clients to set an amount, generally used when seizing resources.void
setAttributeValue(java.lang.String attributeName, double value)
Allows the user to set the value of the named attribute to the given valueprotected void
setCurrentReceiver(EntityReceiverAbstract receiver)
Sets the current receiverprotected void
setCurrentReceiver(GetEntityReceiverIfc getter)
void
setDurationTime(double durationTime)
Sets the duration time.void
setMessage(java.lang.Object message)
protected void
setPlannedReceiver(EntityReceiverAbstract receiver)
Sets the current receiverprotected void
setPlannedReceiver(GetEntityReceiverIfc getter)
void
setProcessExecutor(ProcessExecutor processExecutor)
This is used by the ProcessExecutor to tell the entity what process executor it is currently executing within.protected void
setTimeEnteredReceiver(double time)
Used to set the time that the entity last entered a receiverprotected void
setType(EntityType entityType)
Sets the type of the entity.void
setUseAmountFlag(boolean flag)
This can be used by clients to indicate whether they should used getAmount().void
setUseDurationFlag(boolean flag)
This can be used by clients to indicate whether they should used getDurationTime().int
size()
java.util.List<Entity>
subList(int i, int i1)
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] ts)
-
Methods inherited from class jsl.modeling.queue.QObject
compareTo, enterQueue, exitQueue, getAttachedObject, getCreateTime, getId, getName, getPriority, getQueue, getQueuedState, getTimeEnteredQueue, getTimeExitedQueue, getTimeInQueue, getTimeStamp, getValueObject, initialize, isQueued, setAttachedObject, setName, setNulls, setPriority, setPriority_, setQueue, setTimeStamp, setValueObject, toString
-
-
-
-
Constructor Detail
-
Entity
protected Entity(EntityType entityType, java.lang.String name)
Creates an Entity with the given name and the creation time set to the current simulation time- Parameters:
entityType
-name
- The name of the entity
-
-
Method Detail
-
nullify
public void nullify()
Description copied from class:QObject
Causes all references to objects from this QObject to be set to null and all internal objects to be set to null including State informationMeant primarily to facilitate garbage collection. After this call, the object should not be used.
-
getTimeEnteredReceiver
public final double getTimeEnteredReceiver()
Returns the time that the entity was last received by a receiver. Useful in determining the total time an entity was at a receiver- Returns:
-
setTimeEnteredReceiver
protected final void setTimeEnteredReceiver(double time)
Used to set the time that the entity last entered a receiver- Parameters:
time
-
-
getType
public final EntityType getType()
- Returns:
- Returns the type.
-
getProcessExecutor
public final ProcessExecutor getProcessExecutor()
Gets a reference to the process executor that is currently executing with the entity.- Returns:
- A reference to the process executor.
-
setType
protected final void setType(EntityType entityType)
Sets the type of the entity. Side effects: 1. ALL previously supplied attributes will be cleared, even user defined attributes. The attributes of the entity will be assigned based on the newly supplied entity type.- Parameters:
entityType
- The type to set, must not be null
-
addAttribute
public final void addAttribute(java.lang.String attributeName, AttributeIfc attribute)
Adds the named attribute to the entity as a valid attribute Arguments must be non-null, or exceptions will be thrown. The named attribute must not already have been added to the entity or an exception will be thrown.- Parameters:
attributeName
-attribute
-
-
containsAttribute
public final boolean containsAttribute(java.lang.String attributeName)
Returns whether or not the attribute has been named for this entity- Parameters:
attributeName
-- Returns:
- true if already added, false otherwise
-
setAttributeValue
public final void setAttributeValue(java.lang.String attributeName, double value)
Allows the user to set the value of the named attribute to the given value- Parameters:
attributeName
- the attribute name must be present for the entity or an exception is thrownvalue
-
-
getAttributeValue
public final double getAttributeValue(java.lang.String attributeName)
Gets the value of the attribute using the GetValueIfc- Parameters:
attributeName
-- Returns:
-
setProcessExecutor
public final void setProcessExecutor(ProcessExecutor processExecutor)
This is used by the ProcessExecutor to tell the entity what process executor it is currently executing within.- Parameters:
processExecutor
- The ProcessExecutor
-
hasAllocations
public final boolean hasAllocations()
Checks if the entity has any allocations from resources- Returns:
-
containsAllocation
public final boolean containsAllocation(Allocation a)
Checks if the entity has the supplied allocation- Parameters:
a
-- Returns:
-
containsAllocation
public final boolean containsAllocation(Resource r)
Checks of the entity has an allocation for the supplied resource- Parameters:
r
-- Returns:
-
getAllocation
public final Allocation getAllocation(Resource r)
Gets the allocation for the supplied resource or null if no allocation exists- Parameters:
r
-- Returns:
-
setCurrentReceiver
protected void setCurrentReceiver(GetEntityReceiverIfc getter)
-
setCurrentReceiver
protected void setCurrentReceiver(EntityReceiverAbstract receiver)
Sets the current receiver- Parameters:
receiver
- must not be null
-
setPlannedReceiver
protected void setPlannedReceiver(GetEntityReceiverIfc getter)
-
setPlannedReceiver
protected void setPlannedReceiver(EntityReceiverAbstract receiver)
Sets the current receiver- Parameters:
receiver
- must not be null
-
release
public final void release(Resource resource)
A convenience method that allows an entity to release a resource that it has previously had allocated. Releases all units of the resource that were allocated. Throws an IllegalArgumentException if the supplied resource has not be allocated to the entity- Parameters:
resource
-
-
getMessage
public final java.lang.Object getMessage()
- Returns:
- Returns the Message.
-
setMessage
public final void setMessage(java.lang.Object message)
- Parameters:
message
- The Message to set.
-
getDurationTime
public final double getDurationTime()
Returns the duration time. This can be used by clients to set a duration time and be used within activities, processes, time events, etc.- Returns:
-
setDurationTime
public final void setDurationTime(double durationTime)
Sets the duration time. This can be used by clients to set a duration time and be used within activities, processes, time events, etc.- Parameters:
durationTime
-
-
getUseDurationFlag
public final boolean getUseDurationFlag()
This can be used by clients to indicate whether they should use getDurationTime(). By default it is false (do not use the duration time).- Returns:
-
setUseDurationFlag
public final void setUseDurationFlag(boolean flag)
This can be used by clients to indicate whether they should used getDurationTime(). By default it is false (do not use the duration time).- Parameters:
flag
-
-
getAmount
public final int getAmount()
This can be used by clients to set an amount, generally used when seizing resources.- Returns:
-
setAmount
public final void setAmount(int amount)
This can be used by clients to set an amount, generally used when seizing resources.- Parameters:
amount
- must be > 0
-
getUseAmountFlag
public final boolean getUseAmountFlag()
This can be used by clients to indicate whether they should used getAmount(). By default it is false (do not use the getAmount()).- Returns:
-
setUseAmountFlag
public final void setUseAmountFlag(boolean flag)
This can be used by clients to indicate whether they should used getAmount(). By default it is false (do not use the getAmount()).- Parameters:
flag
-
-
hasReceiverSequence
public final boolean hasReceiverSequence()
Returns true if the entity was supplied a receiver sequence from its entity type- Returns:
-
resetReceiverSequence
public final boolean resetReceiverSequence()
Resets the entity's receiver sequence to the beginning Returns true if a receiver sequence exists- Returns:
-
nextEntityReceiver
public final EntityReceiverAbstract nextEntityReceiver()
Gets the next receiver for this entity Returns null if no next receiver- Specified by:
nextEntityReceiver
in interfaceEntityReceiverIteratorIfc
- Returns:
- , the receiver or null if none
-
peekNextEntityReceiver
public final EntityReceiverAbstract peekNextEntityReceiver()
Peeks at the next receiver, without advancing to the next receiver Returns null if no receiver is next- Returns:
-
peekPreviousEntityReceiver
public final EntityReceiverAbstract peekPreviousEntityReceiver()
Peeks at the previous receiver, without moving to the previous Returns null if no previous receiver is available- Returns:
-
getEntityReceiverAt
public final EntityReceiverAbstract getEntityReceiverAt(int index)
Returns the EntityReceiver at the supplied index for the EntityType. Returns null if no sequence or the index is out of bounds for the sequence.- Parameters:
index
-- Returns:
-
previousEntityReceiver
public final EntityReceiverAbstract previousEntityReceiver()
Gets the previous receiver for this entity Returns null if no previous receiver- Specified by:
previousEntityReceiver
in interfaceEntityReceiverIteratorIfc
- Returns:
- the receiver or null if none
-
nextEntityReceiverIndex
public int nextEntityReceiverIndex()
Returns the index of the next entity receiver in the iterator sequence.- Specified by:
nextEntityReceiverIndex
in interfaceEntityReceiverIteratorIfc
- Returns:
- (-1 if no sequence iterator, size() if at end of list
-
previousEntityReceiverIndex
public int previousEntityReceiverIndex()
Returns the index of the next entity receiver in the iterator sequence.- Specified by:
previousEntityReceiverIndex
in interfaceEntityReceiverIteratorIfc
- Returns:
- (-1 if no sequence iterator or at the beginning of the list
-
hasNextEntityReceiver
public final boolean hasNextEntityReceiver()
Checks if there is a next entity receiver for this entity Returns false if no next receiver- Specified by:
hasNextEntityReceiver
in interfaceEntityReceiverIteratorIfc
- Returns:
- true if there is one, false otherwise
-
hasPreviousEntityReceiver
public final boolean hasPreviousEntityReceiver()
Checks if there is a previous entity receiver for this entity Returns false if no previous receiver- Specified by:
hasPreviousEntityReceiver
in interfaceEntityReceiverIteratorIfc
- Returns:
- true if there is one, false otherwise
-
getCurrentReceiver
public final EntityReceiverAbstract getCurrentReceiver()
Gets the receiver that most recently received the entity This may be null if the entity has never been received- Returns:
-
sendViaReceiver
public final void sendViaReceiver(EntityReceiverAbstract receiver)
Causes the entity to be sent to the receiver. It arrives instantaneously.- Parameters:
receiver
-
-
sendViaReceiver
public final void sendViaReceiver(EntityReceiverAbstract receiver, GetValueIfc time)
Causes the entity to be sent to the receiver. It arrives after the specified amount of time- Parameters:
receiver
-time
-
-
sendViaReceiver
public final void sendViaReceiver(EntityReceiverAbstract receiver, double time)
Causes the entity to be sent to the receiver. It arrives after the specified amount of time- Parameters:
receiver
-time
-
-
sendViaSequence
public final void sendViaSequence()
Causes the entity to be sent to the next receiver in its sequence (i.e. to nextEntityReceiver()). It arrives instantaneously.
-
sendViaSequence
public final void sendViaSequence(double time)
Causes the entity to be sent to the next receiver in its sequence (i.e. to nextEntityReceiver()). It arrives after the specified amount of time- Parameters:
time
-
-
sendViaEntityType
public final void sendViaEntityType()
Causes the entity to be sent to a destination (receiver) as specified by its EntityType based on its current location (receiver)
-
dispose
public final void dispose()
Causes the entity to be disposed. It can no longer be used. The entity must not have any outstanding requests. This can be checked by using hasAllocations(). If the entity is carrying any entities in its list, those entities will also be disposed
-
getSeizeRequirements
public java.util.List<SeizeRequirement> getSeizeRequirements()
-
getReleaseRequirements
public java.util.SortedSet<ReleaseRequirement> getReleaseRequirements()
-
requestFullyAllocated
protected void requestFullyAllocated(Request request)
This method can be overridden to react to the request receiving its full allocation of the desired resource- Parameters:
request
-
-
requestReleased
protected void requestReleased(Request request)
This method can be overridden to react to the request releasing its associated resource- Parameters:
request
-
-
toArray
public <T> T[] toArray(T[] ts)
-
toArray
public java.lang.Object[] toArray()
-
subList
public java.util.List<Entity> subList(int i, int i1)
- Specified by:
subList
in interfacejava.util.List<Entity>
-
size
public int size()
-
set
public Entity set(int i, Entity e)
Preconditions: e must not be null, and must not already be in the group- Specified by:
set
in interfacejava.util.List<Entity>
- Parameters:
i
-e
-- Returns:
-
retainAll
public boolean retainAll(java.util.Collection<?> clctn)
-
removeAll
public boolean removeAll(java.util.Collection<?> clctn)
-
remove
public boolean remove(java.lang.Object o)
-
listIterator
public java.util.ListIterator<Entity> listIterator(int i)
- Specified by:
listIterator
in interfacejava.util.List<Entity>
-
listIterator
public java.util.ListIterator<Entity> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<Entity>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<Entity>
-
iterator
public java.util.Iterator<Entity> iterator()
-
isEmpty
public boolean isEmpty()
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOf
in interfacejava.util.List<Entity>
-
containsAll
public boolean containsAll(java.util.Collection<?> clctn)
-
contains
public boolean contains(java.lang.Object o)
-
clear
public void clear()
-
addAll
public boolean addAll(int i, java.util.Collection<? extends Entity> clctn)
The collection must not have any null elements or any elements that are already part of the entity's group- Specified by:
addAll
in interfacejava.util.List<Entity>
- Parameters:
i
-clctn
-- Returns:
-
addAll
public boolean addAll(java.util.Collection<? extends Entity> clctn)
The collection must not have any null elements or any elements that are already part of the entity's group
-
add
public void add(int i, Entity e)
Adds an entity to the entity's group Preconditions: e must not be null, e must not already be in group- Specified by:
add
in interfacejava.util.List<Entity>
- Parameters:
i
-e
-
-
-