// ** This class was generated with DemFGen (vers:09/27/2009) public class InlineParFlip{ final int THRESHHOLD; final private Flip func; public InlineParFlip(Flip f, int T){ func = f; THRESHHOLD = T; } public InlineParFlip(Flip 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<Pict> _top = (weight!=THRESHHOLD)? new _Trav<Pict>(traversePict(_h.top,weight+1)): new _ParTrav<Pict,Pict>(_h.top,this){ public Pict traverse(){ return trav.traversePict(tobj, weight+1); } }; _Result<Pict> _bot = (weight!=THRESHHOLD)? new _Trav<Pict>(traversePict(_h.bot,weight+1)): new _ParTrav<Pict,Pict>(_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<Pict> _inner = (weight!=THRESHHOLD)? new _Trav<Pict>(traversePict(_h.inner,weight+1)): new _ParTrav<Pict,Pict>(_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 InlineParFlip trav; _R res = null; boolean done = false; _ParTrav(_T to, InlineParFlip 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(); } }