public final class ObjectUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.Object |
NULL |
Modifier and Type | Method and Description |
---|---|
static <T> void |
assertAllElementsNotNull(T [] array) |
static <T> T |
assertNotNull(T t)
Deprecated.
Use
Objects.requireNonNull(Object) |
static int |
binarySearch(int fromIndex,
int toIndex,
IntIntFunction indexComparator)
Performs binary search on the range [fromIndex, toIndex)
|
static <T> T |
chooseNotNull(T t1,
T t2) |
static <T> T |
coalesce(java.lang.Iterable<? extends T> o) |
static <T> T |
coalesce(T t1,
T t2) |
static <T> T |
coalesce(T t1,
T t2,
T t3) |
static <T> void |
consumeIfCast(java.lang.Object obj,
java.lang.Class<T> clazz,
Consumer<? super T> consumer) |
static <T> void |
consumeIfNotNull(T obj,
Consumer<? super T> consumer) |
static <T,S> S |
doIfCast(java.lang.Object obj,
java.lang.Class<T> clazz,
Convertor<? super T,? extends S> convertor) |
static <T,S> S |
doIfNotNull(T obj,
Function<? super T,? extends S> function) |
static <T> T |
notNull(T value)
Deprecated.
Use
Objects.requireNonNull(Object) |
static <T> T |
notNull(T value,
NotNullFactory<? extends T> defaultValue) |
static <T> T |
notNull(T value,
T defaultValue) |
static <T> T |
nullizeByCondition(T obj,
Condition<? super T> condition) |
static <T> T |
nullizeIfDefaultValue(T obj,
T defaultValue) |
static void |
reachabilityFence(java.lang.Object o)
They promise in http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-February/051312.html that
the object reference won't be removed by JIT and GC-ed until this call.
|
static java.lang.Object |
sentinel(java.lang.String name)
Creates a new object which could be used as sentinel value (special value to distinguish from any other object).
|
static <T> T |
sentinel(java.lang.String name,
java.lang.Class<T> ofInterface)
Creates an instance of class
ofInterface with its Object.toString() method returning name . |
static <T> T |
tryCast(java.lang.Object obj,
java.lang.Class<T> clazz) |
public static final java.lang.Object NULL
NotNullizer
public static java.lang.Object sentinel(java.lang.String name)
name
- an object name, returned from Object.toString()
to simplify the debugging or heap dump analysis
(guaranteed to be stored as sentinel object field). If sentinel is assigned to the static final field,
it's recommended to supply that field name (possibly qualified with the class name).public static void reachabilityFence(java.lang.Object o)
public static <T> T sentinel(java.lang.String name, java.lang.Class<T> ofInterface)
ofInterface
with its Object.toString()
method returning name
.
No other guarantees about return value behaviour.
ofInterface
must represent an interface class.
Useful for stubs in generic code, e.g. for storing in List<T>
to represent empty special value.@Deprecated public static <T> T assertNotNull(T t)
Objects.requireNonNull(Object)
public static <T> void assertAllElementsNotNull(T [] array)
public static <T> T chooseNotNull(T t1, T t2)
public static <T> T coalesce(T t1, T t2)
public static <T> T coalesce(T t1, T t2, T t3)
public static <T> T coalesce(java.lang.Iterable<? extends T> o)
@Deprecated public static <T> T notNull(T value)
Objects.requireNonNull(Object)
public static <T> T notNull(T value, T defaultValue)
public static <T> T notNull(T value, NotNullFactory<? extends T> defaultValue)
public static <T> T tryCast(java.lang.Object obj, java.lang.Class<T> clazz)
public static <T,S> S doIfCast(java.lang.Object obj, java.lang.Class<T> clazz, Convertor<? super T,? extends S> convertor)
public static <T,S> S doIfNotNull(T obj, Function<? super T,? extends S> function)
public static <T> void consumeIfNotNull(T obj, Consumer<? super T> consumer)
public static <T> void consumeIfCast(java.lang.Object obj, java.lang.Class<T> clazz, Consumer<? super T> consumer)
public static <T> T nullizeByCondition(T obj, Condition<? super T> condition)
public static <T> T nullizeIfDefaultValue(T obj, T defaultValue)
public static int binarySearch(int fromIndex, int toIndex, IntIntFunction indexComparator)
indexComparator
- a comparator which receives a middle index and returns the result of comparision of the value at this index and the goal value
(e.g 0 if found, -1 if the value[middleIndex] < goal, or 1 if value[middleIndex] > goal)indexComparator
returned 0 or -insertionIndex-1
if wasn't foundArrays.binarySearch(Object[], Object, Comparator)
,
Collections.binarySearch(List, Object, Comparator)