Class Optionals


  • public final class Optionals
    extends Object
    • 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(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.
        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(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.
        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.
        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 each Optional to its value if present.

        This method is intended to be used as follows:
        
             .flatMap(Optionals::streamPresentValue)
         
        Using this method is equivalent of chaining Optional.isPresent() and Optional.get() like this:
        
             .filter(Optional::isPresent)
             .map(Optional::get)