public class Optionals
extends java.lang.Object
null, and the utility methods will provide default
values in this case.| Modifier and Type | Method and Description |
|---|---|
static <T> T |
get(java.util.List<T> list,
int index)
Returns the specified element from the given list, or
null
if the list is null or the index is not valid. |
static <V> V |
get(java.lang.Object key,
java.util.Map<?,V> map)
Returns the value that is associated with the given key in the
given map, or
null if either the key or the map
is null. |
static <T> java.util.List<T> |
of(java.util.List<T> list)
Returns the given list, or an unmodifiable empty list if the
given list is
null. |
static <K,V> java.util.Map<K,V> |
of(java.util.Map<K,V> map)
Returns the given map, or an unmodifiable empty map if the
given map is
null. |
static <T> T |
of(T value,
T defaultValue)
Returns the given value, or the default value if the given value
is
null. |
public static <T> java.util.List<T> of(java.util.List<T> list)
null.T - The element typelist - The listpublic static <T> T get(java.util.List<T> list,
int index)
null
if the list is null or the index is not valid.T - The element typelist - The listindex - The indexpublic static <K,V> java.util.Map<K,V> of(java.util.Map<K,V> map)
null.K - The key typeV - The value typemap - The mappublic static <T> T of(T value,
T defaultValue)
null.T - The value typevalue - The valuedefaultValue - The default valuepublic static <V> V get(java.lang.Object key,
java.util.Map<?,V> map)
null if either the key or the map
is null.V - The value typekey - The keymap - The mapCopyright © 2022. All Rights Reserved.