/*
 * Copyright (c) 2014-2015 Sean Liu.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.baoti.pioneer.biz.interactor;

import com.github.baoti.pioneer.biz.ResourcePage;

/**
 * Created by liuyedong on 2015/1/1.
 */
public interface PageInteractor<E> extends DeferredInteractor<ResourcePage<E>> {
}

@@ -694,16 +694,106 @@
 rcePage;
+%0Aimport com.github.baoti.pioneer.biz.exception.BizException;%0A%0Aimport java.util.Collection;
 %0A%0A/**%0A *
@@ -911,11 +911,1775 @@
 ge%3CE%3E%3E %7B
+%0A%0A    public abstract class Simple%3CE%3E implements PageInteractor%3CE%3E %7B%0A%0A        private final int pageStart;%0A        protected final int pageSize;%0A%0A        public Simple(int pageStart, int pageSize) %7B%0A            this.pageStart = pageStart;%0A            this.pageSize = pageSize;%0A        %7D%0A%0A        @Override%0A        public ResourcePage%3CE%3E interact() throws BizException %7B%0A            return createPage(pageStart, loadResources(pageStart));%0A        %7D%0A%0A        protected abstract Collection%3CE%3E loadResources(int pageIndex) throws BizException;%0A%0A        protected boolean hasNextPage(int pageIndex, Collection%3CE%3E resources) %7B%0A            return !resources.isEmpty() && (pageSize %3C= 0 %7C%7C resources.size() %3E= pageSize);%0A        %7D%0A%0A        protected ResourcePage%3CE%3E nextPage(int pageIndex) throws BizException %7B%0A            return createPage(pageIndex + 1, loadResources(pageIndex + 1));%0A        %7D%0A%0A        protected ResourcePage%3CE%3E createPage(int pageIndex, Collection%3CE%3E resources) %7B%0A            return new Page(pageIndex, resources);%0A        %7D%0A%0A        class Page implements ResourcePage%3CE%3E %7B%0A            private final int pageIndex;%0A            private final Collection%3CE%3E resources;%0A%0A            public Page(int pageIndex, Collection%3CE%3E resources) %7B%0A                this.pageIndex = pageIndex;%0A                this.resources = resources;%0A            %7D%0A%0A            @Override%0A            public Collection%3CE%3E getResources() %7B%0A                return resources;%0A            %7D%0A%0A            @Override%0A            public boolean hasNext() %7B%0A                return hasNextPage(pageIndex, resources);%0A            %7D%0A%0A            @Override%0A            public ResourcePage%3CE%3E next() throws BizException %7B%0A                return nextPage(pageIndex);%0A            %7D%0A        %7D%0A    %7D
 %0A%7D%0A

添加 PageInteractor.Simple