package stepwise; public abstract class Merge extends CoroutineBase implements Stepwise { public Merge() { super(false); } @Override public X lazyEval() { while (true) { Report rep = nextStep(); if (rep instanceof ReportReplace) { ReportReplace repl = (ReportReplace) rep; @SuppressWarnings("unchecked") Stepwise comp = (Stepwise) repl.get(); return comp.lazyEval(); } else if (rep instanceof ReportFail) { throw new RuntimeException( "Merge.lazyEval(): all alternatives fail."); } else if (rep instanceof ReportChild) { throw new RuntimeException( "Merge.lazyEval(): unexpected ReportChild."); } else if (rep instanceof ReportDone) { throw new RuntimeException( "Merge.lazyEval(): unexpected ReportDone."); } // else: skip } } }