From 1dcbe6b0f2f272945be20f67cbb580ad350ed9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Fri, 25 Nov 2022 15:00:04 +0800 Subject: [PATCH] feat: get rid of Pair class --- .../testable/core/util/CollectionUtil.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/testable-core/src/main/java/com/alibaba/testable/core/util/CollectionUtil.java b/testable-core/src/main/java/com/alibaba/testable/core/util/CollectionUtil.java index ab93bec..3d5a062 100644 --- a/testable-core/src/main/java/com/alibaba/testable/core/util/CollectionUtil.java +++ b/testable-core/src/main/java/com/alibaba/testable/core/util/CollectionUtil.java @@ -1,7 +1,5 @@ package com.alibaba.testable.core.util; -import com.alibaba.testable.core.model.Pair; - import java.util.*; public class CollectionUtil { @@ -121,25 +119,35 @@ public class CollectionUtil { /** * Create a map - * @param pair elements to add + * @param entry elements to add * @return map of the provided items */ - public static Map mapOf(Pair... pair) { - return mapOf(new HashMap(pair.length), pair); + public static Map mapOf(Map.Entry... entry) { + return appendMap(new HashMap(entry.length), entry); } /** * Create an ordered map - * @param pair elements to add + * @param entry elements to add * @return ordered map of the provided items */ - public static Map orderMapOf(Pair... pair) { - return mapOf(new LinkedHashMap(pair.length), pair); + public static Map orderMapOf(Map.Entry... entry) { + return appendMap(new LinkedHashMap(entry.length), entry); } - private static Map mapOf(Map kvs, Pair[] pair) { - for (Pair p : pair) { - kvs.put(p.getLeft(), p.getRight()); + /** + * Create a map entry + * @param key the key + * @param value the value + * @return entry of provided key and value + */ + public static Map.Entry entryOf(K key, V value) { + return new AbstractMap.SimpleEntry(key, value); + } + + private static Map appendMap(Map kvs, Map.Entry[] entry) { + for (Map.Entry p : entry) { + kvs.put(p.getKey(), p.getValue()); } return kvs; }