Package modelarium.entities.agentsets
Class ReadOnlyAgentSet
java.lang.Object
modelarium.entities.agentsets.ReadOnlyAgentSet
- All Implemented Interfaces:
Iterable<ReadOnlyAgent>
Class for providing a read-only view of an
AgentSet.
This class wraps a mutable agent set so that its agents can be looked up, filtered and iterated over without
the underlying set being modifiable, with each retrieved agent wrapped as an ReadOnlyAgent.
-
Constructor Summary
ConstructorsConstructorDescriptionReadOnlyAgentSet(AgentSet mutableVersion) Constructs a new immutable agent set wrapping the specified mutable agent set. -
Method Summary
Modifier and TypeMethodDescriptionbooleandoesAgentExist(String agentName) Checks if an agent exists in the set by name.get(int index) Retrieves an agent by index.Retrieves an agent by name.Returns the agents in this set as a list of read-only views.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.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
-
ReadOnlyAgentSet
Constructs a new immutable agent set wrapping the specified mutable agent set.- Parameters:
mutableVersion- the mutable agent set to provide a read-only view of
-
-
Method Details
-
get
Retrieves an agent by name.- Parameters:
agentName- the agent's unique name- Returns:
- a read-only view of the agent with the specified name
-
get
Retrieves an agent by index.- Parameters:
index- the index of the agent- Returns:
- a read-only view of the agent at the given position
-
getAsList
Returns the agents in this set as a list of read-only views.- Returns:
- a list of
ReadOnlyAgentinstances
-
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
-
doesAgentExist
Checks if an agent exists in the set by name.- Parameters:
agentName- the name to check- Returns:
- true if the agent exists
-
getFilteredAgents
Returns a living-only filtered view of the agent set.- Parameters:
agentFilter- a predicate to apply to each agent- Returns:
- a new
ReadOnlyAgentSetcontaining only matching agents
-
getFilteredAgents
public ReadOnlyAgentSet getFilteredAgents(Predicate<ReadOnlyAgent> agentFilter, boolean includeDeadAgents) 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
ReadOnlyAgentSetcontaining 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 read-only views of the agents in random order
-
iterator
Standard iterator over the agents in the order they were added.- Specified by:
iteratorin interfaceIterable<ReadOnlyAgent>- Returns:
- an iterator over read-only views of the agents
-