Class AgentMsgHelpers

java.lang.Object
  extended by AgentMsgHelpers

public class AgentMsgHelpers
extends java.lang.Object

Set of (static) helper routines to make writing agents easier.

Since:
1.1

Nested Class Summary
static class AgentMsgHelpers.appendIter<T>
           
static class AgentMsgHelpers.consIter<T>
           
 class AgentMsgHelpers.FindMatching
          Exists solely for testing purposes
static class AgentMsgHelpers.MsgFilter<T extends IMsg>
           
 class AgentMsgHelpers.MsgIntWrapper
          Exists solely for testing purposes
static class AgentMsgHelpers.MsgPair<T1 extends IMsg,T2 extends IMsg>
           
static class AgentMsgHelpers.NullMsg
          Empty message class.
static class AgentMsgHelpers.PosMsg
          Message class to hold a position in n dimensions
 
Constructor Summary
AgentMsgHelpers()
           
 
Method Summary
static
<T extends IMsg>
java.util.Collection<T>
accumMsgs(java.util.Iterator<CommLink> iterChannels, java.util.Collection<T> msgBag)
          Accumulates all the readable messages from a list of channels.
static
<T extends IMsg>
void
applyFunc(IFuncObj<T,java.lang.Boolean> func, java.util.Iterator<T> iter)
           
static java.util.Vector<java.util.Iterator<CommLink>> duplicateLinks(java.util.Iterator<CommLink> toDup)
           
 int getCountMsg(IFuncObj<IMsg,java.lang.Boolean> filter, java.util.Collection<IMsg> msgBag)
           
static
<T extends IMsg>
java.util.Iterator<T>
getFilteredMsgs(IFuncObj<T,java.lang.Boolean> filter, java.util.Collection<T> msgBag)
           
static
<T> java.util.Vector<java.util.Iterator<T>>
nDuplicateLinks(java.util.Iterator<T> toDup, int nCopies)
           
 boolean testFilters()
          Exists solely for testing purposes
static
<T1 extends IMsg,T2 extends IMsg>
java.util.Collection<AgentMsgHelpers.MsgPair<T1,T2>>
zipMsgs(java.util.Iterator<T1> l1, java.util.Iterator<T2> l2, java.util.Collection<AgentMsgHelpers.MsgPair<T1,T2>> bag)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgentMsgHelpers

public AgentMsgHelpers()
Method Detail

duplicateLinks

public static java.util.Vector<java.util.Iterator<CommLink>> duplicateLinks(java.util.Iterator<CommLink> toDup)
Parameters:
toDup - iterator of communication links to duplicate
Returns:
vector containing two copies of the iterator to communication links.

nDuplicateLinks

public static <T> java.util.Vector<java.util.Iterator<T>> nDuplicateLinks(java.util.Iterator<T> toDup,
                                                                          int nCopies)
Parameters:
toDup - iterator of communication links to duplicate
nCopies - number of copies to make
Returns:
vector containing two copies of the iterator to communication links.

accumMsgs

public static <T extends IMsg> java.util.Collection<T> accumMsgs(java.util.Iterator<CommLink> iterChannels,
                                                                 java.util.Collection<T> msgBag)
Accumulates all the readable messages from a list of channels.

Parameters:
iterChannels - iterator for channels to read from
msgBag - initially empty bag to put messages into

zipMsgs

public static <T1 extends IMsg,T2 extends IMsg> java.util.Collection<AgentMsgHelpers.MsgPair<T1,T2>> zipMsgs(java.util.Iterator<T1> l1,
                                                                                                             java.util.Iterator<T2> l2,
                                                                                                             java.util.Collection<AgentMsgHelpers.MsgPair<T1,T2>> bag)

getFilteredMsgs

public static <T extends IMsg> java.util.Iterator<T> getFilteredMsgs(IFuncObj<T,java.lang.Boolean> filter,
                                                                     java.util.Collection<T> msgBag)

applyFunc

public static <T extends IMsg> void applyFunc(IFuncObj<T,java.lang.Boolean> func,
                                              java.util.Iterator<T> iter)

getCountMsg

public int getCountMsg(IFuncObj<IMsg,java.lang.Boolean> filter,
                       java.util.Collection<IMsg> msgBag)

testFilters

public boolean testFilters()
Exists solely for testing purposes