Package com.github.mizool.core
Class Optionals
- java.lang.Object
-
- com.github.mizool.core.Optionals
-
public final class Optionals extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> Stream<T>streamPresentValue(@NonNull Optional<T> optional)static <T> Function<Optional<T>,T>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.UseunwrapRequiredObject(Optional, Class)instead.static <T> Function<Optional<T>,T>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.UseunwrapUserMentionedObject(Optional, Class)instead.static <T> Function<Optional<T>,T>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.UseunwrapUserRequestedObject(Optional, Class)instead.
-
-
-
Method Detail
-
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 public static <T> T unwrapUserRequestedObject(@NonNull com.google.common.base.Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT)
Deprecated.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
public static <T> Function<Optional<T>,T> unwrapRequiredObject(@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
@Deprecated public static <T> T unwrapRequiredObject(@NonNull com.google.common.base.Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT)
Deprecated.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 public static <T> T unwrapUserMentionedObject(@NonNull com.google.common.base.Optional<T> wrapped, @NonNull @NonNull Class<T> classOfT)
Deprecated.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
public static <T> Stream<T> streamPresentValue(@NonNull @NonNull Optional<T> optional)
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)
-
-