java.lang.Object
dev.metaschema.core.util.ObjectUtils
A collection of utilities for checking and managing Java objects.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TasNullableType(Object obj) Cast the provided object as the requested return type.static <T> TCast the provided object as the requested return type.static <T> Stream<T>filterNull(T item) A filter used to remove null items from a stream.static <T> TnotNull(T obj) Assert that the provided object is notnull.static <T> TrequireNonNull(T obj) Require a non-null value.static <T> TrequireNonNull(T obj, String message) Require a non-null value.
-
Method Details
-
notNull
@NonNull public static <T> T notNull(@Nullable T obj) Assert that the provided object is notnull.This method sets the expectation that the provided object is not
nullin cases where a non-null value is required.- Type Parameters:
T- the object type- Parameters:
obj- the object- Returns:
- the object
-
requireNonNull
@NonNull public static <T> T requireNonNull(@Nullable T obj) Require a non-null value.- Type Parameters:
T- the type of the reference- Parameters:
obj- the object reference to check for nullity- Returns:
objif notnull- Throws:
NullPointerException- ifobjisnull
-
requireNonNull
Require a non-null value.- Type Parameters:
T- the type of the reference- Parameters:
obj- the object reference to check for nullitymessage- detail message to be used in the event that aNullPointerExceptionis thrown- Returns:
objif notnull- Throws:
NullPointerException- ifobjisnull
-
filterNull
A filter used to remove null items from a stream.- Type Parameters:
T- the item type- Parameters:
item- the item to filter- Returns:
- the item as a steam or an empty stream if the item is
null
-
asType
Cast the provided object as the requested return type.- Type Parameters:
T- the Java type to cast the object to- Parameters:
obj- the object to cast- Returns:
- the object cast to the requested type
- Throws:
ClassCastException- if the object cannot be cast to the requested type
-
asNullableType
Cast the provided object as the requested return type.If the object is
null, the returned value will benull.- Type Parameters:
T- the Java type to cast the object to- Parameters:
obj- the object to cast, which may benull- Returns:
- the object cast to the requested type, or
nullif the provided object isnull - Throws:
ClassCastException- if the object cannot be cast to the requested type
-