컬렉션에 있는 객체의 속성 요소에 따라 지정된 양만큼 그룹화

3988 단어 기술적 문제

컬렉션에 있는 객체의 속성 요소에 따라 지정된 양만큼 그룹화

  • 컬렉션 분할
  • public class CollectionsSplitFactory {
        public void buildCollections(List<T> originCollections, String propName, int batchSize){
            Map<Integer, List<String>> objsMap= splitCollectionsByPropName(originCollections, propName, batchSize);
            for(List<String> obj : objsMap.values()){
                // 
            }
        }
    
        private Map<Integer, List<String>> splitCollectionsByPropName(List<T> originCollections, String propName, int batchSize){
            Map<Integer, List<String>> objsMap = new HashMap<Integer, List<String>>();
                // 
                List<String> objs = originCollections.pluck(propName);
                int size = (int)Math.ceil((double)objs.size()/batchSize);
                for(int i=0; i<size; i++){
                    int startInx = batchSize*i;
                    int endInx = batchSize*(i+1)<objs.size()?batchSize*(i+1):objs.size();
                    List<String> subList = objs.subList(startInx, endInx);
                    objsMap.put(i, subList);
                }
                return objsMap;
        }
    }

    좋은 웹페이지 즐겨찾기