AnyLogic
Expand
Font size
Type Parameters:
E - agent type
All Implemented Interfaces:
com.anylogic.engine.internal.Child, java.io.Serializable, java.lang.Iterable<E>

public class AgentArrayList<E extends Agent>
extends AgentList<E>
Agent population list based on array implementation
Supports fast element retrieval by its index (the get(int) operation runs in constant time).
The add operation runs in amortized constant time, that is, adding n elements requires O(n) time.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Constructor Summary

Constructors 
AgentArrayList​(Agent owner)
Constructs an empty list with an initial capacity of ten.
Constructor Description

Method Summary

All Methods Instance Methods Concrete Methods 
void _add​(E agent)
This method should not be called by user
Call add_EONAME() method of class containing embedded object with name EONAME or agent.goToPopulation( population )
boolean _remove​(Agent agent)
This method should not be called by user
Call remove_EONAME() method of class containing embedded object with name EONAME or agent.goToPopulation( null )
boolean contains​(java.lang.Object agent)
Returns true if this agent population contains the specified element.
E get​(int index)
Returns the agent element at the specified position in this agent population.
The position index is the number of list element in the insertion order (i.e.
boolean isEmpty()
Returns true if this agent population contains no elements.
java.util.Iterator<E> iterator()
Returns an iterator over the agent population.
This iterator guarantees the insertion order of elements (i.e.
E random​(java.util.Random r)
Randomly returns one agent from this population
(ses the specified random number generator to choose the element)
This method runs in linear time
This method returns null if the population is empty
int size()
Returns the number of elements in this agent population.
If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
java.util.stream.Stream<E> stream()
Returns a sequential Stream with this agent population as its source.
java.lang.String toString()  
Modifier and Type Method Description

Methods inherited from class com.anylogic.engine.AgentList

average, average, callCreate, callCreate, callSetupParameters, callSetupParameters, count, fillFromTable, fillFromTable, fillFromTable, findAll, findFirst, getEnvironment, getOwner, getPresentationScaleOnOwnerSpace, getValueFromTable, instantiateAgent, isPresentationEnabled, max, max, min, min, min, onChange, random, randomExcept, randomExcept, restoreOwner, setEnvironment, sum, sum

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Methods inherited from interface java.lang.Iterable

forEach, spliterator

Constructor Detail

AgentArrayList

public AgentArrayList​(Agent owner)
Constructs an empty list with an initial capacity of ten.

Method Detail

_add

@AnyLogicInternalCodegenAPI
public void _add​(E agent)
Description copied from class: AgentList
This method should not be called by user
Call add_EONAME() method of class containing embedded object with name EONAME or agent.goToPopulation( population )
Specified by:
_add in class AgentList<E extends Agent>

_remove

@AnyLogicInternalCodegenAPI
public boolean _remove​(Agent agent)
Description copied from class: AgentList
This method should not be called by user
Call remove_EONAME() method of class containing embedded object with name EONAME or agent.goToPopulation( null )
Specified by:
_remove in class AgentList<E extends Agent>

get

public E get​(int index)
Description copied from class: AgentList
Returns the agent element at the specified position in this agent population.
The position index is the number of list element in the insertion order (i.e. the order in which agent were added to this replicated agent list). Thus, index of an element decreases when preceding elements are removed.
Specified by:
get in class AgentList<E extends Agent>
Parameters:
index - index of the element to return
Returns:
the element at the specified position in this list

contains

public boolean contains​(java.lang.Object agent)
Description copied from class: AgentList
Returns true if this agent population contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)).
Specified by:
contains in class AgentList<E extends Agent>
Parameters:
agent - element whose presence in this agent population is to be tested
Returns:
true if this agent population contains the specified element

isEmpty

public boolean isEmpty()
Description copied from class: AgentList
Returns true if this agent population contains no elements.
Specified by:
isEmpty in class AgentList<E extends Agent>
Returns:
true if this agent population contains no elements

iterator

public java.util.Iterator<E> iterator()
Description copied from class: AgentList
Returns an iterator over the agent population.
This iterator guarantees the insertion order of elements (i.e. the order in which agent were added to this agent population list).
Note, that returned iterator doesn't support remove operation
Specified by:
iterator in interface java.lang.Iterable<E extends Agent>
Specified by:
iterator in class AgentList<E extends Agent>
Returns:
an Iterator over the elements in this replicated agent

stream

public java.util.stream.Stream<E> stream()
Description copied from class: AgentList
Returns a sequential Stream with this agent population as its source.
Overrides:
stream in class AgentList<E extends Agent>

size

public int size()
Description copied from class: AgentList
Returns the number of elements in this agent population.
If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
Specified by:
size in class AgentList<E extends Agent>
Returns:
the number of elements in this agent population

random

public E random​(java.util.Random r)
Description copied from class: AgentList
Randomly returns one agent from this population
(ses the specified random number generator to choose the element)
This method runs in linear time
This method returns null if the population is empty
Overrides:
random in class AgentList<E extends Agent>
Parameters:
r - the random number generator.
Returns:
the agent randomly chosen from this population
(uses uniform distribution from the Engine)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
How can we improve this article?