zoukankan      html  css  js  c++  java
  • 反向操作

    今天修改个东西,看到有一段代码被人优化了!!!

    优化前

      public Optional<List<Map<String, String>>> getByCodes(String type, List<String> codeList) {
            if (codeList.size() <= DEFAULT_PAGE_SIZE) {
                return getByBatch(type, codeList);
            }
    
            return IntStream.range(0, (codeList.size() + DEFAULT_PAGE_SIZE - 1) / DEFAULT_PAGE_SIZE)
                    .mapToObj(i -> codeList.subList(i * DEFAULT_PAGE_SIZE, Math.min(DEFAULT_PAGE_SIZE * (i + 1), codeList.size())))
                    .map(list -> getByBatch(type, list).orElse(new ArrayList<>()))
                    .reduce((a, b) -> {
                        a.addAll(b);
                        return a;
                    });
    
        }    
    
    private Optional<List<Map<String, String>>> getByBatch(String type, List<String> codeList) {}
    

    优化后

        public Optional<List<Map<String, String>>> getByCodes(String type, List<String> codeList) {
            Optional<List<Map<String, String>>> result = null;
            if (codeList.size() <= DEFAULT_PAGE_SIZE) {
                result = getByBatch(type, codeList);
    
                if(result.isPresent() && CollectionUtils.isNotEmpty(result.get())){
                    return result;
                }
                return Optional.empty();
            }
    
            result = IntStream.range(0, (codeList.size() + DEFAULT_PAGE_SIZE - 1) / DEFAULT_PAGE_SIZE)
                    .mapToObj(i -> codeList.subList(i * DEFAULT_PAGE_SIZE, Math.min(DEFAULT_PAGE_SIZE * (i + 1), codeList.size())))
                    .map(list -> getByBatch(type, list).orElse(new ArrayList<>()))
                    .reduce((a, b) -> {
                        a.addAll(b);
                        return a;
                    });
            if(result.isPresent() && CollectionUtils.isNotEmpty(result.get())){
                return result;
            }
            return Optional.empty();
        }
    
     private Optional<List<Map<String, String>>> getByBatch(String type, List<String> codeList) {}
    
  • 相关阅读:
    数据结构----------------优先队列
    IDEA建立---- java web项目
    mysql 基础篇5(mysql语法---数据)
    数据库 基础篇4(mysql语法---表)
    数据库 基础篇3(mysql语法)
    数据库 基础篇2(mysql)
    vi保存搜索结果
    自定义修改connect rule
    xargs 的应用
    nfs,nis nobody的问题
  • 原文地址:https://www.cnblogs.com/warrior/p/11915813.html
Copyright © 2011-2022 走看看