A
- the most common class type expected in this group (e.g.
AbstractAgent)T
- the type of the property, i.e. Integer (this works if the field is
an int, i.e. a primitive type)public class PropertyProbe<A extends AbstractAgent,T> extends Probe<A>
Constructor and Description |
---|
PropertyProbe(java.lang.String community,
java.lang.String group,
java.lang.String role,
java.lang.String fieldName)
Builds a new PropertyProbe considering a CGR location and the name of the class's field.
|
Modifier and Type | Method and Description |
---|---|
protected void |
adding(A agent)
This method is automatically called when an agent
joins the corresponding group and role.
|
protected void |
adding(java.util.List<A> agents)
Called when a list of agents joins the corresponding group and role.
|
void |
allAgentsLeaveRole()
Makes all the agents leave the corresponding role at once.
|
java.lang.String |
getCommunity()
Gets the community to which this activator/probe is binded to.
|
java.util.List<A> |
getCurrentAgentsList()
Returns a snapshot at moment t of the agents handling the group/role couple
|
java.lang.String |
getGroup()
Gets the group to which this activator/probe is binded to.
|
T |
getMaxValue()
Returns the maximum for the property over all the agents.
|
T |
getMinValue()
Returns the minimum for the property over all the agents.
|
T |
getPropertyValue(A agent)
Returns the current value of the agent's field
|
java.lang.String |
getRole()
Gets the role to which this activator/probe is binded to.
|
java.util.List<A> |
getShuffledList()
Returns a ListIterator over the agents which is shuffled
|
void |
initialize()
Called by the MaDKit kernel when the Activator or Probe is
first added.
|
void |
killAgents()
Kills all the agents which are monitored.
|
protected void |
removing(A agent)
This method is automatically called when an agent
leaves the corresponding group and role.
|
protected void |
removing(java.util.List<A> agents)
This method is automatically called when
a list of agents has leaved the corresponding group and role.
|
void |
setPropertyValue(A agent,
T value)
Should be used to work with primitive types or fields which are initially
null |
int |
size()
Returns the number of the agents handling the group/role couple
|
java.lang.String |
toString()
returns a string containing the CGR location and the number of monitored agents.
|
findFieldOn
public PropertyProbe(java.lang.String community, java.lang.String group, java.lang.String role, java.lang.String fieldName)
public T getPropertyValue(A agent)
agent
- the agent to probepublic void setPropertyValue(A agent, T value)
null
agent
- value
- public T getMaxValue()
Comparable
interface for this to work.public T getMinValue()
Comparable
interface for this to work.public java.lang.String getCommunity()
public java.lang.String getGroup()
public java.lang.String getRole()
public void initialize()
adding(getCurrentAgentsList());
protected void adding(java.util.List<A> agents)
AbstractAgent.launchAgentBucket(String, int, String...)
.
Override this method when you want
to do some initialization on the agents that enter the group/role.
Default implementation is:
protected void adding(final List<A> agents) { for (A agent : agents) { adding(agent); } }
agents
- the list of agents which have been added to this group/role at once.protected void adding(A agent)
agent
- which has been added to this group/roleprotected void removing(java.util.List<A> agents)
protected void removing(final List<A> agents) { for (A agent : agents) { removing(agent); } }
agents
- the list of agents which have been removed from this group/roleprotected void removing(A agent)
agent
- which has been removed from this group/rolepublic int size()
public java.util.List<A> getCurrentAgentsList()
public java.util.List<A> getShuffledList()
public java.lang.String toString()
toString
in class java.lang.Object
public void killAgents()
public void allAgentsLeaveRole()
Fabien Michel, Olivier Gutknecht, Jacques Ferber - November 18 2014