Move ArgumentMapper inside ArgumentMap

This commit is contained in:
LeoDog896 2021-04-09 12:54:02 -04:00
parent e4c3345da7
commit ca6ee7c23a
3 changed files with 25 additions and 28 deletions

View File

@ -1,26 +0,0 @@
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

@ -226,7 +226,7 @@ public abstract class Argument<T> {
* @return A new ArgumentMap that can get this complex object type.
*/
@Beta
public <O> ArgumentMap<T, O> map(ArgumentMapper<T, O> mapper) {
public <O> ArgumentMap<T, O> map(ArgumentMap.ArgumentMapper<T, O> mapper) {
return new ArgumentMap<>(this, mapper);
}

View File

@ -1,6 +1,5 @@
package net.minestom.server.command.builder.arguments;
import net.minestom.server.command.builder.ArgumentMapper;
import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import org.jetbrains.annotations.NotNull;
@ -32,4 +31,28 @@ public class ArgumentMap<I, O> extends Argument<O> {
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
argument.processNodes(nodeMaker, executable);
}
/**
* 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;
}
}