// ** This class was generated with DemFGen (vers:09/27/2009)


public class InlineParCircsTU{
   final int THRESHHOLD;
   final private CircsTU func;

   public InlineParCircsTU(CircsTU f, int T){ func = f; THRESHHOLD = T; }
   public InlineParCircsTU(CircsTU f){ this(f,10); }

   // New One...
   public Integer traverse(Pict _h){
       //_ParTrav.count = 0;
       Integer ret = traversePict(_h, 0);
       //System.err.println("THREADS: "+_ParTrav.count);
       return ret;
   }

   public Integer traverseSquare(final Square _h, final int weight){
      Integer _size = func.combine(_h.size);
        return func.combine((Square)_h,(Integer)_size);
   }
   public Integer traversePict(final Pict _h, final int weight){
      if(_h instanceof Overlay) return this.traverseOverlay((Overlay)_h,weight);
      if(_h instanceof Offset) return this.traverseOffset((Offset)_h,weight);
      if(_h instanceof Circle) return this.traverseCircle((Circle)_h,weight);
      if(_h instanceof Square) return this.traverseSquare((Square)_h,weight);
      else throw new RuntimeException("Unknown Pict Variant");
   }
   public Integer traverseOverlay(final Overlay _h, final int weight){
      _Result<Integer> _top = (weight!=THRESHHOLD)? new _Trav<Integer>(traversePict(_h.top,weight+1)): new _ParTrav<Pict,Integer>(_h.top,this){
            public Integer traverse(){ return trav.traversePict(tobj, weight+1); }
        };
      _Result<Integer> _bot = (weight!=THRESHHOLD)? new _Trav<Integer>(traversePict(_h.bot,weight+1)): new _ParTrav<Pict,Integer>(_h.bot,this){
            public Integer traverse(){ return trav.traversePict(tobj, weight+1); }
        };
        return func.combine((Overlay)_h,(Integer)(_top.result()), (Integer)(_bot.result()));
   }
   public Integer traverseOffset(final Offset _h, final int weight){
      Integer _dx = func.combine(_h.dx);
      Integer _dy = func.combine(_h.dy);
      _Result<Integer> _inner = (weight!=THRESHHOLD)? new _Trav<Integer>(traversePict(_h.inner,weight+1)): new _ParTrav<Pict,Integer>(_h.inner,this){
            public Integer traverse(){ return trav.traversePict(tobj, weight+1); }
        };
        return func.combine((Offset)_h,(Integer)_dx, (Integer)_dy, (Integer)(_inner.result()));
   }
   public Integer traverseCircle(final Circle _h, final int weight){
      Integer _rad = func.combine(_h.rad);
        return func.combine((Circle)_h,(Integer)_rad);
   }
   static interface _Result<_R>{ _R result(); }
   static class _Trav<_R> implements _Result<_R>{
       final _R res;
       _Trav(_R r){ res = r; }
       public _R result(){ return res; }
   }
   static abstract class _ParTrav<_T,_R> extends Thread implements _Result<_R>{
       static int count = 0;
       final _T tobj;
       final InlineParCircsTU trav;
       _R res = null;
       boolean done = false;
       _ParTrav(_T to, InlineParCircsTU t){ tobj = to; trav = t;  this.start();
           //count++;
           //System.err.println(" ----- "+count+" ----- "+tobj.getClass().getSimpleName());
       }
       public void run(){ setDone(traverse()); }
       synchronized void setDone(_R r){ res = r; done = true; this.notify(); }
       public synchronized _R result(){
           if(!done)
               try{ this.wait(); }catch(InterruptedException e){
                   System.err.println(" ** Error Waiting on Thread!!");
               }
           return res;
       }
       /** Do the Actual Traversal */
       public abstract _R traverse();
   }
}