Package com.github.mizool.core
Class Optionals
java.lang.Object
com.github.mizool.core.Optionals
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Stream<T>
streamPresentValue
(@NonNull Optional<T> optional) unwrapRequiredObject
(@NonNull Class<T> classOfT) Used when an object can be reasonably expected to exist, resulting in a DataInconsistencyException if it does not exist.static <T> T
unwrapRequiredObject
(@NonNull Optional<T> wrapped, @NonNull Class<T> classOfT) Used when an object can be reasonably expected to exist, resulting in a DataInconsistencyException if it does not exist.unwrapUserMentionedObject
(@NonNull Class<T> classOfT) Used when a user-submitted entity refers to another object, resulting in a UnprocessableEntityException if that object does not exist.static <T> T
unwrapUserMentionedObject
(@NonNull Optional<T> wrapped, @NonNull Class<T> classOfT) Used when a user-submitted entity refers to another object, resulting in a UnprocessableEntityException if that object does not exist.unwrapUserRequestedObject
(@NonNull Class<T> classOfT) Used when a user directly requests an object, resulting in an ObjectNotFoundException if it does not exist.static <T> T
unwrapUserRequestedObject
(@NonNull Optional<T> wrapped, @NonNull Class<T> classOfT) Used when a user directly requests an object, resulting in an ObjectNotFoundException if it does not exist.
-
Method Details
-
unwrapUserRequestedObject
public static <T> T unwrapUserRequestedObject(@NonNull @NonNull Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT) Used when a user directly requests an object, resulting in an ObjectNotFoundException if it does not exist. -
unwrapUserRequestedObject
public static <T> Function<Optional<T>,T> unwrapUserRequestedObject(@NonNull @NonNull Class<T> classOfT) Used when a user directly requests an object, resulting in an ObjectNotFoundException if it does not exist. -
unwrapRequiredObject
public static <T> T unwrapRequiredObject(@NonNull @NonNull Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT) Used when an object can be reasonably expected to exist, resulting in a DataInconsistencyException if it does not exist. -
unwrapRequiredObject
Used when an object can be reasonably expected to exist, resulting in a DataInconsistencyException if it does not exist. -
unwrapUserMentionedObject
public static <T> T unwrapUserMentionedObject(@NonNull @NonNull Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT) Used when a user-submitted entity refers to another object, resulting in a UnprocessableEntityException if that object does not exist. -
unwrapUserMentionedObject
public static <T> Function<Optional<T>,T> unwrapUserMentionedObject(@NonNull @NonNull Class<T> classOfT) Used when a user-submitted entity refers to another object, resulting in a UnprocessableEntityException if that object does not exist. -
streamPresentValue
Used in streams to flat-map eachOptional
to its value if present.
This method is intended to be used as follows:
Using this method is equivalent of chaining.flatMap(Optionals::streamPresentValue)
Optional.isPresent()
andOptional.get()
like this:.filter(Optional::isPresent) .map(Optional::get)
-