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) {}
    
  • 相关阅读:
    1022. D进制的A+B (20)
    1032. 挖掘机技术哪家强(20)
    1001. 害死人不偿命的(3n+1)猜想 (15)
    结构-06. 复数四则运算(15)
    结构-05. 有理数均值(20)
    结构-04. 通讯录的录入与显示(10)
    结构-03. 平面向量加法(10)
    软考错题合集之13-05-AM
    软考笔记第八天之法律发规与标准化知识
    软考笔记第七天之程序设计语言与语言处理程序基础
  • 原文地址:https://www.cnblogs.com/warrior/p/11915813.html
Copyright © 2011-2022 走看看