Class Opt

java.lang.Object
io.foxcapades.lib.opt.Opt

public class Opt extends Object
Option factory.
  • Constructor Details

    • Opt

      public Opt()
  • Method Details

    • nullable

      @NotNull public static <T> @NotNull NullableOption<T> nullable(@Nullable T value)
      Constructs a new, non-empty option wrapping the given nullable value.

      This method is a static convenience wrapper around the instance method newNullable(Object).

      Type Parameters:
      T - Generic type of the input value and returned option.
      Parameters:
      value - Nullable value to wrap.
      Returns:
      A new, non-empty option wrapping the given value.
    • newNullable

      @NotNull public <T> @NotNull NullableOption<T> newNullable(@Nullable T value)
      Constructs a new, non-empty option wrapping the given nullable value.
      Type Parameters:
      T - Generic type of the input value and returned option.
      Parameters:
      value - Nullable value to wrap.
      Returns:
      A new, non-empty option wrapping the given value.
    • nullable

      @NotNull public static <T> @NotNull NullableOption<T> nullable()
      Constructs a new, empty option.

      This method is a static convenience wrapper around the instance method newNullable().

      Type Parameters:
      T - Generic type of the returned option.
      Returns:
      A new, empty option.
    • newNullable

      @NotNull public <T> @NotNull NullableOption<T> newNullable()
      Constructs a new, empty option.
      Type Parameters:
      T - Generic type of the returned option.
      Returns:
      A new, empty option.
    • newNonNull

      @NotNull public <T> @NotNull NonNullOption<T> newNonNull(@NotNull T value)
      Constructs a new, non-empty option wrapping the given value.
      Type Parameters:
      T - Generic type of the output option, and type of the input value.
      Parameters:
      value - Value to wrap. Must not be null.
      Returns:
      A new, non-empty option wrapping the given value.
      Throws:
      NullPointerException - if the given input value is null.
    • nonNull

      @NotNull public static <T> @NotNull NonNullOption<T> nonNull(@NotNull T value)
      Constructs a new, non-empty option wrapping the given value.

      This method is a static convenience wrapper around the instance method newNonNull(Object).

      Type Parameters:
      T - Generic type of the output option, and type of the input value.
      Parameters:
      value - Value to wrap. Must not be null.
      Returns:
      A new, non-empty option wrapping the given value.
      Throws:
      NullPointerException - if the given input value is null.
    • newNonNull

      @NotNull public <T> @NotNull NonNullOption<T> newNonNull()
      Constructs a new, empty option.
      Type Parameters:
      T - Generic type of the output option.
      Returns:
      A new empty option.
    • nonNull

      public static <T> NonNullOption<T> nonNull()
      Constructs a new, empty option.

      This method is a static convenience wrapper around the instance method newNonNull().

      Type Parameters:
      T - Generic type of the output option.
      Returns:
      A new empty option.
    • newNonNullOfNullable

      @NotNull public <T> @NotNull NonNullOption<T> newNonNullOfNullable(@Nullable T value)
      Constructs a new option that is empty if the given input is null, or wrapping the given value if it is not null.
      Type Parameters:
      T - Generic type of the output option and type of the input value.
      Parameters:
      value - Input value to wrap or null for an empty option.
      Returns:
      An empty option if the input value is null or an option wrapping the given value if it is not null.
    • nonNullOfNullable

      @NotNull public static <T> @NotNull NonNullOption<T> nonNullOfNullable(@Nullable T value)
      Constructs a new option that is empty if the given input is null, or wrapping the given value if it is not null.

      This method is a static convenience wrapper around the instance method newNonNullOfNullable(Object).

      Type Parameters:
      T - Generic type of the output option and type of the input value.
      Parameters:
      value - Input value to wrap or null for an empty option.
      Returns:
      An empty option if the input value is null or an option wrapping the given value if it is not null.
    • standard

      @NotNull public static @NotNull Opt standard()
      Returns the currently set standard/singleton instance that will be used by the static convenience methods.
      Returns:
      The currently set standard/singleton instance of this class.
    • setStandardInstance

      public static void setStandardInstance(@NotNull @NotNull Opt inst)
      Sets the standard/singleton instance that will be used by the static convenience methods.
      Parameters:
      inst - New opt instance to use as the standard implementation.
      Throws:
      NullPointerException - if the input value is null.