Created
February 8, 2021 14:19
Revisions
-
lovelock created this gist
Feb 8, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ package fun.happyhacker; import lombok.Data; import org.apache.commons.codec.digest.DigestUtils; import java.util.*; import java.util.concurrent.TimeUnit; /** * @author Frost Wong <frostwong@hotmail.com> * @version 2021/2/8 **/ public class CompletableFutureTest { public static void main(String[] args) throws InterruptedException { CompletableFutureTest completableFutureTest = new CompletableFutureTest(); completableFutureTest.compose(); } private List<Target> compose() throws InterruptedException { List<Long> ids = genIds(); Map<Long, String> contentMap = fun1(ids); Map<Long, List<String>> aMap = fun2(ids); Map<Long, String> bMap = hash(contentMap); List<Target> list = new ArrayList<>(); for (Long id : ids) { Target target = new Target(); target.setId(id); target.setContent(contentMap.get(id)); target.setList(aMap.get(id)); target.setMd5(bMap.get(id)); } return list; } private List<Long> genIds() { return Collections.emptyList(); } private Map<Long, String> fun1(List<Long> ids) throws InterruptedException { Map<Long, String> result = new HashMap<>(); for (Long id : ids) { TimeUnit.MILLISECONDS.sleep(100); result.put(id, id.toString()); } return result; } private Map<Long, List<String>> fun2(List<Long> ids) throws InterruptedException { Map<Long, List<String>> result = new HashMap<>(); for (Long id : ids) { TimeUnit.MILLISECONDS.sleep(100); result.put(id, List.of(id.toString(), id.toString())); } return result; } private Map<Long, String> hash(Map<Long, String> map) throws InterruptedException { Map<Long, String> result = new HashMap<>(); for (Map.Entry<Long, String> entry : map.entrySet()) { TimeUnit.MILLISECONDS.sleep(100); result.put(entry.getKey(), DigestUtils.md5Hex(entry.getValue())); } return result; } } @Data class Target { private Long id; private String content; private String md5; private List<String> list; }