Reputation: 1
As i am using getConnections() that will Returns a collection of agents(i.e,list not single agent) connected to any agent. I want to connect the agents (those which are present in the collection returned by getConnections()) to another agent. Problem is connectTo() function is only used for connecting to particuar agent, not list of agent.
Instead of connectTo(), which function can be used or any other way?
Upvotes: 0
Views: 641
Reputation: 12793
You need to loop across all agents retrieved from getConnections()
. A simple solution assuming you want to connect myInitialAgent
to all agents currently connected to myOtherAgent
:
for (Agent currentAgent : myOtherAgent.getConnections()) {
myInitialAgent.connectTo(currentAgent);
}
You could also do it using Lambda expressions but I prefer readability ;-)
Upvotes: 1