@@ -0,0 +1,2581 @@
+package com.glung.redux;%0A%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Aimport redux.api.*;%0Aimport redux.api.Store;%0Aimport redux.api.enhancer.Middleware;%0A%0Apublic class Middlewares %7B%0A%0A    private static class MiddlewareStore%3CS%3E implements redux.api.Store%3CS%3E %7B%0A%0A        private final redux.api.Store%3CS%3E nextStore;%0A        private final List%3Credux.api.enhancer.Middleware%3CS%3E%3E middlewares;%0A%0A        public MiddlewareStore(redux.api.Store%3CS%3E nextStore,%0A                List%3Credux.api.enhancer.Middleware%3CS%3E%3E middlewares) %7B%0A            this.nextStore = nextStore;%0A            this.middlewares = middlewares;%0A        %7D%0A%0A        @Override%0A        public S getState() %7B%0A            return nextStore.getState();%0A        %7D%0A%0A        @Override%0A        public Subscription subscribe(Subscriber subscriber) %7B%0A            return nextStore.subscribe(subscriber);%0A        %7D%0A%0A        @Override%0A        public void replaceReducer(Reducer%3CS%3E reducer) %7B%0A            nextStore.replaceReducer(reducer);%0A        %7D%0A%0A        @Override%0A        public Object dispatch(Object action) %7B%0A            return createMiddlewareDispatcher(middlewares).dispatch(action);%0A        %7D%0A%0A        private Dispatcher createMiddlewareDispatcher(final List%3Credux.api.enhancer.Middleware%3CS%3E%3E middlewares) %7B%0A            if (middlewares.isEmpty()) %7B%0A                return nextStore;%0A            %7D else %7B%0A                return new Dispatcher() %7B%0A                    @Override%0A                    public Object dispatch(Object action) %7B%0A                        Middleware%3CS%3E nextMiddleware = middlewares.get(0);%0A                        List%3Credux.api.enhancer.Middleware%3CS%3E%3E restMiddlewares = middlewares.subList(1, middlewares.size());%0A                        return  nextMiddleware.dispatch(nextStore, createMiddlewareDispatcher(restMiddlewares), action);%0A                    %7D%0A                %7D;%0A%0A            %7D%0A        %7D%0A    %7D%0A%0A    @SafeVarargs%0A    public static %3CS%3E redux.api.Store.Enhancer%3CS%3E applyMiddlewares(final redux.api.enhancer.Middleware%3CS%3E... middlewares) %7B%0A        return new redux.api.Store.Enhancer%3CS%3E()%7B%0A            @Override%0A            public Store.Creator%3CS%3E enhance(final Store.Creator%3CS%3E next) %7B%0A                return new Store.Creator%3CS%3E() %7B%0A                    @Override%0A                    public Store%3CS%3E create(final Reducer%3CS%3E reducer,final S initialState) %7B%0A                        Store%3CS%3E store = next.create(reducer, initialState);%0A                        return new MiddlewareStore%3C%3E(store, Arrays.asList(middlewares));%0A                    %7D%0A                %7D;%0A            %7D%0A        %7D;%0A    %7D%0A%7D%0A

Implement applyMiddlewares