Class ReadOnlyAgentSet

java.lang.Object
modelarium.entities.agentsets.ReadOnlyAgentSet
All Implemented Interfaces:
Iterable<ReadOnlyAgent>

public final class ReadOnlyAgentSet extends Object implements 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 Details

    • ReadOnlyAgentSet

      public ReadOnlyAgentSet(AgentSet mutableVersion)
      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

      public ReadOnlyAgent get(String agentName)
      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

      public ReadOnlyAgent get(int index)
      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

      public List<ReadOnlyAgent> getAsList()
      Returns the agents in this set as a list of read-only views.
      Returns:
      a list of ReadOnlyAgent 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
    • doesAgentExist

      public boolean doesAgentExist(String agentName)
      Checks if an agent exists in the set by name.
      Parameters:
      agentName - the name to check
      Returns:
      true if the agent exists
    • getFilteredAgents

      public ReadOnlyAgentSet getFilteredAgents(Predicate<ReadOnlyAgent> agentFilter)
      Returns a living-only filtered view of the agent set.
      Parameters:
      agentFilter - a predicate to apply to each agent
      Returns:
      a new ReadOnlyAgentSet containing 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 agent
      includeDeadAgents - a boolean which determines if dead agents are to be included in the output agent set or not
      Returns:
      a new ReadOnlyAgentSet containing only matching agents
    • getRandomIterator

      public Iterator<ReadOnlyAgent> getRandomIterator(RandomGenerator randomGenerator)
      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

      public Iterator<ReadOnlyAgent> iterator()
      Standard iterator over the agents in the order they were added.
      Specified by:
      iterator in interface Iterable<ReadOnlyAgent>
      Returns:
      an iterator over read-only views of the agents