Documentation and visibility changes

This commit is contained in:
LeoDog896 2021-04-06 22:12:30 -04:00
parent 0e4168ba45
commit dfae6ad5f8
3 changed files with 27 additions and 2 deletions

View File

@ -2,9 +2,25 @@ package net.minestom.server.command.builder;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
/**
* Represents a lambda that can turn an input into an output
* that also allows the throwing of ArgumentSyntaxException
*
* @param <I> The input expected from the Argument
* @param <O> The desired output type from this lambda.
*/
@FunctionalInterface
public interface ArgumentMapper<I, O> {
/**
* Accept's I data from the argument and returns O output
*
* @param i The input processed from an argument
*
* @return The complex data type that came as a result from this argument
* @throws ArgumentSyntaxException If the input can not be turned into the desired output
* (E.X. an invalid extension name)
*/
O accept(I i) throws ArgumentSyntaxException;
}

View File

@ -217,6 +217,14 @@ public abstract class Argument<T> {
return suggestionCallback != null;
}
/**
* Maps this argument's output to another result.
*
* @param mapper The mapper to use (this argument's input --> desired output)
* @param <O> The type of output expected.
*
* @return A new ArgumentMap that can get this complex object type.
*/
public <O> ArgumentMap<T, O> map(ArgumentMapper<T, O> mapper) {
return new ArgumentMap<>(this, mapper);
}

View File

@ -6,7 +6,8 @@ import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import org.jetbrains.annotations.NotNull;
/**
* Represents an argument that maps an existing argument to a vlaue.
* Represents an argument that maps an existing argument to a value.
*
* @param <I> The input (any object)
* @param <O> The output (any object)
*/
@ -15,7 +16,7 @@ public class ArgumentMap<I, O> extends Argument<O> {
final Argument<I> argument;
final ArgumentMapper<I, O> mapper;
public ArgumentMap(Argument<I> argument, ArgumentMapper<I, O> mapper) {
protected ArgumentMap(Argument<I> argument, ArgumentMapper<I, O> mapper) {
super(argument.getId());
this.argument = argument;