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) {}
    
  • 相关阅读:
    Delphi下的WinSock编程
    基于Delphi使用API实现Sock通讯
    delphi7与XE的变量与函数的改变
    Delphi7·ProgressBar控件
    delphi 进度条
    delphi带包编译详解(build with runtime package)
    TList 的 quicksort 算法研究和使用。
    Delphi7升级到Delphi 2010、Delphi XE、Delphi XE2总结
    Delphi编译错误代码翻译表
    Firebird(火鸟)数据库 v3.0.3.32900官方版
  • 原文地址:https://www.cnblogs.com/warrior/p/11915813.html
Copyright © 2011-2022 走看看