- java.lang.Object
-
- com.speedment.common.invariant.NullUtil
-
public final class NullUtil extends Object
Utility class for checking invariants onnull-values.- Author:
- Emil Forslund
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
Map<K,V>requireKeys(Map<K,V> map, K requiredKey)Checks if the provided map contains all the provided required non-null key(s).static <K,V>
Map<K,V>requireKeys(Map<K,V> map, K... requiredKeys)Checks if the provided map contains all the provided required non-null key(s).static <K,V>
Map<K,V>requireKeys(Map<K,V> map, K requiredKeyA, K requiredKeyB)Checks if the provided map contains all the provided required key(s).static <K,V>
Map<K,V>requireKeys(Map<K,V> map, K requiredKeyA, K requiredKeyB, K requiredKeyC)Checks if the provided map contains all the provided required key(s).static <E,T extends Collection<E>>
TrequireNonNullElements(T collection)Checks if this collection is non null and also that all members are non-null.static <T> T[]requireNonNullElements(T[] array)Checks if this array is non null and also that all members are non-null.static <T> T[]requireNonNullElements(T[] array, String msg)Checks if this array is non null and also that all members are non-null.static voidrequireNonNulls(Object o0)Checks if this element is non null.static voidrequireNonNulls(Object o0, Object o1)Checks if the provided elements all are non null.static voidrequireNonNulls(Object o0, Object o1, Object o2)Checks if the provided elements all are non null.static voidrequireNonNulls(Object o0, Object o1, Object o2, Object o3)Checks if the provided elements all are non null.static voidrequireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4)Checks if the provided elements all are non null.static voidrequireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5)Checks if the provided elements all are non null.static voidrequireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5, Object o6)Checks if the provided elements all are non null.static voidrequireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7)Checks if the provided elements all are non null.
-
-
-
Method Detail
-
requireNonNullElements
public static <T> T[] requireNonNullElements(T[] array)
Checks if this array is non null and also that all members are non-null. If a null is detected a NullPointerException is thrown.- Type Parameters:
T- array type- Parameters:
array- to check- Returns:
- the same array instance as provided
- Throws:
NullPointerException- if a null is found in the array or if the array itself is null
-
requireNonNullElements
public static <E,T extends Collection<E>> T requireNonNullElements(T collection)
Checks if this collection is non null and also that all members are non-null. If a null is detected a NullPointerException is thrown.- Type Parameters:
E- the inner type of the collectionT- collection type- Parameters:
collection- to check- Returns:
- the same collection instance as provided
- Throws:
NullPointerException- if a null is found in the collection or if the array itself is null
-
requireNonNullElements
public static <T> T[] requireNonNullElements(T[] array, String msg)Checks if this array is non null and also that all members are non-null. If a null is detected a NullPointerException is thrown.- Type Parameters:
T- array type- Parameters:
array- to checkmsg- to show if a null is detected- Returns:
- the same array instance as provided
- Throws:
NullPointerException- if a null is found in the array or if the array itself is null
-
requireNonNulls
public static void requireNonNulls(Object o0)
Checks if this element is non null. If a null is detected a NullPointerException is thrown.- Parameters:
o0- object to check- Throws:
NullPointerException- if the element is null
-
requireNonNulls
public static void requireNonNulls(Object o0, Object o1)
Checks if the provided elements all are non null. If a null is detected a NullPointerException is thrown.- Parameters:
o0- object to checko1- object to check- Throws:
NullPointerException- if at least one of the elements are null
-
requireNonNulls
public static void requireNonNulls(Object o0, Object o1, Object o2)
Checks if the provided elements all are non null. If a null is detected a NullPointerException is thrown.- Parameters:
o0- object to checko1- object to checko2- object to check- Throws:
NullPointerException- if at least one of the elements are null
-
requireNonNulls
public static void requireNonNulls(Object o0, Object o1, Object o2, Object o3)
Checks if the provided elements all are non null. If a null is detected a NullPointerException is thrown.- Parameters:
o0- object to checko1- object to checko2- object to checko3- object to check- Throws:
NullPointerException- if at least one of the elements are null
-
requireNonNulls
public static void requireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4)
Checks if the provided elements all are non null. If a null is detected a NullPointerException is thrown.- Parameters:
o0- object to checko1- object to checko2- object to checko3- object to checko4- object to check- Throws:
NullPointerException- if at least one of the elements are null
-
requireNonNulls
public static void requireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5)
Checks if the provided elements all are non null. If a null is detected a NullPointerException is thrown. s- Parameters:
o0- object to checko1- object to checko2- object to checko3- object to checko4- object to checko5- object to check- Throws:
NullPointerException- if at least one of the elements are null
-
requireNonNulls
public static void requireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5, Object o6)
Checks if the provided elements all are non null. If a null is detected a NullPointerException is thrown.- Parameters:
o0- object to checko1- object to checko2- object to checko3- object to checko4- object to checko5- object to checko6- object to check- Throws:
NullPointerException- if at least one of the elements are null
-
requireNonNulls
public static void requireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7)
Checks if the provided elements all are non null. If a null is detected a NullPointerException is thrown.- Parameters:
o0- object to checko1- object to checko2- object to checko3- object to checko4- object to checko5- object to checko6- object to checko7- object to check- Throws:
NullPointerException- if at least one of the elements are null
-
requireKeys
@SafeVarargs public static <K,V> Map<K,V> requireKeys(Map<K,V> map, K... requiredKeys)
Checks if the provided map contains all the provided required non-null key(s).- Type Parameters:
K- key typeV- value type- Parameters:
map- to checkrequiredKeys- to check for existence- Returns:
- the same instance of the provided map
- Throws:
NoSuchElementException- if at least one required key is not a key in the provided MapNullPointerException- if the provided Map is null or if at least one of the required key are null
-
requireKeys
public static <K,V> Map<K,V> requireKeys(Map<K,V> map, K requiredKey)
Checks if the provided map contains all the provided required non-null key(s).- Type Parameters:
K- key typeV- value type- Parameters:
map- to checkrequiredKey- to check for existence- Returns:
- the same instance of the provided map
- Throws:
NoSuchElementException- if the required key is not a key in the provided MapNullPointerException- if the provided Map is null or if the required key is null
-
requireKeys
public static <K,V> Map<K,V> requireKeys(Map<K,V> map, K requiredKeyA, K requiredKeyB)
Checks if the provided map contains all the provided required key(s).- Type Parameters:
K- key typeV- value type- Parameters:
map- to checkrequiredKeyA- to check for existencerequiredKeyB- to check for existence- Returns:
- the same instance of the provided map
- Throws:
NoSuchElementException- if the required keys are not keys in the provided MapNullPointerException- if the provided Map is null
-
requireKeys
public static <K,V> Map<K,V> requireKeys(Map<K,V> map, K requiredKeyA, K requiredKeyB, K requiredKeyC)
Checks if the provided map contains all the provided required key(s).- Type Parameters:
K- key typeV- value type- Parameters:
map- to checkrequiredKeyA- to check for existencerequiredKeyB- to check for existencerequiredKeyC- to check for existence- Returns:
- the same instance of the provided map
- Throws:
NoSuchElementException- if the required keys are not keys in the provided MapNullPointerException- if the provided Map is null
-
-