Package modelarium.entities.contexts
Class EnvironmentSimulationContext
java.lang.Object
modelarium.entities.contexts.SimulationContext
modelarium.entities.contexts.EnvironmentSimulationContext
- All Implemented Interfaces:
Context,EntityContext,EnvironmentContext
public final class EnvironmentSimulationContext
extends SimulationContext
implements EnvironmentContext
Class for providing the environment and its attributes with access to relevant simulation resources.
This class is the concrete EnvironmentContext implementation the model creates for the environment,
combining the shared behaviour of SimulationContext with environment-specific entity access.
-
Method Summary
Modifier and TypeMethodDescriptionRetrieves an agent by name.intReturns the model's current population size.Unsupported for the environment's own context.getFilteredAgents(Predicate<ReadOnlyAgent> filter) Retrieves the living-only agents matching a filter.getFilteredAgents(Predicate<ReadOnlyAgent> agentFilter, boolean includeDeadAgents) Returns an agents matching a filterReturns the attribute currently being run on the owning environment.Returns the attribute set currently being run on the owning environment.Returns the environment this context belongs to.voidKills the agent with the given name.voidkillAgent(ReadOnlyAgent agent) Kills the agent of the givenReadOnlyAgentinstance.voidkillAgents(List<String> agentNames) voidkillAgents(ReadOnlyAgentSet agentSet) Kills all the agents in a givenReadOnlyAgentSetinstance.Methods inherited from class modelarium.entities.contexts.SimulationContext
addAgent, addAgents, addAgents, attribute, attributeSet, config, doesAgentExistInThisCore, entity, getClock, getRandom, localAgentSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface modelarium.entities.contexts.Context
doesAgentExistInThisCore, getClock, getRandomMethods inherited from interface modelarium.entities.contexts.EntityContext
addAgent, addAgents, addAgents
-
Method Details
-
getThisEntity
Returns the environment this context belongs to.- Specified by:
getThisEntityin interfaceEnvironmentContext- Specified by:
getThisEntityin classSimulationContext- Returns:
- the owning
Environmentinstance
-
getThisAttributeSet
Returns the attribute set currently being run on the owning environment.- Specified by:
getThisAttributeSetin interfaceEnvironmentContext- Specified by:
getThisAttributeSetin classSimulationContext- Returns:
- the current
EnvironmentAttributeSetinstance
-
getThisAttribute
Returns the attribute currently being run on the owning environment.- Specified by:
getThisAttributein interfaceEnvironmentContext- Specified by:
getThisAttributein classSimulationContext- Returns:
- the current attribute instance
-
getEnvironment
Unsupported for the environment's own context.The context requester is already the environment, so
getThisEntity()should be used instead.- Overrides:
getEnvironmentin classSimulationContext- Returns:
- this method never returns normally
-
getCurrentPopulationSize
public int getCurrentPopulationSize()Returns the model's current population size.- Specified by:
getCurrentPopulationSizein interfaceContext- Overrides:
getCurrentPopulationSizein classSimulationContext- Returns:
- the current population size as an int
-
getAgent
Retrieves an agent by name.- Specified by:
getAgentin interfaceContext- Overrides:
getAgentin classSimulationContext- Parameters:
targetAgentName- the name of the agent to retrieve- Returns:
- a read-only view of the requested agent
-
getFilteredAgents
Retrieves the living-only agents matching a filter.- Specified by:
getFilteredAgentsin interfaceContext- Overrides:
getFilteredAgentsin classSimulationContext- Parameters:
filter- a predicate to apply to each agent- Returns:
- a new
ReadOnlyAgentSetcontaining the matching agents
-
getFilteredAgents
public ReadOnlyAgentSet getFilteredAgents(Predicate<ReadOnlyAgent> agentFilter, boolean includeDeadAgents) Returns an agents matching a filter- Specified by:
getFilteredAgentsin interfaceContext- Overrides:
getFilteredAgentsin classSimulationContext- 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
-
killAgent
Kills the agent with the given name.- Specified by:
killAgentin interfaceContext- Overrides:
killAgentin classSimulationContext- Parameters:
agentName- the agent's name as a string
-
killAgent
Kills the agent of the givenReadOnlyAgentinstance.- Specified by:
killAgentin interfaceContext- Overrides:
killAgentin classSimulationContext- Parameters:
agent- the immutable agent to kill
-
killAgents
- Specified by:
killAgentsin interfaceContext- Overrides:
killAgentsin classSimulationContext- Parameters:
agentNames- the list of names of agents to kill
-
killAgents
Kills all the agents in a givenReadOnlyAgentSetinstance.- Specified by:
killAgentsin interfaceContext- Overrides:
killAgentsin classSimulationContext- Parameters:
agentSet- the immutable agent set of agents to kill
-