# HG changeset patch # User Jaroslav Tulach # Date 1272803748 -7200 # Node ID b8edf9de56c5c10186577e769f1d168c04860fcd # Parent 414d979b20b9d82516a33e66602dde430d3df465 Renaming Progress to ProgressStateful diff -r 414d979b20b9 -r b8edf9de56c5 samples/stateful/src/org/apidesign/stateful/api/Progress.java --- a/samples/stateful/src/org/apidesign/stateful/api/Progress.java Sun May 02 14:34:48 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -package org.apidesign.stateful.api; - -/** API for notifying progress. - * - * @author Jaroslav Tulach - */ -// BEGIN: progress.api -public abstract class Progress { - public static Progress 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 - - Progress() { - } - - private static Progress createImpl(String name) { - return new Impl(name); - } - - private static final class Impl extends Progress { - 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; - } - - } -} diff -r 414d979b20b9 -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; + } + + } +} diff -r 414d979b20b9 -r b8edf9de56c5 samples/stateful/test/org/apidesign/stateful/api/ProgressStatefulTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/stateful/test/org/apidesign/stateful/api/ProgressStatefulTest.java Sun May 02 14:35:48 2010 +0200 @@ -0,0 +1,25 @@ +package org.apidesign.stateful.api; + +import junit.framework.TestCase; + +public class ProgressStatefulTest extends TestCase { + + public ProgressStatefulTest(String testName) { + super(testName); + } + + public void testProgressWithoutStart() { + try { + // BEGIN: progress.wrong.order + ProgressStateful p = ProgressStateful.create("WrongOrder"); + p.progress(10); + p.finish(); + // END: progress.wrong.order + + fail("Calling progress without start yields an exception!?"); + } catch (IllegalStateException ex) { + // OK + } + } + +} diff -r 414d979b20b9 -r b8edf9de56c5 samples/stateful/test/org/apidesign/stateful/api/ProgressTest.java --- a/samples/stateful/test/org/apidesign/stateful/api/ProgressTest.java Sun May 02 14:34:48 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package org.apidesign.stateful.api; - -import junit.framework.TestCase; - -public class ProgressTest extends TestCase { - - public ProgressTest(String testName) { - super(testName); - } - - public void testProgressWithoutStart() { - try { - // BEGIN: progress.wrong.order - Progress p = Progress.create("WrongOrder"); - p.progress(10); - p.finish(); - // END: progress.wrong.order - - fail("Calling progress without start yields an exception!?"); - } catch (IllegalStateException ex) { - // OK - } - } - -}