diff -r 26f9a0ec4315 -r b8edf9de56c5 samples/stateful/src/org/apidesign/stateful/api/ProgressStateful.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/stateful/src/org/apidesign/stateful/api/ProgressStateful.java Sun May 02 14:35:48 2010 +0200 @@ -0,0 +1,53 @@ +package org.apidesign.stateful.api; + +/** API for notifying progress. + * + * @author Jaroslav Tulach + */ +// BEGIN: progress.api +public abstract class ProgressStateful { + public static ProgressStateful create(String name) { + return createImpl(name); + } + public abstract void start(int totalAmount); + public abstract void progress(int howMuch); + public abstract void finish(); + // FINISH: progress.api + + ProgressStateful() { + } + + private static ProgressStateful createImpl(String name) { + return new Impl(name); + } + + private static final class Impl extends ProgressStateful { + private final String name; + private int total = -1; + private int current; + + public Impl(String name) { + this.name = name; + } + + @Override + public void start(int totalAmount) { + total = totalAmount; + } + + @Override + public void progress(int howMuch) { + if (total == -1) { + throw new IllegalStateException("Call start first!"); + } + current = howMuch; + } + + @Override + public void finish() { + total = -1; + current = 0; + } + + } +}