# HG changeset patch # User Jaroslav Tulach # Date 1272803688 -7200 # Node ID 414d979b20b9d82516a33e66602dde430d3df465 # Parent 26f9a0ec4315bdc7603e562c2380766d24f6f4a5 Sample @StateChange annotation diff -r 26f9a0ec4315 -r 414d979b20b9 samples/stateful/src/org/apidesign/stateful/api/ProgressStateMachine.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/stateful/src/org/apidesign/stateful/api/ProgressStateMachine.java Sun May 02 14:34:48 2010 +0200 @@ -0,0 +1,47 @@ +package org.apidesign.stateful.api; + +import java.lang.annotation.Documented; + +/** + * + * @author Jaroslav Tulach + */ +// BEGIN: progress.annotations +public abstract class ProgressStateMachine { + /** Annotation that helps users and IDEs to understand what + * is the allowed order of method calls on instances of given class. + */ + @Documented + public @interface StateChange { + /** What is the required state of the object before given method + * is called. + * @return "*" means any state, otherwise specify the state's name + */ + String from() default "*"; + /** The state object enters after the method successfully returns. + * @return name of new state + */ + String to(); + } + + @StateChange(to="ready") + public static ProgressStateMachine create(String name) { + return createImpl(name); + } + + @StateChange(from="ready", to="started") + public abstract void start(int totalAmount); + + @StateChange(from="started", to="started") + public abstract void progress(int howMuch); + + @StateChange(to="finished") + public abstract void finish(); + // FINISH: progress.annotations + + + + private static ProgressStateMachine createImpl(String name) { + return null; // implementation left out, similar to Progress.java + } +}