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> TunwrapRequiredObject(@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.static <T> TunwrapRequiredObject(com.google.common.base.Optional<T> wrapped, @NonNull Class<T> classOfT) Deprecated, for removal: This API element is subject to removal in a future version.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> TunwrapUserMentionedObject(@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.static <T> TunwrapUserMentionedObject(com.google.common.base.Optional<T> wrapped, @NonNull Class<T> classOfT) Deprecated, for removal: This API element is subject to removal in a future version.UseunwrapUserMentionedObject(Optional, Class)instead.unwrapUserRequestedObject(@NonNull Class<T> classOfT) Used when a user directly requests an object, resulting in an ObjectNotFoundException if it does not exist.static <T> TunwrapUserRequestedObject(@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.static <T> TunwrapUserRequestedObject(com.google.common.base.Optional<T> wrapped, @NonNull Class<T> classOfT) Deprecated, for removal: This API element is subject to removal in a future version.UseunwrapUserRequestedObject(Optional, Class)instead.
-
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. -
unwrapUserRequestedObject
@Deprecated(forRemoval=true) public static <T> T unwrapUserRequestedObject(@NonNull com.google.common.base.Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT) Deprecated, for removal: This API element is subject to removal in a future version.UseunwrapUserRequestedObject(Optional, Class)instead.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. -
unwrapRequiredObject
@Deprecated(forRemoval=true) public static <T> T unwrapRequiredObject(@NonNull com.google.common.base.Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT) Deprecated, for removal: This API element is subject to removal in a future version.UseunwrapRequiredObject(Optional, Class)instead.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. -
unwrapUserMentionedObject
@Deprecated(forRemoval=true) public static <T> T unwrapUserMentionedObject(@NonNull com.google.common.base.Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT) Deprecated, for removal: This API element is subject to removal in a future version.UseunwrapUserMentionedObject(Optional, Class)instead.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 eachOptionalto 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)
-
unwrapRequiredObject(Optional, Class)instead.