Class FullNullableOption<T>

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

public class FullNullableOption<T> extends FullOption<T,​NullableOption<T>> implements NullableOption<T>
Non-Empty Nullable Option

Non-singleton implementation of NullableOption that must wrap a value which may be null.

  • Constructor Details

    • FullNullableOption

      public FullNullableOption(@Nullable T value)
      Constructs a new option instance wrapping the given nullable value.
      Parameters:
      value - Value to wrap.
  • Method Details

    • isNull

      public boolean isNull()
      Description copied from interface: NullableOption
      Tests whether the wrapped value is null.

      A return value of true means that this Option is not empty and the value it wraps is null.

      A return value of false may mean either that this Option is empty, or that the wrapped value is not null. To test if this is the case, NullableOption.isPresent() and/or NullableOption.isEmpty() should be used.

      Specified by:
      isNull in interface NullableOption<T>
      Returns:
      true if this Option is both non-empty and is wrapping a null value. false if this option is empty, or is not wrapping a null value.
    • map

      @NotNull public <R> @NotNull NullableOption<R> map(@NotNull @NotNull Function<? super T,​? extends R> fn)
      Description copied from interface: NullableOption
      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 allow wrapping null values. This means the given Function should be prepared to accept null values.

      The given Function may null.

      Specified by:
      map in interface NullableOption<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.
    • map

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

      IMPORTANT: Implementations of this interface allow wrapping null values. This means, if this Option is wrapping a null value, it will call the Function ifPresent, passing in the wrapped null value. In this case, ifEmpty will not be called.

      The passed Function ifPresent may return null, and should be prepared to accept a null input.

      If the called input function returns null, the output Option will be non-empty, wrapping a null value.

      Specified by:
      map in interface NullableOption<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 NullableOption<T> filter(@NotNull @NotNull Predicate<? super T> fn)
      Description copied from interface: NullableOption
      Calls the given Predicate on the value wrapped by this Option, if this Option is not empty.

      The given Predicate will not be called if this Option is empty.

      If the given Predicate returns true, this Option will be returned, otherwise an empty Option will be returned.

      IMPORTANT: Implementations of this interface allow wrapping null values. This means Predicate will be called if the Option is wrapping a null value, and will be passed the wrapped null.

      The given Predicate should be prepared to handle a null input value.

      Specified by:
      filter in interface NullableOption<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.
    • toNonNullable

      @NotNull public @NotNull NonNullOption<T> toNonNullable()
      Description copied from interface: NullableOption
      Converts this Option to a NonNullOption.

      The conversion happens as follows:

      Option conversion rules.
      This Value Returns
      Not-null Non-empty Option wrapping this Option's value.
      null Empty Option
      empty Empty Option
      Specified by:
      toNonNullable in interface NullableOption<T>
      Returns:
      A new NonNullOption which may be empty or non-empty based on the rules detailed above.