Class ArgumentOptional<T>

  • Type Parameters:
    T - argument type

    public final class ArgumentOptional<T>
    extends java.lang.Object
    Represents a optional which contains things for our purpose and that's arguments.
    • Method Detail

      • of

        public static <T> ArgumentOptional<T> of​(@Nullable
                                                 T value,
                                                 @NotNull
                                                 @NotNull FailReason failReason,
                                                 @Nullable
                                                 @Nullable java.lang.String argument,
                                                 @NotNull
                                                 @NotNull CommandExecutionContext commandContext,
                                                 @Nullable
                                                 @Nullable FailReasonHandler failReasonHandler)
        Creates a new argument optional. If the value given is null, the optional will be empty.
        Type Parameters:
        T - argument type
        Parameters:
        value - the value of which you want argument optional
        failReason - the fail reason of why this argument optional would fail
        argument - argument typed. Can be null
        commandContext - command context
        failReasonHandler - default fail reason handler
        Returns:
        argument optional if value not null, empty argument optional else
      • ifPresent

        @NotNull
        @CheckReturnValue
        public @NotNull RestArgumentAction ifPresent​(@NotNull
                                                     @NotNull java.util.function.Consumer<T> action)
        If value is being present, the executor will get executed and the return value will don't come in work, otherwise the return value, a rest argument action will execute its RestArgumentAction.orElse(Consumer) method if it was called.
        Parameters:
        action - executor of the argument
        Returns:
        a rest argument action
      • map

        @NotNull
        public <U> @NotNull ArgumentOptional<U> map​(@NotNull
                                                    @NotNull java.util.function.Function<T,​U> mapper)
        Leads the specified argument to a new argument.
        Type Parameters:
        U - new argument type
        Parameters:
        mapper - mapper for converting the current argument to another
        Returns:
        argument optional with the new argument if present or a empty optional if the value was not present.
      • isPresent

        public boolean isPresent()
        Returns whenever the value is present.
        Returns:
        true if value present, false otherwise
      • getRawArgument

        @Nullable
        public @Nullable java.lang.String getRawArgument()
        Returns the raw argument
        Returns:
        raw argument or null if not present
      • getFailReason

        @NotNull
        public @NotNull FailReason getFailReason()
        Returns the FailReason of why this argument optional may fail.
        Returns:
        fail reason
      • get

        @NotNull
        public T get()
        Gets the specified value if present. If the value is not present, the method will throw a NullPointerException. It is required to use instead ifPresent(Consumer) to access the value, which also provides you handling when the value is not present.
        Returns:
        value if present
        Throws:
        java.lang.NullPointerException - if value not present