Package com.fizzed.crux.util
Class MoreObjects
- java.lang.Object
-
- com.fizzed.crux.util.MoreObjects
-
public class MoreObjects extends java.lang.ObjectMethods that java.util.Objects should include.- Author:
- jjlauer
-
-
Constructor Summary
Constructors Constructor Description MoreObjects()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tfirst(java.lang.Iterable<T> values)static <T> Tfirst(T[] values)static <T> booleanin(T value, java.lang.Iterable<T> values)Checks whether the value is in the list of values.static <T> booleanin(T value, T... values)Checks whether the value is in the list of values.static booleanisBlank(java.lang.CharSequence chars)Checks if the string is null, empty, or has only characters consisting of spaces.static booleanisEmpty(java.lang.CharSequence chars)Checks if the string is null or has zero chars.static booleanisEmpty(java.lang.Iterable<?> values)Null-safe evaluation of whether an Iterable is empty.static booleanisEmpty(java.util.Collection<?> values)Null-safe evaluation of whether a collection is empty.static booleanisEmpty(java.util.Map<?,?> map)Null-safe evaluation of whether a map is empty.static <T> booleanisEmpty(T[] values)Null-safe evaluation of whether an array is empty.static booleanisTrue(java.lang.Boolean value)Null-safe evaluation of whether a boolean is true.static <T> java.lang.Iterable<T>iterable(java.lang.Iterable<T> values)Null-safe iterable to simplify use in for-loops, etc.static <T> java.lang.Iterable<T>iterable(T[] values)Null-safe iterable to simplify use in for-loops, etc.static <T> Tlast(java.lang.Iterable<T> values)static <T> Tlast(T[] values)static intsize(java.lang.Object[] values)Null-safe evaluation of the length of an array.static intsize(java.util.Collection<?> values)Null-safe evaluation of the size of a collection.static intsize(java.util.Map<?,?> map)Null-safe evaluation of the size of a map.
-
-
-
Method Detail
-
isTrue
public static boolean isTrue(java.lang.Boolean value)
Null-safe evaluation of whether a boolean is true.- Parameters:
value- The value to check- Returns:
- True if value is non-null AND true otherwise false
-
in
public static <T> boolean in(T value, T... values)Checks whether the value is in the list of values.- Type Parameters:
T- The type- Parameters:
value- The value to checkvalues- The list of values to check against- Returns:
- True if the value is contained otherwise false
-
in
public static <T> boolean in(T value, java.lang.Iterable<T> values)Checks whether the value is in the list of values.- Type Parameters:
T- The type- Parameters:
value- The value to checkvalues- The list of values to check against- Returns:
- True if the value is contained otherwise false
-
iterable
public static <T> java.lang.Iterable<T> iterable(T[] values)
Null-safe iterable to simplify use in for-loops, etc.- Type Parameters:
T-- Parameters:
values-- Returns:
- An empty iterable if values is null otherwise an iterable of values.
-
iterable
public static <T> java.lang.Iterable<T> iterable(java.lang.Iterable<T> values)
Null-safe iterable to simplify use in for-loops, etc.- Type Parameters:
T-- Parameters:
values-- Returns:
- An empty iterable if values is null otherwise an iterable of values.
-
size
public static int size(java.lang.Object[] values)
Null-safe evaluation of the length of an array.- Parameters:
values-- Returns:
- 0 if array is null or empty otherwise the length
-
size
public static int size(java.util.Collection<?> values)
Null-safe evaluation of the size of a collection.- Parameters:
values-- Returns:
- 0 if collection is null or empty otherwise the length
-
size
public static int size(java.util.Map<?,?> map)
Null-safe evaluation of the size of a map.- Parameters:
map-- Returns:
- 0 if map is null or empty otherwise the length
-
first
public static <T> T first(T[] values)
-
first
public static <T> T first(java.lang.Iterable<T> values)
-
last
public static <T> T last(T[] values)
-
last
public static <T> T last(java.lang.Iterable<T> values)
-
isEmpty
public static <T> boolean isEmpty(T[] values)
Null-safe evaluation of whether an array is empty.- Type Parameters:
T-- Parameters:
values- The array- Returns:
- True if array is null or has 0 elements
-
isEmpty
public static boolean isEmpty(java.util.Collection<?> values)
Null-safe evaluation of whether a collection is empty.- Parameters:
values- The collection- Returns:
- True if the collection is null or has 0 elements.
-
isEmpty
public static boolean isEmpty(java.lang.Iterable<?> values)
Null-safe evaluation of whether an Iterable is empty.- Parameters:
values- The iterable- Returns:
- True if the iterable is null or has 0 elements.
-
isEmpty
public static boolean isEmpty(java.util.Map<?,?> map)
Null-safe evaluation of whether a map is empty.- Parameters:
map- The map- Returns:
- True if the map is null or has 0 elements.
-
isEmpty
public static boolean isEmpty(java.lang.CharSequence chars)
Checks if the string is null or has zero chars.
-
isBlank
public static boolean isBlank(java.lang.CharSequence chars)
Checks if the string is null, empty, or has only characters consisting of spaces.
-
-