Package com.mrivanplays.jdcf.args
Class ArgumentOptional<T>
- java.lang.Object
-
- com.mrivanplays.jdcf.args.ArgumentOptional<T>
-
- Type Parameters:
T- argument type
public final class ArgumentOptional<T> extends java.lang.ObjectRepresents a optional which contains things for our purpose and that's arguments.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget()Gets the specified value if present.@NotNull FailReasongetFailReason()Returns theFailReasonof why this argument optional may fail.@Nullable java.lang.StringgetRawArgument()Returns the raw argument@NotNull RestArgumentActionifPresent(@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 itsRestArgumentAction.orElse(Consumer)method if it was called.booleanisPresent()Returns whenever the value is present.<U> @NotNull ArgumentOptional<U>map(@NotNull java.util.function.Function<T,U> mapper)Leads the specified argument to a new argument.static <T> ArgumentOptional<T>of(T value, @NotNull FailReason failReason, @Nullable java.lang.String argument, @NotNull CommandExecutionContext commandContext, @Nullable FailReasonHandler failReasonHandler)Creates a new argument optional.
-
-
-
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 optionalfailReason- the fail reason of why this argument optional would failargument- argument typed. Can be nullcommandContext- command contextfailReasonHandler- 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 itsRestArgumentAction.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:
trueif value present,falseotherwise
-
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 theFailReasonof 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 aNullPointerException. It is required to use insteadifPresent(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
-
-