Class GetUtils
- java.lang.Object
-
- com.igormaznitsa.meta.common.utils.GetUtils
-
-
Constructor Summary
Constructors Modifier Constructor Description private
GetUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
ensureNonNull(T value)
Get value if it is not null.static <T> T
ensureNonNull(T value, T defaultValue)
Get value and ensure that the value is not nullstatic java.lang.String
ensureNonNullAndNonEmpty(java.lang.String value, java.lang.String dflt)
Get non-null non-empty string.static java.lang.String
ensureNonNullStr(java.lang.String value)
Ensure that a string will not be null.static <T> T
findFirstNonNull(T... objects)
Find the first non-null value in an array and return that.
-
-
-
Method Detail
-
ensureNonNull
public static <T> T ensureNonNull(T value, T defaultValue)
Get value and ensure that the value is not null- Type Parameters:
T
- type of value- Parameters:
value
- the valuedefaultValue
- the default value to be returned if the value is null- Returns:
- not null value
- Throws:
java.lang.AssertionError
- if both the value and the default value are null- Since:
- 1.0
-
ensureNonNull
public static <T> T ensureNonNull(T value)
Get value if it is not null.- Type Parameters:
T
- type of value- Parameters:
value
- the value- Returns:
- the value if it is not null
- Throws:
java.lang.AssertionError
- if the value is null- Since:
- 1.0
-
findFirstNonNull
public static <T> T findFirstNonNull(T... objects)
Find the first non-null value in an array and return that.- Type Parameters:
T
- type of value- Parameters:
objects
- array to find value- Returns:
- the first non-null value from the array
- Throws:
java.lang.AssertionError
- if the array is null or it doesn't contain a non-null value- Since:
- 1.0
-
ensureNonNullAndNonEmpty
public static java.lang.String ensureNonNullAndNonEmpty(java.lang.String value, @Constraint("notEmpty(X)") java.lang.String dflt)
Get non-null non-empty string.- Parameters:
value
- a base stringdflt
- default string to be provided if value is null or empty- Returns:
- non-nullable non-empty string
- Since:
- 1.1.1
-
ensureNonNullStr
public static java.lang.String ensureNonNullStr(java.lang.String value)
Ensure that a string will not be null.- Parameters:
value
- value to be checked- Returns:
- the value if it is not null or empty string if the value is null
- Since:
- 1.1.1
-
-