fipaos.agent
Class AgentList


public class AgentList

This class implements a specific list type data structure to store lists of agents of specific types. The idea is that this list structure provides a convenient way of storing lists of agents that we are registered with, or a list of agents that we are waiting on etc. The data structure lets you store an agent name or AgentGUID object with an associated type/id/string. You can then search the structure for the name or identifier and receive specific objects or lists of objects back.


Constructor Summary
AgentList()
          Constructs an empty agent list.

Method Summary
 booleanadd(Object name, String type)
          Adds a new agent to the list.
 voidclear()
          Removes every element in the list.
 booleancontains(Object name)
          Indicates whether this list contains the agent name specified.
 booleancontainsType(String type)
          Indicates whether this list contains any elements added with an associated string that matches the type parameter.
 AgentID[]getAIDs(String type)
          Returns every agent name with the associated type specified by the type parameter in an array of AgentGUIDs.
 String[]getNames(String type)
          Returns every agent name with the associated type specified by the type parameter in an array of Strings.
 StringgetType(Object name)
          Returns the type/id/string of the specified agent name.
 voidremove(Object name)
          Removes an agent from the list.
 voidremoveAll(String type)
          Removes all agents with the given type/id parameter.
 voidremoveAll()
          Removes every element in the list.
 StringtoString()
          Returns a string representation of the contents of the agent list.

Constructor Detail

AgentList

public AgentList()
Constructs an empty agent list. Use the add, get and remove methods to access, set and retrieve data in the list.
Method Detail

add

public boolean add(Object name, String type)
Adds a new agent to the list. The name parameter is the agent name. This can be of type String or AgentID. If an object of a different type is passed into this method then it will return false.
Parameters:
name - A String or AgentGUID representing the agent to be stored in the list
type - A String that can hold whatever data you like. For example, it could be the type of an agent (df, ams, oa, arb etc) or it could be some other data.
Returns: True if the name parameter is of the correct type, false otherwise

clear

public void clear()
Removes every element in the list.

contains

public boolean contains(Object name)
Indicates whether this list contains the agent name specified.
Parameters:
name - The agent name to look for in the list (as a String or AgentID)
Returns: True if the name is in the list, false otherwise

containsType

public boolean containsType(String type)
Indicates whether this list contains any elements added with an associated string that matches the type parameter.
Parameters:
type - The type/id/string to look for in the list
Returns: True if the type/id/string is in the list, false otherwise

getAIDs

public AgentID[] getAIDs(String type)
Returns every agent name with the associated type specified by the type parameter in an array of AgentGUIDs. The names are returned in the order in which they were added to the list.
Parameters:
type - The type/id/string associated with the names that you wish to extract
Returns: An array of agent names as AgentGUID objects

getNames

public String[] getNames(String type)
Returns every agent name with the associated type specified by the type parameter in an array of Strings.
Parameters:
type - The type/id/string associated with the names that you wish to extract
Returns: An array of agent id's as String objects

getType

public String getType(Object name)
Returns the type/id/string of the specified agent name. The name parameter can have type AgentGUID or String. If the name cannot be found in the list then null is returned.
Parameters:
name - The String or AgentGUID of the agent of whose type you wish to find
Returns: The type/id/string associated with the specified agent name, or null if the name could not be found

remove

public void remove(Object name)
Removes an agent from the list. As with add the name parameter can be of type String or AgentGUID.
Parameters:
name - The String or AgentGUID object to remove.

removeAll

public void removeAll(String type)
Removes all agents with the given type/id parameter. Any agents that have been stored with their 'type' set to the given parameter will be removed from the list.
Parameters:
type - The type/id/string of the agent names to remove

removeAll

public void removeAll()
Removes every element in the list.

toString

public String toString()
Returns a string representation of the contents of the agent list.
The output is in the form:

[ {agent-name, type/id/string}, ... ]

e.g.
[ {agent@iiop://45.45.45.45:9000/acc, df}, {agent2@iiop://67.45.34.564:90/Agency/FIPA_Agent_97, ams} ]

Returns: The string representation of this list

Association Links

to Class java.util.TreeMap