// ** This class was generated with DemFGen (vers:09/27/2009) public class InlineParScale{ final int THRESHHOLD; final private Scale func; public InlineParScale(Scale f, int T){ func = f; THRESHHOLD = T; } public InlineParScale(Scale f){ this(f,10); } // New One... public Pict traverse(Pict _h){ //_ParTrav.count = 0; Pict ret = traversePict(_h, 0); //System.err.println("THREADS: "+_ParTrav.count); return ret; } public Square traverseSquare(final Square _h, final int weight){ int _size = func.combine(_h.size); return func.combine((Square)_h,(int)_size); } public Pict 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 Overlay traverseOverlay(final Overlay _h, final int weight){ _Result _top = (weight!=THRESHHOLD)? new _Trav(traversePict(_h.top,weight+1)): new _ParTrav(_h.top,this){ public Pict traverse(){ return trav.traversePict(tobj, weight+1); } }; _Result _bot = (weight!=THRESHHOLD)? new _Trav(traversePict(_h.bot,weight+1)): new _ParTrav(_h.bot,this){ public Pict traverse(){ return trav.traversePict(tobj, weight+1); } }; return func.combine((Overlay)_h,(Pict)(_top.result()), (Pict)(_bot.result())); } public Offset traverseOffset(final Offset _h, final int weight){ int _dx = func.combine(_h.dx); int _dy = func.combine(_h.dy); _Result _inner = (weight!=THRESHHOLD)? new _Trav(traversePict(_h.inner,weight+1)): new _ParTrav(_h.inner,this){ public Pict traverse(){ return trav.traversePict(tobj, weight+1); } }; return func.combine((Offset)_h,(int)_dx, (int)_dy, (Pict)(_inner.result())); } public Circle traverseCircle(final Circle _h, final int weight){ int _rad = func.combine(_h.rad); return func.combine((Circle)_h,(int)_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 InlineParScale trav; _R res = null; boolean done = false; _ParTrav(_T to, InlineParScale 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(); } }