Package modelarium.entities.agentsets
Class AgentSet
java.lang.Object
modelarium.entities.agentsets.AgentSet
A collection class for managing
Agent instances, with support for:
- Optional deep copying of agents on insertion
- Fast lookup by agent name
- Filtering, duplication, and setup routines
- Randomised iteration
This class is iterable and designed to support both sequential and parallel simulation use cases.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a list of agents to the set.voidAdds an agent to the set.voidAdds all agents from anotherAgentSet.voidaddDeepCopy(List<Agent> agents) Adds a deep copy of each agent in a list to the set.voidaddDeepCopy(Agent agent) Adds a deep copy of an agent to the set.voidaddDeepCopy(AgentSet agentSet) Adds a deep copy of each agent from anotherAgentSet.voidclear()Clears the agent set entirely.booleandoesAgentExist(String agentName) Checks if an agent exists in the set by name.Returns a duplicate of this agent set.get(int index) Retrieves an agent by index.Retrieves an agent by name.Returns a read-only view of this agent set.Returns the list of agents in this set.getFilteredAgents(Predicate<ReadOnlyAgent> agentFilter) Returns a living-only filtered view of the agent set.getFilteredAgents(Predicate<ReadOnlyAgent> agentFilter, boolean includeDeadAgents) Returns a filtered view of the agent set.getRandomIterator(RandomGenerator randomGenerator) Returns a randomised iterator over the agents in this set.booleanisEmpty()Returns whether the set contains no agents.iterator()Standard iterator over the agents in the order they were added.intsize()Returns the number of agents in the set.voidUpdates this set with all agents from another set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
AgentSet
Constructs a new agent set from a list of agents, without deep copying.- Parameters:
agentsList- list of agents to add
-
AgentSet
public AgentSet()Constructs an empty agent set without deep copying.
-
-
Method Details
-
add
Adds an agent to the set. If the agent already exists, it will be replaced.- Parameters:
agent- the agent to add
-
add
Adds a list of agents to the set.- Parameters:
agents- list of agents to add
-
add
Adds all agents from anotherAgentSet.- Parameters:
agentSet- the agent set to add from
-
addDeepCopy
Adds a deep copy of an agent to the set. If the agent already exists, it will be replaced.- Parameters:
agent- the agent to deep clone and add
-
addDeepCopy
Adds a deep copy of each agent in a list to the set.- Parameters:
agents- list of agents to deep clone and add
-
addDeepCopy
Adds a deep copy of each agent from anotherAgentSet.- Parameters:
agentSet- the agent set to deep clone and add from
-
get
Retrieves an agent by name.- Parameters:
agentName- the agent's unique name- Returns:
- the agent instance
-
get
Retrieves an agent by index.- Parameters:
index- the index of the agent- Returns:
- the agent at the given position
-
getAsList
Returns the list of agents in this set.- Returns:
- a list of agent instances
-
size
public int size()Returns the number of agents in the set.- Returns:
- the size of the agent set
-
isEmpty
public boolean isEmpty()Returns whether the set contains no agents.- Returns:
- true if the set is empty, false otherwise
-
clear
public void clear()Clears the agent set entirely. -
doesAgentExist
Checks if an agent exists in the set by name.- Parameters:
agentName- the name to check- Returns:
- true if the agent exists
-
update
Updates this set with all agents from another set. Existing agents are replaced if names match.- Parameters:
otherAgentSet- the other agent set to pull fromareDeepCopied- whether the agents should be deep cloned before being stored
-
getFilteredAgents
Returns a living-only filtered view of the agent set.- Parameters:
agentFilter- a predicate to apply to each agent- Returns:
- a new
AgentSetcontaining only matching agents
-
getFilteredAgents
Returns a filtered view of the agent set.- Parameters:
agentFilter- a predicate to apply to each agentincludeDeadAgents- a boolean which determines if dead agents are to be included in the output agent set or not- Returns:
- a new
AgentSetcontaining only matching agents
-
getRandomIterator
Returns a randomised iterator over the agents in this set.- Parameters:
randomGenerator- the random generator used to shuffle the agents- Returns:
- an iterator that yields agents in random order
-
getAsImmutable
Returns a read-only view of this agent set.- Returns:
- a new
ReadOnlyAgentSetinstance wrapping this set
-
duplicate
Returns a duplicate of this agent set. If deep copy is enabled, agents will be duplicated as well.- Returns:
- a new
AgentSetwith the same agents
-
iterator
Standard iterator over the agents in the order they were added.
-