码迷,mamicode.com
首页 > 其他好文 > 详细

建造者模式构建可复用性大集合切片循环

时间:2015-05-05 19:54:06      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:空间复杂度算法 建造者模式

package com.qunar.piao.sight.common.util;

import com.google.common.annotations.GwtCompatible;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;

import java.util.Collection;
import java.util.List;

/**
 * Created by yubin.qi on 2015/4/15.
 */
public class SubListUtil {

    //Function<? super F, ? extends T>
    public static interface SubListFuntion<T> {

        public  void processor(List<T> tList);


    }



    public static <T> void dealForSubList(List<T> totalList, Integer subSize, SubListFuntion<T> subFuntion) {

        int count = totalList.size();
        int iteratorCount = count / subSize;
        for (int i = 0; i <= iteratorCount; i++) {
            int endIndex, startIndex;
            startIndex = i * subSize;
            endIndex = ((endIndex = (i + 1) * subSize) > count) ? count : endIndex;
            if (endIndex == startIndex) {
                break;
            }

            List<T> subList = totalList.subList(startIndex, endIndex);
            //dataPre
            subFuntion.processor(subList);

        }

    }


    public static void main(String args[]) {
        List<String> as = null;
        SubListUtil.dealForSubList(as, 1000, new SubListFuntion<String>() {
            @Override
            public void processor(List<String> strings) {

            }
        });
    }

}


本文出自 “程序猿De香蕉” 博客,请务必保留此出处http://qiyubin.blog.51cto.com/3642349/1642185

建造者模式构建可复用性大集合切片循环

标签:空间复杂度算法 建造者模式

原文地址:http://qiyubin.blog.51cto.com/3642349/1642185

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!