edu.neu.ccs.demeterf
Class TU<T>

java.lang.Object
  extended by edu.neu.ccs.demeterf.FC
      extended by edu.neu.ccs.demeterf.TU<T>

public abstract class TU<T>
extends FC

A Helper Class to implement something like SYB queries. To use this class, you must implement at least three methods:

The easiest way to use TUCombiner is to subclass, and create a wrapper method:
    // Example Binary Tree Representation...
    abstract class BTree{}
    class Leaf extends BTree{
       int data;
       Leaf(int i){ data = i; }
    }
    class Node extends BTree{
       BTree left, right;
       Node(BTree l, BTree r){ left = l; right = r; }
    }

    // Concrete TUCombiner Class
    //    Counts the number of Leafs in a BTree instance
    class CountLeafs extends TUCombiner<Integer>{
       public Integer combine(){ return 0; }
       public Integer fold(Integer i, Integer j){ return i+j; }
       int combine(Leaf l){ return 1; }
   
       static int leafs(BTree t){
          return TUCombiner.traverse(t, new CountLeafs());
       }
    } 
    

TUCombiner will make sure that the Leaf class becomes an actual leaf of the traversal, because the combine method only takes one parameter. If there are other cases that we care about we can add more combine methods, one for each to be considered a value producing leaf with a return type T.

For non-leaf classes of interest, you can write a normal combine methods (more than one parameter) for special cases, but the recursive results of fields will always be of type T unless you handle the or to use non-type-unifying traversal for a portion of the data structure.


Field Summary
 
Fields inherited from class edu.neu.ccs.demeterf.FC
augMethodName, buildMethodName
 
Constructor Summary
TU()
           
 
Method Summary
abstract  T combine()
          Default combine (must be implemented for safety)
 T combine(java.lang.Object o1)
           
 T combine(java.lang.Object o1, T o2)
          A Bunch of simple Object* methods to catch all the rest
 T combine(java.lang.Object o1, T o2, T o3)
           
 T combine(java.lang.Object o1, T o2, T o3, T o4)
           
 T combine(java.lang.Object o1, T o2, T o3, T o4, T o5)
           
 T combine(java.lang.Object o1, T o2, T o3, T o4, T o5, T o6)
           
 T combine(java.lang.Object o1, T o2, T o3, T o4, T o5, T o6, T o7)
           
 T combine(java.lang.Object o1, T o2, T o3, T o4, T o5, T o6, T o7, T o8)
           
 T combine(java.lang.Object o1, T o2, T o3, T o4, T o5, T o6, T o7, T o8, T o9)
           
 T combine(java.lang.Object o1, T o2, T o3, T o4, T o5, T o6, T o7, T o8, T o9, T o10)
           
abstract  T fold(T accum, T one)
          Perform one step of the combination
 T traverse(java.lang.Object o)
          Use this to do a TU Traversal of an Object.
 T traverse(java.lang.Object o, MutableControl c)
          Use this to do a TU Traversal of an Object with a given Control for optimization purposes.
 T traverseHeap(java.lang.Object o)
          TU Traversal On the Heap instead of the stack
 T traverseHeap(java.lang.Object o, MutableControl c)
          TU Traversal On the Heap instead of the stack, with the given control
static
<R> R
traversePar(java.lang.Object o, TU<R> tuc)
          Uses ParTraversal to do combines in parallel
static
<R> R
traversePar(java.lang.Object o, TU<R> tuc, MutableControl c)
          Uses ParTraversal to do combines in parallel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TU

public TU()
Method Detail

combine

public T combine(java.lang.Object o1)

combine

public T combine(java.lang.Object o1,
                 T o2)
A Bunch of simple Object* methods to catch all the rest


combine

public T combine(java.lang.Object o1,
                 T o2,
                 T o3)

combine

public T combine(java.lang.Object o1,
                 T o2,
                 T o3,
                 T o4)

combine

public T combine(java.lang.Object o1,
                 T o2,
                 T o3,
                 T o4,
                 T o5)

combine

public T combine(java.lang.Object o1,
                 T o2,
                 T o3,
                 T o4,
                 T o5,
                 T o6)

combine

public T combine(java.lang.Object o1,
                 T o2,
                 T o3,
                 T o4,
                 T o5,
                 T o6,
                 T o7)

combine

public T combine(java.lang.Object o1,
                 T o2,
                 T o3,
                 T o4,
                 T o5,
                 T o6,
                 T o7,
                 T o8)

combine

public T combine(java.lang.Object o1,
                 T o2,
                 T o3,
                 T o4,
                 T o5,
                 T o6,
                 T o7,
                 T o8,
                 T o9)

combine

public T combine(java.lang.Object o1,
                 T o2,
                 T o3,
                 T o4,
                 T o5,
                 T o6,
                 T o7,
                 T o8,
                 T o9,
                 T o10)

fold

public abstract T fold(T accum,
                       T one)
Perform one step of the combination


combine

public abstract T combine()
Default combine (must be implemented for safety)


traverse

public T traverse(java.lang.Object o)
Use this to do a TU Traversal of an Object. It reflects on the given TUCombiner, and sees what you're interested in (single argument combine methods), making those classes BuiltIns


traverse

public T traverse(java.lang.Object o,
                  MutableControl c)
Use this to do a TU Traversal of an Object with a given Control for optimization purposes. Note: The function object is not run on bypassed edges, so your methods *must* handle these edges correctly.


traverseHeap

public T traverseHeap(java.lang.Object o)
TU Traversal On the Heap instead of the stack


traverseHeap

public T traverseHeap(java.lang.Object o,
                      MutableControl c)
TU Traversal On the Heap instead of the stack, with the given control


traversePar

public static <R> R traversePar(java.lang.Object o,
                                TU<R> tuc)
Uses ParTraversal to do combines in parallel


traversePar

public static <R> R traversePar(java.lang.Object o,
                                TU<R> tuc,
                                MutableControl c)
Uses ParTraversal to do combines in parallel