/**
 * 
 */
package com.github.phantomthief.stats;

import static java.util.function.Function.identity;

import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.UnaryOperator;

/**
 * @author w.vela
 */
public class SingleStatsHelper<C> {

    private static final String DEFAULT_KEY = "s";
    private final StatsHelper<String, C> stats;

    /**
     * @param stats
     */
    private SingleStatsHelper(StatsHelper<String, C> stats) {
        this.stats = stats;
    }

    public void stats(Consumer<C> counterFunction) {
        stats.stats(DEFAULT_KEY, counterFunction);
    }

    public Map<Long, C> getStats() {
        return stats.getStats().get(DEFAULT_KEY);
    }

    public <V> Map<String, V> getFriendlyStats(Function<C, V> counterFormatter) {
        return stats.getFriendlyStats(identity(), counterFormatter).get(DEFAULT_KEY);
    }

    public <D, V> Map<D, V> getFriendlyStats( //
            Function<Long, D> durationFormatter, //
            Function<C, V> counterFormatter) {
        return stats.getFriendlyStats(identity(), durationFormatter, counterFormatter)
                .get(DEFAULT_KEY);
    }

    public static final class Builder<C> {

        private final com.github.phantomthief.stats.StatsHelper.Builder<C> builder = StatsHelper
                .newBuilder();

        public com.github.phantomthief.stats.StatsHelper.Builder<C> addDuration(long duration,
                TimeUnit timeUnit) {
            return builder.addDuration(duration, timeUnit);
        }

        public com.github.phantomthief.stats.StatsHelper.Builder<C>
                setCounterReset(UnaryOperator<C> resetter) {
            return builder.setCounterReset(resetter);
        }

        public com.github.phantomthief.stats.StatsHelper.Builder<C>
                setScheduledExecutorService(ScheduledExecutorService scheduledExecutorService) {
            return builder.setScheduledExecutorService(scheduledExecutorService);
        }

        public SingleStatsHelper<C> build() {
            return new SingleStatsHelper<>(builder.build());
        }
    }

    public static final <C> Builder<C> newBuilder() {
        return new Builder<>();
    }

}

@@ -1471,50 +1471,8 @@
 lic 
-com.github.phantomthief.stats.StatsHelper.
 Buil
@@ -1504,32 +1504,16 @@
 uration,
-%0A               
  TimeUni
@@ -1530,39 +1530,32 @@
 ) %7B%0A            
-return 
 builder.addDurat
@@ -1591,94 +1591,61 @@
     
-%7D%0A%0A        public com.github.phantomthief.stats.StatsHelper.Builder%3CC%3E%0A               
+    return this;%0A        %7D%0A%0A        public Builder%3CC%3E
  set
@@ -1690,39 +1690,32 @@
 ) %7B%0A            
-return 
 builder.setCount
@@ -1733,16 +1733,41 @@
 etter);%0A
+            return this;%0A
         
@@ -1788,50 +1788,8 @@
 lic 
-com.github.phantomthief.stats.StatsHelper.
 Buil
@@ -1904,23 +1904,16 @@
         
-return 
 builder.
@@ -1967,16 +1967,41 @@
 rvice);%0A
+            return this;%0A
         

fix builder return wrong type.