public abstract class ObjectUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends CharSequence> |
getNonEmptyOrDefault(T instance,
T defaultValue)
Returns the given instance, if not
null or of zero length, or otherwise the given defaultValue . |
static <I,T> T |
getOrDefault(I instance,
Function<I,T> valueProvider,
T defaultValue)
Returns the result of the given
valueProvider by ingesting the given instance , if the
instance is not null . |
static <T> T |
getOrDefault(T instance,
Supplier<T> defaultProvider)
Returns the given instance, if not
null , or otherwise the value provided by defaultProvider . |
static <T> T |
getOrDefault(T instance,
T defaultValue)
Returns the given instance, if not
null , or otherwise the given defaultValue . |
static long |
getRemainingOfDeadline(long deadline)
Gets number of millis which are remaining of current deadline to be reached by
System.currentTimeMillis() . |
static <T> Class<T> |
nullSafeTypeOf(T instance)
Returns the type of the given
instance , if it is not null . |
public static <T> T getOrDefault(T instance, Supplier<T> defaultProvider)
null
, or otherwise the value provided by defaultProvider
.T
- the type of value to returninstance
- the value to return, if not null
defaultProvider
- to provide the value, when instance
is null
instance
if not null
, otherwise the value provided by defaultProvider
public static <T> T getOrDefault(T instance, T defaultValue)
null
, or otherwise the given defaultValue
.T
- the type of value to returninstance
- the value to return, if not null
defaultValue
- the value, when instance
is null
instance
if not null
, otherwise defaultValue
public static <T extends CharSequence> T getNonEmptyOrDefault(T instance, T defaultValue)
null
or of zero length, or otherwise the given defaultValue
.T
- the type of value to returninstance
- the value to return, if not null
defaultValue
- the value, when instance
is null
instance
if not null
, otherwise defaultValue
public static <I,T> T getOrDefault(I instance, Function<I,T> valueProvider, T defaultValue)
valueProvider
by ingesting the given instance
, if the
instance
is not null
. If it is, the defaultValue
is returned.I
- the type of the instance
to verify and use by the valueProvider
T
- the type of value to returninstance
- the value to verify if it is not null
. If it isn't, the given valueProvider
will be invoked with this objectvalueProvider
- the function to return the result of by ingesting the instance
if it is not nulldefaultValue
- the value to return if the given instance
is null
valueProvider
by ingesting instance
if it is not null
, otherwise
the defaultValue
public static <T> Class<T> nullSafeTypeOf(T instance)
instance
, if it is not null
. If it is null
, Object.getClass()
will be returned.T
- the generic type of the Class
to returninstance
- the object to return the type forinstance
if it is not null
, otherwise Object.getClass()
public static long getRemainingOfDeadline(long deadline)
System.currentTimeMillis()
. If deadline is passed, 0 will be returned.deadline
- deadline to be metCopyright © 2010–2020. All rights reserved.