java.lang.Object
de.cuioss.tools.collect.MoreCollections
Overview
Utility Methods for Collections and some types to be used in the context of Collections.isEmpty()
The overloaded methodisEmpty(Collection) checks all kinds of Collections /
varargs parameter for not being null and emptiness. In case of
Streams it solely checks for being not null in order not to consume
it.
requireNotEmpty()
The overloaded methodrequireNotEmpty(Collection) checks all kinds of
Collections / varargs parameter for not being null nor empty. In case of
being null / empty they will throw an IllegalArgumentException
Map Difference
The methoddifference(Map, Map) creates an MapDifference
view on the two given maps in order to check, well whether they are equal or
not and if not which elements are differing.
Map contains key
Check whether the given Map contains at least one of the given keys (varags)- Author:
- Oliver Wolff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsKey(Map<?, ?> map, Object... keys) Checks whether the given map contains at least one of the given keys to be checked.static <K,V> MapDifference<K, V> difference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) Computes the difference between two maps.static booleanSimple check method for anullsafe check of the emptiness of the given parameter.static booleanSimple check method for anullsafe check of the emptiness of the given varags-parameter.static booleanisEmpty(Collection<?> elements) Simple check method for anullsafe check of the emptiness of the given parameter.static booleanSimple check method for anullsafe check of the emptiness of the given parameter.static booleanSimple check method for anullsafe check of the emptiness of the given parameter.static booleanSimple check method for anullsafe check of the emptiness of the given parameter.static <T> Iterable<T>requireNotEmpty(Iterable<T> elements) Shorthand for checking whether the given elements are empty or not.static <T> Iterable<T>requireNotEmpty(Iterable<T> elements, String message) Shorthand for checking whether the given elements are empty or not.static <T> Collection<T>requireNotEmpty(Collection<T> elements) Shorthand for checking whether the given elements are empty or not.static <T> Collection<T>requireNotEmpty(Collection<T> elements, String message) Shorthand for checking whether the given elements are empty or not.static <T> Iterator<T>requireNotEmpty(Iterator<T> elements) Shorthand for checking whether the given elements are empty or not.static <T> Iterator<T>requireNotEmpty(Iterator<T> elements, String message) Shorthand for checking whether the given elements are empty or not.static <K,V> Map<K, V> requireNotEmpty(Map<K, V> elements) Shorthand for checking whether the given elements are empty or not.static <K,V> Map<K, V> requireNotEmpty(Map<K, V> elements, String message) Shorthand for checking whether the given elements are empty or not.static <T> Stream<T>requireNotEmpty(Stream<T> elements) Shorthand for checking whether the given elements are empty or not.static <T> Stream<T>requireNotEmpty(Stream<T> elements, String message) Shorthand for checking whether the given elements are empty or not.static <T> T[]requireNotEmpty(T... elements) Shorthand for checking whether the given elements are empty or not.
-
Constructor Details
-
MoreCollections
public MoreCollections()
-
-
Method Details
-
isEmpty
Simple check method for anullsafe check of the emptiness of the given varags-parameter.- Parameters:
elements- to be checked, may be null- Returns:
trueis the given elements arenullorempty
-
isEmpty
Simple check method for anullsafe check of the emptiness of the given parameter.- Parameters:
elements- to be checked, may be null- Returns:
trueis the given elements arenullorempty
-
isEmpty
Simple check method for anullsafe check of the emptiness of the given parameter.- Parameters:
elements- to be checked, may be null- Returns:
trueis the given elements arenullorempty
-
isEmpty
Simple check method for anullsafe check of the emptiness of the given parameter.- Parameters:
map- to be checked, may be null- Returns:
trueis the given elements arenullorempty
-
isEmpty
Simple check method for anullsafe check of the emptiness of the given parameter.- Parameters:
elements- to be checked, may be null- Returns:
trueis the given elements arenullorempty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Type Parameters:
T- identifying the type to be checked- Parameters:
elements- to be checked- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Type Parameters:
T- identifying the type to be checked- Parameters:
elements- to be checked- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Type Parameters:
T- identifying the type to be checked- Parameters:
elements- to be checkedmessage- to be set in error-case- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Type Parameters:
K- the type for the keyV- the type for the value- Parameters:
elements- to be checked- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Type Parameters:
K- the type for the keyV- the type for the value- Parameters:
elements- to be checkedmessage- to be set in error-case- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Type Parameters:
T- identifying the type to be checked- Parameters:
elements- to be checked- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Type Parameters:
T- identifying the type to be checked- Parameters:
elements- to be checkedmessage- to be set in error-case- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Parameters:
elements- to be checked- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not.- Type Parameters:
T- identifying the type to be checked- Parameters:
elements- to be checkedmessage- to be set in error-case- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenullor empty
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not. Caution: In order not to consume the stream only a null check will be performed.- Type Parameters:
T- identifying the type to be checked- Parameters:
elements- to be checked- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenull
-
requireNotEmpty
Shorthand for checking whether the given elements are empty or not. Caution: In order not to consume the stream only a null check will be performed.- Type Parameters:
T- identifying the type to be checked- Parameters:
elements- to be checkedmessage- to be set in error-case- Returns:
- the given parameter
- Throws:
IllegalArgumentException- in case the given elements arenull
-
isEmpty
Simple check method for anullsafe check of the emptiness of the given parameter. Caution: In order not to consume the stream only a null check will be performed.- Parameters:
elements- to be checked, may be null- Returns:
trueis the given elements arenull. The Stream content will be untouched- Throws:
IllegalArgumentException- in case the given elements arenull
-
containsKey
Checks whether the given map contains at least one of the given keys to be checked.- Parameters:
map- to be checked. If it isnullor empty the method will always returnfalsekeys- to be checked. If it isnullor empty the method will always returnfalse- Returns:
trueif the map contains at lest one of the given keys,falseotherwise
-
difference
public static <K,V> MapDifference<K,V> difference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) Computes the difference between two maps. This difference is an immutable snapshot of the state of the maps at the time this method is called. It will never change, even if the maps change at a later time.Since this method uses
HashMapinstances internally, the keys of the supplied maps must be well-behaved with respect toObject.equals(java.lang.Object)andObject.hashCode().Note:If you only need to know whether two maps have the same mappings, call
left.equals(right)instead of this method.- Type Parameters:
K- the type for the keyV- the type for the value- Parameters:
left- the map to treat as the "left" map for purposes of comparison, must not be nullright- the map to treat as the "right" map for purposes of comparison , must not be null- Returns:
- the difference between the two maps
-