001    // Copyright 2006 Waterken Inc. under the terms of the MIT X license
002    // found at http://www.opensource.org/licenses/mit-license.html
003    package org.waterken.bang;
004    
005    import static org.ref_send.promise.Eventual.ref;
006    
007    import java.io.Serializable;
008    
009    import org.ref_send.promise.Promise;
010    
011    /**
012     * A {@link Drum} maker.
013     */
014    public final class
015    Bang {
016        private Bang() { /* no instance interface */ }
017        
018        /**
019         * Constructs a {@link Drum}.
020         */
021        static public Drum
022        make() {
023            class DrumX implements Drum, Serializable {
024                static private final long serialVersionUID = 1L;
025                
026                private int hits = 0;
027    
028                public Promise<Integer>
029                getHits() { return ref(hits); }
030                
031                public Drum
032                bang(final int beats) {
033                    if (0 > beats) { throw new RuntimeException(); }
034                    hits += beats;
035                    return this;
036                }
037            }
038            return new DrumX();
039        }
040    }