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


public class InlineParToString{
   final int THRESHHOLD;
   final private ToString func;

   public InlineParToString(ToString f, int T){ func = f; THRESHHOLD = T; }
   public InlineParToString(ToString f){ this(f,10); }

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

   public String traverseSquare(Square _h, final int weight){
      String _size = func.combine(_h.size);
        return func.combine((Square)_h,(String)_size);
   }
   public String traversePict(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 String traverseOverlay(Overlay _h, final int weight){
      _Result<String> _top = (weight!=THRESHHOLD)? new _Trav<String>(traversePict(_h.top,weight+1)): new _ParTrav<Pict,String>(_h.top,this){
            public String traverse(){ return trav.traversePict(tobj, weight+1); }
        };
      _Result<String> _bot = (weight!=THRESHHOLD)? new _Trav<String>(traversePict(_h.bot,weight+1)): new _ParTrav<Pict,String>(_h.bot,this){
            public String traverse(){ return trav.traversePict(tobj, weight+1); }
        };
        return func.combine((Overlay)_h,(String)(_top.result()), (String)(_bot.result()));
   }
   public String traverseOffset(Offset _h, final int weight){
      String _dx = func.combine(_h.dx);
      String _dy = func.combine(_h.dy);
      _Result<String> _inner = (weight!=THRESHHOLD)? new _Trav<String>(traversePict(_h.inner,weight+1)): new _ParTrav<Pict,String>(_h.inner,this){
            public String traverse(){ return trav.traversePict(tobj, weight+1); }
        };
        return func.combine((Offset)_h,(String)_dx, (String)_dy, (String)(_inner.result()));
   }
   public String traverseCircle(Circle _h, final int weight){
      String _rad = func.combine(_h.rad);
        return func.combine((Circle)_h,(String)_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 InlineParToString trav;
       _R res = null;
       boolean done = false;
       _ParTrav(_T to, InlineParToString t){ tobj = to; trav = t;  this.start();
           //count++;
       }
       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();
   }
}