JTP API Documentation

jtp.disp
Class DispatcherUtils

java.lang.Object
  |
  +--jtp.disp.DispatcherUtils

public class DispatcherUtils
extends Object

A collection of static utility methods for Dispatchers.

See Also:
Dispatcher

Constructor Summary
DispatcherUtils()
           
 
Method Summary
static boolean addToDispatcher(Reasoner r, Dispatcher tgt)
          Adds Reasoner r to Dispatcher tgt or an appropriate child dispatcher of tgt.
protected static Collection collectReasoners(Dispatcher d, Dispatcher tgt, Collection out)
          From the children of a given dispatcher d, selects and adds to the provided collection out those reasoners that are acceptable for the target dispatcher tgt.
protected static List findChildDispatchers(Reasoner r0, Dispatcher tgt, List out)
          For a given dispatcher tgt, finds all children dispatchers that would accept reasoner r0.
static boolean moveChildren(Dispatcher src, Dispatcher tgt)
          Moves reasoners in src that are acceptable to tgt into tgt.
static boolean removeFromDispatcher(Reasoner r, Dispatcher tgt)
          Removes a reasoner from a dispatcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DispatcherUtils

public DispatcherUtils()
Method Detail

addToDispatcher

public static boolean addToDispatcher(Reasoner r,
                                      Dispatcher tgt)
Adds Reasoner r to Dispatcher tgt or an appropriate child dispatcher of tgt. In addition, if r is itself a Dispatcher, then all Reasoners currently in tgt that are acceptable for r (see Dispatcher.getReasonerClass()) are moved from tgt to r.

Returns:
true if r was successfully added to tgt; false otherwise

moveChildren

public static boolean moveChildren(Dispatcher src,
                                   Dispatcher tgt)
Moves reasoners in src that are acceptable to tgt into tgt.

Returns:
true if any reasoners were moved from src to tgt; false otherwise

removeFromDispatcher

public static boolean removeFromDispatcher(Reasoner r,
                                           Dispatcher tgt)
Removes a reasoner from a dispatcher. This is the preferred way to do this, since this function walks the dispatcher hierarchy looking for the target reasoner, in contrast with Dispatcher.removeReasoner(jtp.Reasoner) that only tries to remove reasoners directly attached to the given dispatcher. Only one occurence is removed.

Parameters:
r - the reasoner that we want to remove
tgt - the dispatcher that we want to remove it from
Returns:
true if the state of dispatcher has changed

findChildDispatchers

protected static List findChildDispatchers(Reasoner r0,
                                           Dispatcher tgt,
                                           List out)
For a given dispatcher tgt, finds all children dispatchers that would accept reasoner r0. Puts them into the list out, if provided. Otherwise, creates a new ArrayList. Dispatchers are arranged in the order of increasing generality, i.e. most specific first.

Returns:
a list of suitable dispatchers

collectReasoners

protected static Collection collectReasoners(Dispatcher d,
                                             Dispatcher tgt,
                                             Collection out)
From the children of a given dispatcher d, selects and adds to the provided collection out those reasoners that are acceptable for the target dispatcher tgt. The reasoners are not removed from their source, and they are not added to the target, they are just put into the collection. If out is null, a new ArrayList is created.

Returns:
a collections of reasoners that can be moved to the target dispatcher

JTP API Documentation