samples/stateful/src/org/apidesign/stateful/api/ProgressStateful.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
parent 348 26f9a0ec4315
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 /** API for notifying progress.
     4  *
     5  * @author Jaroslav Tulach <jtulach@netbeans.org>
     6  */
     7 // BEGIN: progress.api
     8 public abstract class ProgressStateful {
     9     public static ProgressStateful create(String name) {
    10         return createImpl(name);
    11     }
    12     public abstract void start(int totalAmount);
    13     public abstract void progress(int howMuch);
    14     public abstract void finish();
    15     // FINISH: progress.api
    16 
    17     ProgressStateful() {
    18     }
    19     
    20     private static ProgressStateful createImpl(String name) {
    21         return new Impl(name);
    22     }
    23 
    24     private static final class Impl extends ProgressStateful {
    25         private final String name;
    26         private int total = -1;
    27         private int current;
    28 
    29         public Impl(String name) {
    30             this.name = name;
    31         }
    32 
    33         @Override
    34         public void start(int totalAmount) {
    35             total = totalAmount;
    36         }
    37 
    38         @Override
    39         public void progress(int howMuch) {
    40             if (total == -1) {
    41                 throw new IllegalStateException("Call start first!");
    42             }
    43             current = howMuch;
    44         }
    45 
    46         @Override
    47         public void finish() {
    48             total = -1;
    49             current = 0;
    50         }
    51 
    52     }
    53 }