diff --git a/src/main/java/xyz/zhouxy/plusone/commons/collection/CollectionTools.java b/src/main/java/xyz/zhouxy/plusone/commons/collection/CollectionTools.java index d15aaee..f5e671b 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/collection/CollectionTools.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/collection/CollectionTools.java @@ -17,8 +17,12 @@ package xyz.zhouxy.plusone.commons.collection; import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.Map; +import java.util.Set; +import javax.annotation.Nonnull; import javax.annotation.Nullable; /** @@ -51,6 +55,21 @@ public class CollectionTools { return map != null && !map.isEmpty(); } + @Nonnull + public static List nullToEmptyList(@Nullable List list) { + return list == null ? Collections.emptyList() : list; + } + + @Nonnull + public static Set nullToEmptySet(@Nullable Set set) { + return set == null ? Collections.emptySet() : set; + } + + @Nonnull + public static Map nullToEmptyMap(@Nullable Map map) { + return map == null ? Collections.emptyMap() : map; + } + private CollectionTools() { throw new IllegalStateException("Utility class"); }