forked from plusone/plusone-commons
commit
f7f7bed848
|
@ -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 <T> List<T> nullToEmptyList(@Nullable List<T> list) {
|
||||
return list == null ? Collections.emptyList() : list;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static <T> Set<T> nullToEmptySet(@Nullable Set<T> set) {
|
||||
return set == null ? Collections.emptySet() : set;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static <K, V> Map<K, V> nullToEmptyMap(@Nullable Map<K, V> map) {
|
||||
return map == null ? Collections.emptyMap() : map;
|
||||
}
|
||||
|
||||
private CollectionTools() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue