samples/stateful/src/org/apidesign/stateful/api/ProgressStateMachine.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
permissions -rw-r--r--
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
     1 package org.apidesign.stateful.api;
     2 
     3 import java.lang.annotation.Documented;
     4 
     5 /**
     6  *
     7  * @author Jaroslav Tulach <jtulach@netbeans.org>
     8  */
     9 // BEGIN: progress.annotations
    10 public abstract class ProgressStateMachine {
    11     /** Annotation that helps users and IDEs to understand what
    12      * is the allowed order of method calls on instances of given class.
    13      */
    14     @Documented
    15     public @interface StateChange {
    16         /** What is the required state of the object before given method
    17          * is called.
    18          * @return "*" means any state, otherwise specify the state's name
    19          */
    20         String from() default "*";
    21         /** The state object enters after the method successfully returns.
    22          * @return name of new state
    23          */
    24         String to();
    25     }
    26 
    27     @StateChange(to="ready")
    28     public static ProgressStateMachine create(String name) {
    29         return createImpl(name);
    30     }
    31 
    32     @StateChange(from="ready", to="started")
    33     public abstract void start(int totalAmount);
    34 
    35     @StateChange(from="started", to="started")
    36     public abstract void progress(int howMuch);
    37 
    38     @StateChange(to="finished")
    39     public abstract void finish();
    40     // FINISH: progress.annotations
    41 
    42 
    43 
    44     private static ProgressStateMachine createImpl(String name) {
    45         return null; // implementation left out, similar to Progress.java
    46     }
    47 }