jtulach@351: package org.apidesign.stateful.api; jtulach@351: jtulach@351: /** API for notifying progress that cannot call jtulach@351: * {@link #start(int)} and {@link InProgress#progress(int)} in wrong jtulach@351: * order. In contract to {@link ProgressStateful} class which allows that. jtulach@351: * jtulach@351: * @author Jaroslav Tulach jtulach@351: */ jtulach@351: public abstract class ProgressStateless { jtulach@351: // BEGIN: progress.phases jtulach@351: public static ProgressStateless create(String name) { jtulach@351: return createImpl(name); jtulach@351: } jtulach@351: public abstract InProgress start(int totalAmount); jtulach@351: jtulach@351: public abstract class InProgress { jtulach@351: public abstract void progress(int howMuch); jtulach@351: public abstract void finish(); jtulach@351: // FINISH: progress.phases jtulach@351: jtulach@351: InProgress() { jtulach@351: } jtulach@351: } jtulach@351: jtulach@351: jtulach@351: ProgressStateless() { jtulach@351: } jtulach@351: jtulach@351: private static ProgressStateless createImpl(String name) { jtulach@351: return new Impl(name); jtulach@351: } jtulach@351: jtulach@351: private static final class Impl extends ProgressStateless { jtulach@351: private final String name; jtulach@351: jtulach@351: public Impl(String name) { jtulach@351: this.name = name; jtulach@351: } jtulach@351: jtulach@351: @Override jtulach@351: public InProgress start(int totalAmount) { jtulach@351: return new InImpl(totalAmount); jtulach@351: } jtulach@351: jtulach@351: private class InImpl extends InProgress { jtulach@351: private final int total; jtulach@351: private int current; jtulach@351: jtulach@351: public InImpl(int total) { jtulach@351: this.total = total; jtulach@351: } jtulach@351: jtulach@351: @Override jtulach@351: public void progress(int howMuch) { jtulach@351: current = howMuch; jtulach@351: } jtulach@351: jtulach@351: @Override jtulach@351: public void finish() { jtulach@351: current = total; jtulach@351: } jtulach@351: } jtulach@351: } jtulach@351: }