Class FullNonNullOption<T>

java.lang.Object
io.foxcapades.lib.opt.impl.FullOption<T,​NonNullOption<T>>
io.foxcapades.lib.opt.impl.FullNonNullOption<T>
Type Parameters:
T - Type of the wrapped value.
All Implemented Interfaces:
NonNullOption<T>, Option<T>

public class FullNonNullOption<T> extends FullOption<T,​NonNullOption<T>> implements NonNullOption<T>
Non-Empty Non-Null Option.

Non singleton implementation of NonNullOption that must wrap a non null value.

  • Constructor Details

    • FullNonNullOption

      public FullNonNullOption(@NotNull T value)
      Constructs a new non-empty option wrapping a non-null value.
      Parameters:
      value - Value to wrap.
      Throws:
      NullPointerException - if the given value is null.
  • Method Details

    • map

      @NotNull public <R> @NotNull NonNullOption<R> map(@NotNull @NotNull Function<? super T,​? extends R> fn)
      Description copied from interface: NonNullOption
      Calls the given Function on the value wrapped by this Option if and only if this Option is not empty.

      IMPORTANT: Implementations of this interface do not allow wrapping null values.

      If the given function returns null an empty Option will be returned. If the given function does not return null a new Option will be returned wrapping the result value of the call to the given Function.

      Specified by:
      map in interface NonNullOption<T>
      Specified by:
      map in interface Option<T>
      Type Parameters:
      R - The return type of the given mapping Function.
      Parameters:
      fn - Function to call on the value wrapped by this Option.

      This argument must not be null

      Returns:
      A new Option of generic type R. This Option will be empty if the return value of fn was null, otherwise the returned Option will be wrapping the value returned by the given Function.
    • map

      @NotNull public <R> @NotNull NonNullOption<R> map(@NotNull @NotNull Function<? super T,​? extends R> ifPresent, @NotNull @NotNull Supplier<? extends R> ignored)
      Description copied from interface: NonNullOption
      Calls the given Function ifPresent if this Option is not empty, otherwise calls the given Supplier ifEmpty.

      IMPORTANT: Implementations of this interface do not allow wrapping null values.

      Specified by:
      map in interface NonNullOption<T>
      Specified by:
      map in interface Option<T>
      Type Parameters:
      R - Generic type of the returned Option.
      Parameters:
      ifPresent - Mapping function to call on the value wrapped by this Option.

      This argument must not be null.

      This function will only be called if this Option is not empty.

      ignored - Value supplier to call when this Option is empty.

      This argument must not be null.

      Returns:
      A new Option of generic type R.
    • filter

      @NotNull public @NotNull NonNullOption<T> filter(@NotNull @NotNull Predicate<? super T> fn)
      Description copied from interface: NonNullOption
      Calls the given Predicate on the value wrapped by this Option, if this Option is not empty.

      IMPORTANT: Implementations of this interface do not allow wrapping null values.

      Specified by:
      filter in interface NonNullOption<T>
      Specified by:
      filter in interface Option<T>
      Parameters:
      fn - Predicate to apply to the value wrapped by this Option if this Option is not empty.

      This value must not be null.

      Returns:
      This Option if the given Predicate returns true, otherwise an empty Option.
    • toNullable

      @NotNull public @NotNull NullableOption<T> toNullable()
      Description copied from interface: NonNullOption
      Converts this NonNullOption into an instance of NullableOption.

      If the current Option is empty, the returned Option will also be empty.

      This method is equivalent to calling toNullable(false).

      Specified by:
      toNullable in interface NonNullOption<T>
      Returns:
      A NullableOption that is either empty or wrapping the same value as this Option.
    • toNullable

      @NotNull public @NotNull NullableOption<T> toNullable(boolean emptyToNull)
      Description copied from interface: NonNullOption
      Converts this NonNullOption into an instance of NullableOption.

      If the current option is not empty, the returned Option will wrap the same value as this Option.

      If the current option is empty, either a new NullableOption wrapping null or an empty Option will be returned depending on the value of emptyToNull.

      If emptyToNull == true && this.isEmpty(), then a NullableOption that is not-empty, wrapping the value null will be returned.

      If emptyToNull == false && this.isEmpty(), then an empty option will be returned.

      Specified by:
      toNullable in interface NonNullOption<T>
      Parameters:
      emptyToNull - Flag indicating whether an empty option instance should be converted to a null wrapping option or an empty option.
      Returns:
      A new option that will be wrapping this option's value, null, or will be empty.