@@ -0,0 +1,2805 @@
+package games;%0A%0Aimport java.util.concurrent.Future;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport com.ibm.streamsx.topology.TStream;%0Aimport com.ibm.streamsx.topology.Topology;%0Aimport com.ibm.streamsx.topology.context.StreamsContextFactory;%0Aimport com.ibm.streamsx.topology.function7.Function;%0Aimport com.ibm.streamsx.topology.streams.BeaconStreams;%0A%0A/**%0A * Play%0A * %3Ca href=%22https://en.wikipedia.org/wiki/Fizz_buzz%22%3EFizz Buzz%3C/a%3E.%0A *%0A */%0Apublic class FizzBuzz %7B%0A%0A    /**%0A     * Entry point for a streaming Fizz Buzz!%0A     */%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        Topology topology = new Topology();%0A        %0A        // Declare an infinite stream of Long values%0A        TStream%3CLong%3E counting = BeaconStreams.longBeacon(topology);%0A        %0A        // Throttle the rate to allow the output to be seen easier%0A        counting = counting.throttle(100, TimeUnit.MILLISECONDS);%0A        %0A        // Print the tuples to standard output%0A        playFizzBuzz(counting).print();%0A        %0A        // At this point the streaming topology (streaming) is%0A        // declared, but no data is flowing. The topology%0A        // must be submitted to a StreamsContext to be executed.%0A%0A        // Since this is an streaming graph with an endless%0A        // data source it will run for ever%0A        Future%3C?%3E runningTopology = StreamsContextFactory.getEmbedded().submit(topology);%0A        %0A        // Run for one minute before canceling.%0A        Thread.sleep(TimeUnit.MINUTES.toMillis(1));%0A        %0A        runningTopology.cancel(true);       %0A    %7D%0A    %0A    /**%0A     * Return a stream that plays Fizz Buzz based%0A     * upon the values in the input stream.%0A     */%0A    public static TStream%3CString%3E playFizzBuzz(TStream%3CLong%3E counting) %7B%0A        %0A        /*%0A         * Transform an input stream of longs TStream%3CLong%3E to a%0A         * stream of strings TStream%3CString%3E that follow%0A         * the Fizz Buzz rules based upon each value in the%0A         * input stream.%0A         */%0A        TStream%3CString%3E shouts = counting.transform(new Function%3CLong,String%3E() %7B%0A            private static final long serialVersionUID = 1L;%0A%0A            @Override%0A            public String apply(Long v) %7B%0A                // Skip 0, humans count from 1!%0A                if (v == 0)%0A                    return null;%0A                %0A                StringBuilder sb = new StringBuilder();%0A                if (v %25 3 == 0)%0A                    sb.append(%22Fizz%22);%0A                if (v %25 5 == 0)%0A                    sb.append(%22Buzz%22);%0A                %0A                if (sb.length() == 0)%0A                    sb.append(Long.toString(v));%0A                else%0A                    sb.append(%22!%22);%0A                %0A                return sb.toString();%0A            %7D%7D, String.class);%0A        %0A        return shouts;%0A    %7D%0A%0A%7D%0A

Add FizzBuzz