🚚 Begin migrating from javax annotations to checker-qual
This commit is contained in:
parent
e914d04450
commit
9f0c846050
43 changed files with 273 additions and 549 deletions
|
|
@ -100,7 +100,7 @@ subprojects {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
api 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
compileOnly 'org.checkerframework:checker-qual:3.5.0'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ import cloud.commandframework.permission.Permission;
|
|||
import cloud.commandframework.types.tuples.Pair;
|
||||
import cloud.commandframework.types.tuples.Triplet;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
|
|
@ -55,11 +55,11 @@ import java.util.function.Function;
|
|||
*/
|
||||
public class Command<C> {
|
||||
|
||||
@Nonnull private final Map<CommandArgument<C, ?>, Description> arguments;
|
||||
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||
@Nullable private final Class<? extends C> senderType;
|
||||
@Nonnull private final CommandPermission commandPermission;
|
||||
@Nonnull private final CommandMeta commandMeta;
|
||||
private final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> arguments;
|
||||
private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||
private final Class<? extends C> senderType;
|
||||
private final CommandPermission commandPermission;
|
||||
private final CommandMeta commandMeta;
|
||||
|
||||
/**
|
||||
* Construct a new command
|
||||
|
|
@ -70,11 +70,11 @@ public class Command<C> {
|
|||
* @param commandPermission Command permission
|
||||
* @param commandMeta Command meta instance
|
||||
*/
|
||||
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments,
|
||||
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
||||
public Command(@NonNull final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
|
||||
@NonNull final CommandExecutionHandler<@NonNull C> commandExecutionHandler,
|
||||
@Nullable final Class<? extends C> senderType,
|
||||
@Nonnull final CommandPermission commandPermission,
|
||||
@Nonnull final CommandMeta commandMeta) {
|
||||
@NonNull final CommandPermission commandPermission,
|
||||
@NonNull final CommandMeta commandMeta) {
|
||||
this.arguments = Objects.requireNonNull(commandArguments, "Command arguments may not be null");
|
||||
if (this.arguments.size() == 0) {
|
||||
throw new IllegalArgumentException("At least one command argument is required");
|
||||
|
|
@ -107,10 +107,10 @@ public class Command<C> {
|
|||
* @param senderType Required sender type. May be {@code null}
|
||||
* @param commandMeta Command meta instance
|
||||
*/
|
||||
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments,
|
||||
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
||||
public Command(@NonNull final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
|
||||
@NonNull final CommandExecutionHandler<@NonNull C> commandExecutionHandler,
|
||||
@Nullable final Class<? extends C> senderType,
|
||||
@Nonnull final CommandMeta commandMeta) {
|
||||
@NonNull final CommandMeta commandMeta) {
|
||||
this(commandArguments, commandExecutionHandler, senderType, Permission.empty(), commandMeta);
|
||||
}
|
||||
|
||||
|
|
@ -122,10 +122,10 @@ public class Command<C> {
|
|||
* @param commandPermission Command permission
|
||||
* @param commandMeta Command meta instance
|
||||
*/
|
||||
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments,
|
||||
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
||||
@Nonnull final CommandPermission commandPermission,
|
||||
@Nonnull final CommandMeta commandMeta) {
|
||||
public Command(@NonNull final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
|
||||
@NonNull final CommandExecutionHandler<@NonNull C> commandExecutionHandler,
|
||||
@NonNull final CommandPermission commandPermission,
|
||||
@NonNull final CommandMeta commandMeta) {
|
||||
this(commandArguments, commandExecutionHandler, null, commandPermission, commandMeta);
|
||||
}
|
||||
|
||||
|
|
@ -140,12 +140,11 @@ public class Command<C> {
|
|||
* @param <C> Command sender type
|
||||
* @return Command builder
|
||||
*/
|
||||
@Nonnull
|
||||
public static <C> Builder<C> newBuilder(@Nonnull final String commandName,
|
||||
@Nonnull final CommandMeta commandMeta,
|
||||
@Nonnull final Description description,
|
||||
@Nonnull final String... aliases) {
|
||||
final Map<CommandArgument<C, ?>, Description> map = new LinkedHashMap<>();
|
||||
public static <C> @NonNull Builder<C> newBuilder(@NonNull final String commandName,
|
||||
@NonNull final CommandMeta commandMeta,
|
||||
@NonNull final Description description,
|
||||
@NonNull final String... aliases) {
|
||||
final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> map = new LinkedHashMap<>();
|
||||
map.put(StaticArgument.required(commandName, aliases), description);
|
||||
return new Builder<>(null, commandMeta, null, map,
|
||||
new CommandExecutionHandler.NullCommandExecutionHandler<>(), Permission.empty());
|
||||
|
|
@ -161,10 +160,9 @@ public class Command<C> {
|
|||
* @param <C> Command sender type
|
||||
* @return Command builder
|
||||
*/
|
||||
@Nonnull
|
||||
public static <C> Builder<C> newBuilder(@Nonnull final String commandName,
|
||||
@Nonnull final CommandMeta commandMeta,
|
||||
@Nonnull final String... aliases) {
|
||||
public static <C> @NonNull Builder<C> newBuilder(@NonNull final String commandName,
|
||||
@NonNull final CommandMeta commandMeta,
|
||||
@NonNull final String... aliases) {
|
||||
final Map<CommandArgument<C, ?>, Description> map = new LinkedHashMap<>();
|
||||
map.put(StaticArgument.required(commandName, aliases), Description.empty());
|
||||
return new Builder<>(null, commandMeta, null, map,
|
||||
|
|
@ -176,8 +174,7 @@ public class Command<C> {
|
|||
*
|
||||
* @return Copy of the command argument array
|
||||
*/
|
||||
@Nonnull
|
||||
public List<CommandArgument<C, ?>> getArguments() {
|
||||
public @NonNull List<CommandArgument<@NonNull C, @NonNull ?>> getArguments() {
|
||||
return new ArrayList<>(this.arguments.keySet());
|
||||
}
|
||||
|
||||
|
|
@ -186,8 +183,7 @@ public class Command<C> {
|
|||
*
|
||||
* @return Command execution handler
|
||||
*/
|
||||
@Nonnull
|
||||
public CommandExecutionHandler<C> getCommandExecutionHandler() {
|
||||
public CommandExecutionHandler<@NonNull C> getCommandExecutionHandler() {
|
||||
return this.commandExecutionHandler;
|
||||
}
|
||||
|
||||
|
|
@ -196,8 +192,7 @@ public class Command<C> {
|
|||
*
|
||||
* @return Required sender type
|
||||
*/
|
||||
@Nonnull
|
||||
public Optional<Class<? extends C>> getSenderType() {
|
||||
public @NonNull Optional<Class<? extends C>> getSenderType() {
|
||||
return Optional.ofNullable(this.senderType);
|
||||
}
|
||||
|
||||
|
|
@ -206,8 +201,7 @@ public class Command<C> {
|
|||
*
|
||||
* @return Command permission
|
||||
*/
|
||||
@Nonnull
|
||||
public CommandPermission getCommandPermission() {
|
||||
public @NonNull CommandPermission getCommandPermission() {
|
||||
return this.commandPermission;
|
||||
}
|
||||
|
||||
|
|
@ -216,8 +210,7 @@ public class Command<C> {
|
|||
*
|
||||
* @return Command meta
|
||||
*/
|
||||
@Nonnull
|
||||
public CommandMeta getCommandMeta() {
|
||||
public @NonNull CommandMeta getCommandMeta() {
|
||||
return this.commandMeta;
|
||||
}
|
||||
|
||||
|
|
@ -227,8 +220,7 @@ public class Command<C> {
|
|||
* @param argument Argument
|
||||
* @return Argument description
|
||||
*/
|
||||
@Nonnull
|
||||
public String getArgumentDescription(@Nonnull final CommandArgument<C, ?> argument) {
|
||||
public @NonNull String getArgumentDescription(@NonNull final CommandArgument<C, ?> argument) {
|
||||
return this.arguments.get(argument).getDescription();
|
||||
}
|
||||
|
||||
|
|
@ -260,19 +252,19 @@ public class Command<C> {
|
|||
*/
|
||||
public static final class Builder<C> {
|
||||
|
||||
@Nonnull private final CommandMeta commandMeta;
|
||||
@Nonnull private final Map<CommandArgument<C, ?>, Description> commandArguments;
|
||||
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||
@Nullable private final Class<? extends C> senderType;
|
||||
@Nonnull private final CommandPermission commandPermission;
|
||||
@Nullable private final CommandManager<C> commandManager;
|
||||
private final CommandMeta commandMeta;
|
||||
private final Map<CommandArgument<C, ?>, Description> commandArguments;
|
||||
private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||
private final Class<? extends C> senderType;
|
||||
private final CommandPermission commandPermission;
|
||||
private final CommandManager<C> commandManager;
|
||||
|
||||
private Builder(@Nullable final CommandManager<C> commandManager,
|
||||
@Nonnull final CommandMeta commandMeta,
|
||||
@NonNull final CommandMeta commandMeta,
|
||||
@Nullable final Class<? extends C> senderType,
|
||||
@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments,
|
||||
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
||||
@Nonnull final CommandPermission commandPermission) {
|
||||
@NonNull final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
|
||||
@NonNull final CommandExecutionHandler<@NonNull C> commandExecutionHandler,
|
||||
@NonNull final CommandPermission commandPermission) {
|
||||
this.commandManager = commandManager;
|
||||
this.senderType = senderType;
|
||||
this.commandArguments = Objects.requireNonNull(commandArguments, "Arguments may not be null");
|
||||
|
|
@ -288,8 +280,7 @@ public class Command<C> {
|
|||
* @param value Meta value
|
||||
* @return New builder instance using the inserted meta key-value pair
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> meta(@Nonnull final String key, @Nonnull final String value) {
|
||||
public @NonNull Builder<C> meta(@NonNull final String key, @NonNull final String value) {
|
||||
final CommandMeta commandMeta = SimpleCommandMeta.builder().with(this.commandMeta).with(key, value).build();
|
||||
return new Builder<>(this.commandManager, commandMeta, this.senderType, this.commandArguments,
|
||||
this.commandExecutionHandler, this.commandPermission);
|
||||
|
|
@ -303,8 +294,7 @@ public class Command<C> {
|
|||
* @param commandManager Command manager
|
||||
* @return New builder instance using the provided command manager
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> manager(@Nullable final CommandManager<C> commandManager) {
|
||||
public @NonNull Builder<C> manager(@Nullable final CommandManager<C> commandManager) {
|
||||
return new Builder<>(commandManager, this.commandMeta, this.senderType, this.commandArguments,
|
||||
this.commandExecutionHandler, this.commandPermission);
|
||||
}
|
||||
|
|
@ -316,8 +306,8 @@ public class Command<C> {
|
|||
* @param aliases Argument aliases
|
||||
* @return New builder instance with the modified command chain
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> literal(@Nonnull final String main, @Nonnull final String... aliases) {
|
||||
public @NonNull Builder<C> literal(@NonNull final String main,
|
||||
@NonNull final String... aliases) {
|
||||
return this.argument(StaticArgument.required(main, aliases));
|
||||
}
|
||||
|
||||
|
|
@ -329,10 +319,9 @@ public class Command<C> {
|
|||
* @param aliases Argument aliases
|
||||
* @return New builder instance with the modified command chain
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> literal(@Nonnull final String main,
|
||||
@Nonnull final Description description,
|
||||
@Nonnull final String... aliases) {
|
||||
public @NonNull Builder<C> literal(@NonNull final String main,
|
||||
@NonNull final Description description,
|
||||
@NonNull final String... aliases) {
|
||||
return this.argument(StaticArgument.required(main, aliases), description);
|
||||
}
|
||||
|
||||
|
|
@ -343,8 +332,7 @@ public class Command<C> {
|
|||
* @param <T> Argument type
|
||||
* @return New builder instance with the command argument inserted into the argument list
|
||||
*/
|
||||
@Nonnull
|
||||
public <T> Builder<C> argument(@Nonnull final CommandArgument<C, T> argument) {
|
||||
public <T> @NonNull Builder<C> argument(@NonNull final CommandArgument<C, T> argument) {
|
||||
return this.argument(argument, Description.empty());
|
||||
}
|
||||
|
||||
|
|
@ -356,9 +344,8 @@ public class Command<C> {
|
|||
* @param <T> Argument type
|
||||
* @return New builder instance with the command argument inserted into the argument list
|
||||
*/
|
||||
@Nonnull
|
||||
public <T> Builder<C> argument(@Nonnull final CommandArgument<C, T> argument,
|
||||
@Nonnull final Description description) {
|
||||
public <T> @NonNull Builder<C> argument(@NonNull final CommandArgument<C, T> argument,
|
||||
@NonNull final Description description) {
|
||||
final Map<CommandArgument<C, ?>, Description> commandArgumentMap = new LinkedHashMap<>(this.commandArguments);
|
||||
commandArgumentMap.put(argument, description);
|
||||
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandArgumentMap,
|
||||
|
|
@ -374,10 +361,9 @@ public class Command<C> {
|
|||
* @param <T> Argument type
|
||||
* @return New builder instance with the command argument inserted into the argument list
|
||||
*/
|
||||
@Nonnull
|
||||
public <T> Builder<C> argument(@Nonnull final Class<T> clazz,
|
||||
@Nonnull final String name,
|
||||
@Nonnull final Consumer<CommandArgument.Builder<C, T>> builderConsumer) {
|
||||
public <T> @NonNull Builder<C> argument(@NonNull final Class<T> clazz,
|
||||
@NonNull final String name,
|
||||
@NonNull final Consumer<CommandArgument.Builder<C, T>> builderConsumer) {
|
||||
final CommandArgument.Builder<C, T> builder = CommandArgument.ofType(clazz, name);
|
||||
if (this.commandManager != null) {
|
||||
builder.manager(this.commandManager);
|
||||
|
|
@ -524,8 +510,7 @@ public class Command<C> {
|
|||
* @param commandExecutionHandler New execution handler
|
||||
* @return New builder instance using the command execution handler
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> handler(@Nonnull final CommandExecutionHandler<C> commandExecutionHandler) {
|
||||
public @NonNull Builder<C> handler(@NonNull final CommandExecutionHandler<C> commandExecutionHandler) {
|
||||
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments,
|
||||
commandExecutionHandler, this.commandPermission);
|
||||
}
|
||||
|
|
@ -536,8 +521,7 @@ public class Command<C> {
|
|||
* @param senderType Required sender type
|
||||
* @return New builder instance using the command execution handler
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> withSenderType(@Nonnull final Class<? extends C> senderType) {
|
||||
public @NonNull Builder<C> withSenderType(@NonNull final Class<? extends C> senderType) {
|
||||
return new Builder<>(this.commandManager, this.commandMeta, senderType, this.commandArguments,
|
||||
this.commandExecutionHandler, this.commandPermission);
|
||||
}
|
||||
|
|
@ -548,8 +532,7 @@ public class Command<C> {
|
|||
* @param permission Command permission
|
||||
* @return New builder instance using the command permission
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> withPermission(@Nonnull final CommandPermission permission) {
|
||||
public @NonNull Builder<C> withPermission(@NonNull final CommandPermission permission) {
|
||||
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments,
|
||||
this.commandExecutionHandler, permission);
|
||||
}
|
||||
|
|
@ -560,8 +543,7 @@ public class Command<C> {
|
|||
* @param permission Command permission
|
||||
* @return New builder instance using the command permission
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> withPermission(@Nonnull final String permission) {
|
||||
public @NonNull Builder<C> withPermission(@NonNull final String permission) {
|
||||
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments,
|
||||
this.commandExecutionHandler, Permission.of(permission));
|
||||
}
|
||||
|
|
@ -577,8 +559,7 @@ public class Command<C> {
|
|||
* @param command Command to proxy
|
||||
* @return New builder that proxies the given command
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> proxies(@Nonnull final Command<C> command) {
|
||||
public @NonNull Builder<C> proxies(@NonNull final Command<C> command) {
|
||||
Builder<C> builder = this;
|
||||
for (final CommandArgument<C, ?> argument : command.getArguments()) {
|
||||
if (argument instanceof StaticArgument) {
|
||||
|
|
@ -599,8 +580,7 @@ public class Command<C> {
|
|||
*
|
||||
* @return New builder instance that indicates that the constructed command should be hidden
|
||||
*/
|
||||
@Nonnull
|
||||
public Builder<C> hidden() {
|
||||
public @NonNull Builder<C> hidden() {
|
||||
return this.meta("hidden", "true");
|
||||
}
|
||||
|
||||
|
|
@ -609,8 +589,7 @@ public class Command<C> {
|
|||
*
|
||||
* @return Built command
|
||||
*/
|
||||
@Nonnull
|
||||
public Command<C> build() {
|
||||
public @NonNull Command<C> build() {
|
||||
return new Command<>(Collections.unmodifiableMap(this.commandArguments),
|
||||
this.commandExecutionHandler,
|
||||
this.senderType,
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
|||
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
//
|
||||
package cloud.commandframework.execution.postprocessor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* {@link CommandPostprocessor} that does nothing besides indicating that the context
|
||||
|
|
@ -39,7 +39,7 @@ public final class AcceptingCommandPostprocessor<C> implements CommandPostproces
|
|||
public static final String PROCESSED_INDICATOR_KEY = "__COMMAND_POST_PROCESSED__";
|
||||
|
||||
@Override
|
||||
public void accept(@Nonnull final CommandPostprocessingContext<C> context) {
|
||||
public void accept(@NonNull final CommandPostprocessingContext<C> context) {
|
||||
context.getCommandContext().store(PROCESSED_INDICATOR_KEY, "true");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ package cloud.commandframework.execution.postprocessor;
|
|||
|
||||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
|
@ -36,8 +36,8 @@ import java.util.Objects;
|
|||
*/
|
||||
public final class CommandPostprocessingContext<C> {
|
||||
|
||||
private final CommandContext<C> commandContext;
|
||||
private final Command<C> command;
|
||||
private final CommandContext<@NonNull C> commandContext;
|
||||
private final Command<@NonNull C> command;
|
||||
|
||||
/**
|
||||
* Construct a new command postprocessing context
|
||||
|
|
@ -45,8 +45,8 @@ public final class CommandPostprocessingContext<C> {
|
|||
* @param commandContext Command context
|
||||
* @param command Command instance
|
||||
*/
|
||||
public CommandPostprocessingContext(@Nonnull final CommandContext<C> commandContext,
|
||||
@Nonnull final Command<C> command) {
|
||||
public CommandPostprocessingContext(@NonNull final CommandContext<@NonNull C> commandContext,
|
||||
@NonNull final Command<@NonNull C> command) {
|
||||
this.commandContext = commandContext;
|
||||
this.command = command;
|
||||
}
|
||||
|
|
@ -56,8 +56,7 @@ public final class CommandPostprocessingContext<C> {
|
|||
*
|
||||
* @return Command context
|
||||
*/
|
||||
@Nonnull
|
||||
public CommandContext<C> getCommandContext() {
|
||||
public @NonNull CommandContext<@NonNull C> getCommandContext() {
|
||||
return this.commandContext;
|
||||
}
|
||||
|
||||
|
|
@ -66,8 +65,7 @@ public final class CommandPostprocessingContext<C> {
|
|||
*
|
||||
* @return Command instance
|
||||
*/
|
||||
@Nonnull
|
||||
public Command<C> getCommand() {
|
||||
public @NonNull Command<@NonNull C> getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@
|
|||
package cloud.commandframework.internal;
|
||||
|
||||
import cloud.commandframework.Command;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Utility that registers commands natively for whatever
|
||||
|
|
@ -40,8 +39,7 @@ public interface CommandRegistrationHandler {
|
|||
*
|
||||
* @return Constructed registration
|
||||
*/
|
||||
@Nonnull
|
||||
static CommandRegistrationHandler nullCommandRegistrationHandler() {
|
||||
static @NonNull CommandRegistrationHandler nullCommandRegistrationHandler() {
|
||||
return new NullCommandRegistrationHandler();
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +50,7 @@ public interface CommandRegistrationHandler {
|
|||
* @return {@code true} if the command was registered successfully,
|
||||
* else {@code false}
|
||||
*/
|
||||
boolean registerCommand(@Nonnull Command<?> command);
|
||||
boolean registerCommand(@NonNull Command<?> command);
|
||||
|
||||
final class NullCommandRegistrationHandler implements CommandRegistrationHandler {
|
||||
|
||||
|
|
@ -60,7 +58,7 @@ public interface CommandRegistrationHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean registerCommand(@Nonnull final Command<?> command) {
|
||||
public boolean registerCommand(@NonNull final Command<?> command) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.permission;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
|
|
@ -36,8 +37,7 @@ public interface CommandPermission {
|
|||
*
|
||||
* @return Permission nodes
|
||||
*/
|
||||
@Nonnull
|
||||
Collection<CommandPermission> getPermissions();
|
||||
@NonNull Collection<@NonNull CommandPermission> getPermissions();
|
||||
|
||||
/**
|
||||
* Get a string representation of the permission
|
||||
|
|
@ -45,7 +45,6 @@ public interface CommandPermission {
|
|||
* @return String representation of the permission node
|
||||
*/
|
||||
@Override
|
||||
@Nonnull
|
||||
String toString();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.permission;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
|
@ -37,7 +38,7 @@ public final class OrPermission implements CommandPermission {
|
|||
|
||||
private final Collection<CommandPermission> permissions;
|
||||
|
||||
private OrPermission(@Nonnull final Collection<CommandPermission> permissions) {
|
||||
private OrPermission(@NonNull final Collection<CommandPermission> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
|
|
@ -47,8 +48,7 @@ public final class OrPermission implements CommandPermission {
|
|||
* @param permissions Permissions to join
|
||||
* @return Constructed permission
|
||||
*/
|
||||
@Nonnull
|
||||
public static CommandPermission of(@Nonnull final Collection<CommandPermission> permissions) {
|
||||
public static @NonNull CommandPermission of(@NonNull final Collection<CommandPermission> permissions) {
|
||||
final Set<CommandPermission> permissionSet = new HashSet<>();
|
||||
for (final CommandPermission permission : permissions) {
|
||||
permissionSet.addAll(permission.getPermissions());
|
||||
|
|
@ -56,9 +56,8 @@ public final class OrPermission implements CommandPermission {
|
|||
return new OrPermission(permissionSet);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<CommandPermission> getPermissions() {
|
||||
public @NonNull Collection<@NonNull CommandPermission> getPermissions() {
|
||||
return this.permissions;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.permission;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
|
@ -40,7 +41,7 @@ public final class Permission implements CommandPermission {
|
|||
|
||||
private final String permission;
|
||||
|
||||
private Permission(@Nonnull final String permission) {
|
||||
private Permission(@NonNull final String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
|
|
@ -49,8 +50,7 @@ public final class Permission implements CommandPermission {
|
|||
*
|
||||
* @return Command permission
|
||||
*/
|
||||
@Nonnull
|
||||
public static Permission empty() {
|
||||
public static @NonNull Permission empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
|
|
@ -60,8 +60,7 @@ public final class Permission implements CommandPermission {
|
|||
* @param string Command permission
|
||||
* @return Created command permission
|
||||
*/
|
||||
@Nonnull
|
||||
public static Permission of(@Nonnull final String string) {
|
||||
public static @NonNull Permission of(@NonNull final String string) {
|
||||
return new Permission(string);
|
||||
}
|
||||
|
||||
|
|
@ -70,14 +69,12 @@ public final class Permission implements CommandPermission {
|
|||
*
|
||||
* @return Command permission
|
||||
*/
|
||||
@Nonnull
|
||||
public String getPermission() {
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<CommandPermission> getPermissions() {
|
||||
public @NonNull Collection<@NonNull CommandPermission> getPermissions() {
|
||||
return Collections.singleton(this);
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +83,6 @@ public final class Permission implements CommandPermission {
|
|||
*
|
||||
* @return Command permission
|
||||
*/
|
||||
@Nonnull
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.permission;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.types.tuples;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
|
@ -34,13 +35,11 @@ import java.util.Objects;
|
|||
*/
|
||||
public class Pair<U, V> implements Tuple {
|
||||
|
||||
@Nonnull
|
||||
private final U first;
|
||||
@Nonnull
|
||||
private final V second;
|
||||
|
||||
protected Pair(@Nonnull final U first,
|
||||
@Nonnull final V second) {
|
||||
protected Pair(@NonNull final U first,
|
||||
@NonNull final V second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
|
@ -54,9 +53,8 @@ public class Pair<U, V> implements Tuple {
|
|||
* @param <V> Second type
|
||||
* @return Created pair
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V> Pair<U, V> of(@Nonnull final U first,
|
||||
@Nonnull final V second) {
|
||||
public static <U, V> @NonNull Pair<@NonNull U, @NonNull V> of(@NonNull final U first,
|
||||
@NonNull final V second) {
|
||||
return new Pair<>(first, second);
|
||||
}
|
||||
|
||||
|
|
@ -65,8 +63,7 @@ public class Pair<U, V> implements Tuple {
|
|||
*
|
||||
* @return First value
|
||||
*/
|
||||
@Nonnull
|
||||
public final U getFirst() {
|
||||
public final @NonNull U getFirst() {
|
||||
return this.first;
|
||||
}
|
||||
|
||||
|
|
@ -75,8 +72,7 @@ public class Pair<U, V> implements Tuple {
|
|||
*
|
||||
* @return Second value
|
||||
*/
|
||||
@Nonnull
|
||||
public final V getSecond() {
|
||||
public final @NonNull V getSecond() {
|
||||
return this.second;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.types.tuples;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
|
@ -36,19 +37,15 @@ import java.util.Objects;
|
|||
*/
|
||||
public class Quartet<U, V, W, X> implements Tuple {
|
||||
|
||||
@Nonnull
|
||||
private final U first;
|
||||
@Nonnull
|
||||
private final V second;
|
||||
@Nonnull
|
||||
private final W third;
|
||||
@Nonnull
|
||||
private final X fourth;
|
||||
|
||||
protected Quartet(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth) {
|
||||
protected Quartet(@NonNull final U first,
|
||||
@NonNull final V second,
|
||||
@NonNull final W third,
|
||||
@NonNull final X fourth) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
|
|
@ -68,11 +65,10 @@ public class Quartet<U, V, W, X> implements Tuple {
|
|||
* @param <X> Fourth type
|
||||
* @return Created quartet
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V, W, X> Quartet<U, V, W, X> of(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth) {
|
||||
public static <U, V, W, X> @NonNull Quartet<@NonNull U, @NonNull V, @NonNull W, @NonNull X> of(@NonNull final U first,
|
||||
@NonNull final V second,
|
||||
@NonNull final W third,
|
||||
@NonNull final X fourth) {
|
||||
return new Quartet<>(first, second, third, fourth);
|
||||
}
|
||||
|
||||
|
|
@ -81,8 +77,7 @@ public class Quartet<U, V, W, X> implements Tuple {
|
|||
*
|
||||
* @return First value
|
||||
*/
|
||||
@Nonnull
|
||||
public final U getFirst() {
|
||||
public final @NonNull U getFirst() {
|
||||
return this.first;
|
||||
}
|
||||
|
||||
|
|
@ -91,8 +86,7 @@ public class Quartet<U, V, W, X> implements Tuple {
|
|||
*
|
||||
* @return Second value
|
||||
*/
|
||||
@Nonnull
|
||||
public final V getSecond() {
|
||||
public final @NonNull V getSecond() {
|
||||
return this.second;
|
||||
}
|
||||
|
||||
|
|
@ -101,8 +95,7 @@ public class Quartet<U, V, W, X> implements Tuple {
|
|||
*
|
||||
* @return Third value
|
||||
*/
|
||||
@Nonnull
|
||||
public final W getThird() {
|
||||
public final @NonNull W getThird() {
|
||||
return this.third;
|
||||
}
|
||||
|
||||
|
|
@ -111,8 +104,7 @@ public class Quartet<U, V, W, X> implements Tuple {
|
|||
*
|
||||
* @return Fourth value
|
||||
*/
|
||||
@Nonnull
|
||||
public final X getFourth() {
|
||||
public final @NonNull X getFourth() {
|
||||
return this.fourth;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.types.tuples;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
|
@ -37,22 +38,17 @@ import java.util.Objects;
|
|||
*/
|
||||
public class Quintet<U, V, W, X, Y> implements Tuple {
|
||||
|
||||
@Nonnull
|
||||
private final U first;
|
||||
@Nonnull
|
||||
private final V second;
|
||||
@Nonnull
|
||||
private final W third;
|
||||
@Nonnull
|
||||
private final X fourth;
|
||||
@Nonnull
|
||||
private final Y fifth;
|
||||
|
||||
protected Quintet(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth,
|
||||
@Nonnull final Y fifth) {
|
||||
protected Quintet(@NonNull final U first,
|
||||
@NonNull final V second,
|
||||
@NonNull final W third,
|
||||
@NonNull final X fourth,
|
||||
@NonNull final Y fifth) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
|
|
@ -75,12 +71,12 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
|
|||
* @param <Y> Fifth type
|
||||
* @return Created quintet
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V, W, X, Y> Quintet<U, V, W, X, Y> of(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth,
|
||||
@Nonnull final Y fifth) {
|
||||
public static <U, V, W, X, Y> @NonNull Quintet<@NonNull U, @NonNull V, @NonNull W, @NonNull X, @NonNull Y> of(
|
||||
@NonNull final U first,
|
||||
@NonNull final V second,
|
||||
@NonNull final W third,
|
||||
@NonNull final X fourth,
|
||||
@NonNull final Y fifth) {
|
||||
return new Quintet<>(first, second, third, fourth, fifth);
|
||||
}
|
||||
|
||||
|
|
@ -89,8 +85,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
|
|||
*
|
||||
* @return First value
|
||||
*/
|
||||
@Nonnull
|
||||
public final U getFirst() {
|
||||
public final @NonNull U getFirst() {
|
||||
return this.first;
|
||||
}
|
||||
|
||||
|
|
@ -99,8 +94,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
|
|||
*
|
||||
* @return Second value
|
||||
*/
|
||||
@Nonnull
|
||||
public final V getSecond() {
|
||||
public final @NonNull V getSecond() {
|
||||
return this.second;
|
||||
}
|
||||
|
||||
|
|
@ -109,8 +103,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
|
|||
*
|
||||
* @return Third value
|
||||
*/
|
||||
@Nonnull
|
||||
public final W getThird() {
|
||||
public final @NonNull W getThird() {
|
||||
return this.third;
|
||||
}
|
||||
|
||||
|
|
@ -119,8 +112,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
|
|||
*
|
||||
* @return Fourth value
|
||||
*/
|
||||
@Nonnull
|
||||
public final X getFourth() {
|
||||
public final @NonNull X getFourth() {
|
||||
return this.fourth;
|
||||
}
|
||||
|
||||
|
|
@ -129,8 +121,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
|
|||
*
|
||||
* @return Fifth value
|
||||
*/
|
||||
@Nonnull
|
||||
public final Y getFifth() {
|
||||
public final @NonNull Y getFifth() {
|
||||
return this.fifth;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.types.tuples;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
|
@ -38,25 +39,19 @@ import java.util.Objects;
|
|||
*/
|
||||
public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
||||
|
||||
@Nonnull
|
||||
private final U first;
|
||||
@Nonnull
|
||||
private final V second;
|
||||
@Nonnull
|
||||
private final W third;
|
||||
@Nonnull
|
||||
private final X fourth;
|
||||
@Nonnull
|
||||
private final Y fifth;
|
||||
@Nonnull
|
||||
private final Z sixth;
|
||||
|
||||
protected Sextet(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth,
|
||||
@Nonnull final Y fifth,
|
||||
@Nonnull final Z sixth) {
|
||||
protected Sextet(@NonNull final U first,
|
||||
@NonNull final V second,
|
||||
@NonNull final W third,
|
||||
@NonNull final X fourth,
|
||||
@NonNull final Y fifth,
|
||||
@NonNull final Z sixth) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
|
|
@ -82,13 +77,13 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
|||
* @param <Z> Sixth type
|
||||
* @return Created sextet
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V, W, X, Y, Z> Sextet<U, V, W, X, Y, Z> of(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth,
|
||||
@Nonnull final Y fifth,
|
||||
@Nonnull final Z sixth) {
|
||||
public static <U, V, W, X, Y, Z> @NonNull Sextet<@NonNull U, @NonNull V, @NonNull W, @NonNull X, @NonNull Y, @NonNull Z> of(
|
||||
@NonNull final U first,
|
||||
@NonNull final V second,
|
||||
@NonNull final W third,
|
||||
@NonNull final X fourth,
|
||||
@NonNull final Y fifth,
|
||||
@NonNull final Z sixth) {
|
||||
return new Sextet<>(first, second, third, fourth, fifth, sixth);
|
||||
}
|
||||
|
||||
|
|
@ -97,8 +92,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
|||
*
|
||||
* @return First value
|
||||
*/
|
||||
@Nonnull
|
||||
public final U getFirst() {
|
||||
public final @NonNull U getFirst() {
|
||||
return this.first;
|
||||
}
|
||||
|
||||
|
|
@ -107,8 +101,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
|||
*
|
||||
* @return Second value
|
||||
*/
|
||||
@Nonnull
|
||||
public final V getSecond() {
|
||||
public final @NonNull V getSecond() {
|
||||
return this.second;
|
||||
}
|
||||
|
||||
|
|
@ -117,8 +110,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
|||
*
|
||||
* @return Third value
|
||||
*/
|
||||
@Nonnull
|
||||
public final W getThird() {
|
||||
public final @NonNull W getThird() {
|
||||
return this.third;
|
||||
}
|
||||
|
||||
|
|
@ -127,8 +119,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
|||
*
|
||||
* @return Fourth value
|
||||
*/
|
||||
@Nonnull
|
||||
public final X getFourth() {
|
||||
public final @NonNull X getFourth() {
|
||||
return this.fourth;
|
||||
}
|
||||
|
||||
|
|
@ -137,8 +128,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
|||
*
|
||||
* @return Fifth value
|
||||
*/
|
||||
@Nonnull
|
||||
public final Y getFifth() {
|
||||
public final @NonNull Y getFifth() {
|
||||
return this.fifth;
|
||||
}
|
||||
|
||||
|
|
@ -147,8 +137,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
|||
*
|
||||
* @return Sixth value
|
||||
*/
|
||||
@Nonnull
|
||||
public final Z getSixth() {
|
||||
public final @NonNull Z getSixth() {
|
||||
return this.sixth;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.types.tuples;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
|
@ -35,16 +36,13 @@ import java.util.Objects;
|
|||
*/
|
||||
public class Triplet<U, V, W> implements Tuple {
|
||||
|
||||
@Nonnull
|
||||
private final U first;
|
||||
@Nonnull
|
||||
private final V second;
|
||||
@Nonnull
|
||||
private final W third;
|
||||
|
||||
protected Triplet(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third) {
|
||||
protected Triplet(@NonNull final U first,
|
||||
@NonNull final V second,
|
||||
@NonNull final W third) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
|
|
@ -61,10 +59,9 @@ public class Triplet<U, V, W> implements Tuple {
|
|||
* @param <W> Third type
|
||||
* @return Created triplet
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V, W> Triplet<U, V, W> of(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third) {
|
||||
public static <U, V, W> @NonNull Triplet<@NonNull U, @NonNull V, @NonNull W> of(@NonNull final U first,
|
||||
@NonNull final V second,
|
||||
@NonNull final W third) {
|
||||
return new Triplet<>(first, second, third);
|
||||
}
|
||||
|
||||
|
|
@ -73,8 +70,7 @@ public class Triplet<U, V, W> implements Tuple {
|
|||
*
|
||||
* @return First value
|
||||
*/
|
||||
@Nonnull
|
||||
public final U getFirst() {
|
||||
public final @NonNull U getFirst() {
|
||||
return this.first;
|
||||
}
|
||||
|
||||
|
|
@ -83,8 +79,7 @@ public class Triplet<U, V, W> implements Tuple {
|
|||
*
|
||||
* @return Second value
|
||||
*/
|
||||
@Nonnull
|
||||
public final V getSecond() {
|
||||
public final @NonNull V getSecond() {
|
||||
return this.second;
|
||||
}
|
||||
|
||||
|
|
@ -93,8 +88,7 @@ public class Triplet<U, V, W> implements Tuple {
|
|||
*
|
||||
* @return Third value
|
||||
*/
|
||||
@Nonnull
|
||||
public final W getThird() {
|
||||
public final @NonNull W getThird() {
|
||||
return this.third;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,147 +0,0 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2020 Alexander Söderberg & Contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package cloud.commandframework.types.tuples;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Utility class for dealing with tuples
|
||||
*/
|
||||
public final class Tuples {
|
||||
|
||||
static final int SIZE_PAIR = 2;
|
||||
static final int SIZE_TRIPLET = 3;
|
||||
static final int SIZE_QUARTET = 4;
|
||||
static final int SIZE_QUINTET = 5;
|
||||
static final int SIZE_SEXTET = 6;
|
||||
|
||||
private Tuples() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new pair
|
||||
*
|
||||
* @param first First value
|
||||
* @param second Second value
|
||||
* @param <U> First type
|
||||
* @param <V> Second type
|
||||
* @return Created pair
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V> Pair<U, V> of(@Nonnull final U first,
|
||||
@Nonnull final V second) {
|
||||
return Pair.of(first, second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new triplet
|
||||
*
|
||||
* @param first First value
|
||||
* @param second Second value
|
||||
* @param third Third value
|
||||
* @param <U> First type
|
||||
* @param <V> Second type
|
||||
* @param <W> Third type
|
||||
* @return Created triplet
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V, W> Triplet<U, V, W> of(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third) {
|
||||
return Triplet.of(first, second, third);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new quartet
|
||||
*
|
||||
* @param first First value
|
||||
* @param second Second value
|
||||
* @param third Third value
|
||||
* @param fourth Fourth value
|
||||
* @param <U> First type
|
||||
* @param <V> Second type
|
||||
* @param <W> Third type
|
||||
* @param <X> Fourth type
|
||||
* @return Created quartet
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V, W, X> Quartet<U, V, W, X> of(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth) {
|
||||
return Quartet.of(first, second, third, fourth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new quintet
|
||||
*
|
||||
* @param first First value
|
||||
* @param second Second value
|
||||
* @param third Third value
|
||||
* @param fourth Fourth value
|
||||
* @param fifth Fifth value
|
||||
* @param <U> First type
|
||||
* @param <V> Second type
|
||||
* @param <W> Third type
|
||||
* @param <X> Fourth type
|
||||
* @param <Y> Fifth type
|
||||
* @return Created quintet
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V, W, X, Y> Quintet<U, V, W, X, Y> of(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth,
|
||||
@Nonnull final Y fifth) {
|
||||
return Quintet.of(first, second, third, fourth, fifth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new sextet
|
||||
*
|
||||
* @param first First value
|
||||
* @param second Second value
|
||||
* @param third Third value
|
||||
* @param fourth Fourth value
|
||||
* @param fifth Fifth value
|
||||
* @param sixth Sixth value
|
||||
* @param <U> First type
|
||||
* @param <V> Second type
|
||||
* @param <W> Third type
|
||||
* @param <X> Fourth type
|
||||
* @param <Y> Fifth type
|
||||
* @param <Z> Sixth type
|
||||
* @return Created sextet
|
||||
*/
|
||||
@Nonnull
|
||||
public static <U, V, W, X, Y, Z> Sextet<U, V, W, X, Y, Z> of(@Nonnull final U first,
|
||||
@Nonnull final V second,
|
||||
@Nonnull final W third,
|
||||
@Nonnull final X fourth,
|
||||
@Nonnull final Y fifth,
|
||||
@Nonnull final Z sixth) {
|
||||
return Sextet.of(first, second, third, fourth, fifth, sixth);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -25,9 +25,9 @@ package cloud.commandframework.services;
|
|||
|
||||
import cloud.commandframework.services.annotations.Order;
|
||||
import cloud.commandframework.services.types.Service;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Method;
|
||||
|
|
@ -40,7 +40,8 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
|
|||
private final Method method;
|
||||
private final Object instance;
|
||||
|
||||
AnnotatedMethodService(@Nonnull final Object instance, @Nonnull final Method method)
|
||||
AnnotatedMethodService(@NonNull final Object instance,
|
||||
@NonNull final Method method)
|
||||
throws Exception {
|
||||
ExecutionOrder executionOrder = ExecutionOrder.SOON;
|
||||
try {
|
||||
|
|
@ -57,10 +58,9 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
|
|||
this.method = method;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Result handle(@Nonnull final Context context) {
|
||||
public @Nullable Result handle(@NonNull final Context context) {
|
||||
try {
|
||||
return (Result) this.methodHandle.invoke(this.instance, context);
|
||||
} catch (final Throwable throwable) {
|
||||
|
|
@ -72,9 +72,8 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExecutionOrder order() {
|
||||
public @NonNull ExecutionOrder order() {
|
||||
return this.executionOrder;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ package cloud.commandframework.services;
|
|||
import io.leangen.geantyref.TypeToken;
|
||||
import cloud.commandframework.services.annotations.ServiceImplementation;
|
||||
import cloud.commandframework.services.types.Service;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -35,8 +35,8 @@ import java.util.Map;
|
|||
enum AnnotatedMethodServiceFactory {
|
||||
INSTANCE;
|
||||
|
||||
Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> lookupServices(
|
||||
@Nonnull final Object instance) throws Exception {
|
||||
@NonNull Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> lookupServices(
|
||||
@NonNull final Object instance) throws Exception {
|
||||
final Map<Service<?, ?>, TypeToken<? extends Service<?, ?>>> map = new HashMap<>();
|
||||
final Class<?> clazz = instance.getClass();
|
||||
for (final Method method : clazz.getDeclaredMethods()) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.services;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
|
@ -38,18 +39,18 @@ import java.util.Map;
|
|||
* @param <Context> Context/Request type
|
||||
* @param <Result> Result type
|
||||
*/
|
||||
public abstract class ChunkedRequestContext<Context, Result> {
|
||||
public abstract class ChunkedRequestContext<@NonNull Context, @NonNull Result> {
|
||||
|
||||
private final Object lock = new Object();
|
||||
private final List<Context> requests;
|
||||
private final Map<Context, Result> results;
|
||||
private final List<@NonNull Context> requests;
|
||||
private final Map<@NonNull Context, @NonNull Result> results;
|
||||
|
||||
/**
|
||||
* Initialize a new request
|
||||
*
|
||||
* @param requests Request contexts
|
||||
*/
|
||||
protected ChunkedRequestContext(@Nonnull final Collection<Context> requests) {
|
||||
protected ChunkedRequestContext(@NonNull final Collection<Context> requests) {
|
||||
this.requests = new ArrayList<>(requests);
|
||||
this.results = new HashMap<>(requests.size());
|
||||
}
|
||||
|
|
@ -59,8 +60,7 @@ public abstract class ChunkedRequestContext<Context, Result> {
|
|||
*
|
||||
* @return Unmodifiable map of results
|
||||
*/
|
||||
@Nonnull
|
||||
public final Map<Context, Result> getAvailableResults() {
|
||||
public final @NonNull Map<@NonNull Context, @NonNull Result> getAvailableResults() {
|
||||
synchronized (this.lock) {
|
||||
return Collections.unmodifiableMap(this.results);
|
||||
}
|
||||
|
|
@ -71,8 +71,7 @@ public abstract class ChunkedRequestContext<Context, Result> {
|
|||
*
|
||||
* @return Unmodifiable list of remaining requests
|
||||
*/
|
||||
@Nonnull
|
||||
public final List<Context> getRemaining() {
|
||||
public final @NonNull List<@NonNull Context> getRemaining() {
|
||||
synchronized (this.lock) {
|
||||
return Collections.unmodifiableList(this.requests);
|
||||
}
|
||||
|
|
@ -84,7 +83,7 @@ public abstract class ChunkedRequestContext<Context, Result> {
|
|||
* @param context Context
|
||||
* @param result Result
|
||||
*/
|
||||
public final void storeResult(@Nonnull final Context context, @Nonnull final Result result) {
|
||||
public final void storeResult(@NonNull final Context context, @NonNull final Result result) {
|
||||
synchronized (this.lock) {
|
||||
this.results.put(context, result);
|
||||
this.requests.remove(context);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
//
|
||||
package cloud.commandframework.services;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Wrapper for exceptions thrown during pipeline execution.
|
||||
|
|
@ -37,7 +37,7 @@ public final class PipelineException extends RuntimeException {
|
|||
*
|
||||
* @param cause Cause of the exception
|
||||
*/
|
||||
public PipelineException(@Nonnull final Exception cause) {
|
||||
public PipelineException(@NonNull final Exception cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public final class PipelineException extends RuntimeException {
|
|||
* @param message Message explaining the exception
|
||||
* @param cause Cause of the exception
|
||||
*/
|
||||
public PipelineException(@Nonnull final String message, @Nonnull final Exception cause) {
|
||||
public PipelineException(@NonNull final String message, @NonNull final Exception cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,16 +24,16 @@
|
|||
package cloud.commandframework.services;
|
||||
|
||||
import cloud.commandframework.services.types.Service;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
enum ServiceFilterHandler {
|
||||
INSTANCE;
|
||||
|
||||
<Context> boolean passes(
|
||||
@Nonnull final ServiceRepository<Context, ?>.ServiceWrapper<? extends Service<Context, ?>> service,
|
||||
@Nonnull final Context context) {
|
||||
@NonNull final ServiceRepository<Context, ?>.ServiceWrapper<? extends Service<Context, ?>> service,
|
||||
@NonNull final Context context) {
|
||||
if (!service.isDefaultImplementation()) {
|
||||
for (final Predicate<Context> predicate : service.getFilters()) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ package cloud.commandframework.services;
|
|||
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import cloud.commandframework.services.types.Service;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -45,7 +45,7 @@ public final class ServicePipeline {
|
|||
private final Map<TypeToken<? extends Service<?, ?>>, ServiceRepository<?, ?>> repositories;
|
||||
private final Executor executor;
|
||||
|
||||
ServicePipeline(@Nonnull final Executor executor) {
|
||||
ServicePipeline(@NonNull final Executor executor) {
|
||||
this.repositories = new HashMap<>();
|
||||
this.executor = executor;
|
||||
}
|
||||
|
|
@ -55,8 +55,7 @@ public final class ServicePipeline {
|
|||
*
|
||||
* @return Builder instance
|
||||
*/
|
||||
@Nonnull
|
||||
public static ServicePipelineBuilder builder() {
|
||||
public static @NonNull ServicePipelineBuilder builder() {
|
||||
return new ServicePipelineBuilder();
|
||||
}
|
||||
|
||||
|
|
@ -71,9 +70,9 @@ public final class ServicePipeline {
|
|||
* @param <Result> Service result type
|
||||
* @return ServicePipeline The service pipeline instance
|
||||
*/
|
||||
public <Context, Result> ServicePipeline registerServiceType(
|
||||
@Nonnull final TypeToken<? extends Service<Context, Result>> type,
|
||||
@Nonnull final Service<Context, Result> defaultImplementation) {
|
||||
public <Context, Result> @NonNull ServicePipeline registerServiceType(
|
||||
@NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type,
|
||||
@NonNull final Service<@NonNull Context, @NonNull Result> defaultImplementation) {
|
||||
synchronized (this.lock) {
|
||||
if (repositories.containsKey(type)) {
|
||||
throw new IllegalArgumentException(String
|
||||
|
|
@ -105,8 +104,8 @@ public final class ServicePipeline {
|
|||
* @throws Exception Any exceptions thrown during the registration process
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ServicePipeline registerMethods(
|
||||
@Nonnull final T instance) throws Exception {
|
||||
public <T> @NonNull ServicePipeline registerMethods(
|
||||
@NonNull final T instance) throws Exception {
|
||||
synchronized (this.lock) {
|
||||
final Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> services =
|
||||
AnnotatedMethodServiceFactory.INSTANCE.lookupServices(instance);
|
||||
|
|
@ -139,9 +138,9 @@ public final class ServicePipeline {
|
|||
* @return ServicePipeline The service pipeline instance
|
||||
*/
|
||||
public <Context, Result> ServicePipeline registerServiceImplementation(
|
||||
@Nonnull final TypeToken<? extends Service<Context, Result>> type,
|
||||
@Nonnull final Service<Context, Result> implementation,
|
||||
@Nonnull final Collection<Predicate<Context>> filters) {
|
||||
@NonNull final TypeToken<? extends Service<Context, Result>> type,
|
||||
@NonNull final Service<Context, Result> implementation,
|
||||
@NonNull final Collection<Predicate<Context>> filters) {
|
||||
synchronized (this.lock) {
|
||||
final ServiceRepository<Context, Result> repository = getRepository(type);
|
||||
repository.registerImplementation(implementation, filters);
|
||||
|
|
@ -163,9 +162,9 @@ public final class ServicePipeline {
|
|||
* @return ServicePipeline The service pipeline instance
|
||||
*/
|
||||
public <Context, Result> ServicePipeline registerServiceImplementation(
|
||||
@Nonnull final Class<? extends Service<Context, Result>> type,
|
||||
@Nonnull final Service<Context, Result> implementation,
|
||||
@Nonnull final Collection<Predicate<Context>> filters) {
|
||||
@NonNull final Class<? extends Service<Context, Result>> type,
|
||||
@NonNull final Service<Context, Result> implementation,
|
||||
@NonNull final Collection<Predicate<Context>> filters) {
|
||||
return registerServiceImplementation(TypeToken.get(type), implementation, filters);
|
||||
}
|
||||
|
||||
|
|
@ -177,15 +176,15 @@ public final class ServicePipeline {
|
|||
* @param <Context> Context type
|
||||
* @return Service pumper instance
|
||||
*/
|
||||
@Nonnull
|
||||
public <Context> ServicePump<Context> pump(@Nonnull final Context context) {
|
||||
@NonNull
|
||||
public <Context> ServicePump<Context> pump(@NonNull final Context context) {
|
||||
return new ServicePump<>(this, context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nonnull
|
||||
@NonNull
|
||||
<Context, Result> ServiceRepository<Context, Result> getRepository(
|
||||
@Nonnull final TypeToken<? extends Service<Context, Result>> type) {
|
||||
@NonNull final TypeToken<? extends Service<Context, Result>> type) {
|
||||
final ServiceRepository<Context, Result> repository =
|
||||
(ServiceRepository<Context, Result>) this.repositories.get(type);
|
||||
if (repository == null) {
|
||||
|
|
@ -200,7 +199,7 @@ public final class ServicePipeline {
|
|||
*
|
||||
* @return Returns an Immutable collection of the service types registered.
|
||||
*/
|
||||
@Nonnull
|
||||
@NonNull
|
||||
public Collection<TypeToken<? extends Service<?, ?>>> getRecognizedTypes() {
|
||||
return Collections.unmodifiableCollection(this.repositories.keySet());
|
||||
}
|
||||
|
|
@ -215,10 +214,10 @@ public final class ServicePipeline {
|
|||
* @return Returns an collection of the {@link TypeToken}s of the implementations for a given
|
||||
* service. Iterator order matches the priority when pumping contexts through the pipeline
|
||||
*/
|
||||
@Nonnull
|
||||
@NonNull
|
||||
@SuppressWarnings("unchecked")
|
||||
public <Context, Result, S extends Service<Context, Result>> Collection<TypeToken<? extends S>> getImplementations(
|
||||
@Nonnull final TypeToken<S> type) {
|
||||
@NonNull final TypeToken<S> type) {
|
||||
ServiceRepository<Context, Result> repository = getRepository(type);
|
||||
List<TypeToken<? extends S>> collection = new LinkedList<>();
|
||||
final LinkedList<? extends ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>>>
|
||||
|
|
@ -232,7 +231,7 @@ public final class ServicePipeline {
|
|||
return Collections.unmodifiableList(collection);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NonNull
|
||||
Executor getExecutor() {
|
||||
return this.executor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.services;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -44,8 +45,7 @@ public final class ServicePipelineBuilder {
|
|||
*
|
||||
* @return New service pipeline
|
||||
*/
|
||||
@Nonnull
|
||||
public ServicePipeline build() {
|
||||
public @NonNull ServicePipeline build() {
|
||||
return new ServicePipeline(this.executor);
|
||||
}
|
||||
|
||||
|
|
@ -56,8 +56,7 @@ public final class ServicePipelineBuilder {
|
|||
* @param executor New executor
|
||||
* @return Builder instance
|
||||
*/
|
||||
@Nonnull
|
||||
public ServicePipelineBuilder withExecutor(@Nonnull final Executor executor) {
|
||||
public @NonNull ServicePipelineBuilder withExecutor(@NonNull final Executor executor) {
|
||||
this.executor = Objects.requireNonNull(executor, "Executor may not be null");
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ package cloud.commandframework.services;
|
|||
|
||||
import cloud.commandframework.services.types.Service;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Class that forwards a context to a service type that consumes said context
|
||||
|
|
@ -38,7 +37,8 @@ public final class ServicePump<Context> {
|
|||
private final ServicePipeline servicePipeline;
|
||||
private final Context context;
|
||||
|
||||
ServicePump(final ServicePipeline servicePipeline, final Context context) {
|
||||
ServicePump(@NonNull final ServicePipeline servicePipeline,
|
||||
@NonNull final Context context) {
|
||||
this.servicePipeline = servicePipeline;
|
||||
this.context = context;
|
||||
}
|
||||
|
|
@ -50,9 +50,8 @@ public final class ServicePump<Context> {
|
|||
* @param <Result> Result type
|
||||
* @return Service spigot instance
|
||||
*/
|
||||
@Nonnull
|
||||
public <Result> ServiceSpigot<Context, Result> through(
|
||||
@Nonnull final TypeToken<? extends Service<Context, Result>> type) {
|
||||
public <Result> @NonNull ServiceSpigot<@NonNull Context, @NonNull Result> through(
|
||||
@NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type) {
|
||||
return new ServiceSpigot<>(this.servicePipeline, this.context, type);
|
||||
}
|
||||
|
||||
|
|
@ -63,9 +62,8 @@ public final class ServicePump<Context> {
|
|||
* @param <Result> Result type
|
||||
* @return Service spigot instance
|
||||
*/
|
||||
@Nonnull
|
||||
public <Result> ServiceSpigot<Context, Result> through(
|
||||
@Nonnull final Class<? extends Service<Context, Result>> clazz) {
|
||||
public <Result> @NonNull ServiceSpigot<@NonNull Context, @NonNull Result> through(
|
||||
@NonNull final Class<? extends Service<@NonNull Context, @NonNull Result>> clazz) {
|
||||
return this.through(TypeToken.get(clazz));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ package cloud.commandframework.services;
|
|||
import io.leangen.geantyref.TypeToken;
|
||||
import cloud.commandframework.services.annotations.Order;
|
||||
import cloud.commandframework.services.types.Service;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
|
@ -54,7 +54,7 @@ public final class ServiceRepository<Context, Response> {
|
|||
*
|
||||
* @param serviceType Service type
|
||||
*/
|
||||
ServiceRepository(@Nonnull final TypeToken<? extends Service<Context, Response>> serviceType) {
|
||||
ServiceRepository(@NonNull final TypeToken<? extends Service<Context, Response>> serviceType) {
|
||||
this.serviceType = serviceType;
|
||||
this.implementations = new LinkedList<>();
|
||||
}
|
||||
|
|
@ -66,8 +66,8 @@ public final class ServiceRepository<Context, Response> {
|
|||
* @param filters Filters that will be used to determine whether or not the service gets used
|
||||
* @param <T> Type of the implementation
|
||||
*/
|
||||
<T extends Service<Context, Response>> void registerImplementation(@Nonnull final T service,
|
||||
@Nonnull final Collection<Predicate<Context>> filters) {
|
||||
<T extends Service<Context, Response>> void registerImplementation(@NonNull final T service,
|
||||
@NonNull final Collection<Predicate<Context>> filters) {
|
||||
synchronized (this.lock) {
|
||||
this.implementations.add(new ServiceWrapper<>(service, filters));
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ public final class ServiceRepository<Context, Response> {
|
|||
*
|
||||
* @return Queue containing all implementations
|
||||
*/
|
||||
@Nonnull
|
||||
@NonNull
|
||||
LinkedList<ServiceWrapper<? extends Service<Context, Response>>> getQueue() {
|
||||
synchronized (this.lock) {
|
||||
return new LinkedList<>(this.implementations);
|
||||
|
|
@ -101,8 +101,8 @@ public final class ServiceRepository<Context, Response> {
|
|||
private final int registrationOrder = ServiceRepository.this.registrationOrder++;
|
||||
private final ExecutionOrder executionOrder;
|
||||
|
||||
private ServiceWrapper(@Nonnull final T implementation,
|
||||
@Nonnull final Collection<Predicate<Context>> filters) {
|
||||
private ServiceWrapper(@NonNull final T implementation,
|
||||
@NonNull final Collection<Predicate<Context>> filters) {
|
||||
this.defaultImplementation = implementations.isEmpty();
|
||||
this.implementation = implementation;
|
||||
this.filters = filters;
|
||||
|
|
@ -118,12 +118,12 @@ public final class ServiceRepository<Context, Response> {
|
|||
this.executionOrder = executionOrder;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NonNull
|
||||
T getImplementation() {
|
||||
return this.implementation;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NonNull
|
||||
Collection<Predicate<Context>> getFilters() {
|
||||
return Collections.unmodifiableCollection(this.filters);
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ public final class ServiceRepository<Context, Response> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@Nonnull final ServiceWrapper<T> other) {
|
||||
public int compareTo(@NonNull final ServiceWrapper<T> other) {
|
||||
return Comparator.<ServiceWrapper<T>>comparingInt(
|
||||
wrapper -> wrapper.isDefaultImplementation()
|
||||
? Integer.MIN_VALUE
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ import io.leangen.geantyref.TypeToken;
|
|||
import cloud.commandframework.services.types.ConsumerService;
|
||||
import cloud.commandframework.services.types.Service;
|
||||
import cloud.commandframework.services.types.SideEffectService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
|
|
@ -45,8 +45,9 @@ public final class ServiceSpigot<Context, Result> {
|
|||
private final ServicePipeline pipeline;
|
||||
private final ServiceRepository<Context, Result> repository;
|
||||
|
||||
ServiceSpigot(@Nonnull final ServicePipeline pipeline, @Nonnull final Context context,
|
||||
@Nonnull final TypeToken<? extends Service<Context, Result>> type) {
|
||||
ServiceSpigot(@NonNull final ServicePipeline pipeline,
|
||||
@NonNull final Context context,
|
||||
@NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type) {
|
||||
this.context = context;
|
||||
this.pipeline = pipeline;
|
||||
this.repository = pipeline.getRepository(type);
|
||||
|
|
@ -72,11 +73,11 @@ public final class ServiceSpigot<Context, Result> {
|
|||
* @see PipelineException PipelineException wraps exceptions thrown during filtering and result
|
||||
* retrieval
|
||||
*/
|
||||
@Nonnull
|
||||
@SuppressWarnings("unchecked")
|
||||
public Result getResult()
|
||||
public @NonNull Result getResult()
|
||||
throws IllegalStateException, PipelineException {
|
||||
final LinkedList<? extends ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>>>
|
||||
final LinkedList<? extends ServiceRepository<@NonNull Context, @NonNull Result>
|
||||
.ServiceWrapper<? extends Service<@NonNull Context, @NonNull Result>>>
|
||||
queue = this.repository.getQueue();
|
||||
queue.sort(null); // Sort using the built in comparator method
|
||||
ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>>
|
||||
|
|
@ -128,7 +129,7 @@ public final class ServiceSpigot<Context, Result> {
|
|||
* default implementation
|
||||
* @throws IllegalStateException If a {@link SideEffectService} returns {@code null}
|
||||
*/
|
||||
public void getResult(@Nonnull final BiConsumer<Result, Throwable> consumer) {
|
||||
public void getResult(@NonNull final BiConsumer<Result, Throwable> consumer) {
|
||||
try {
|
||||
consumer.accept(getResult(), null);
|
||||
} catch (final PipelineException pipelineException) {
|
||||
|
|
@ -145,8 +146,7 @@ public final class ServiceSpigot<Context, Result> {
|
|||
*
|
||||
* @return Generated result
|
||||
*/
|
||||
@Nonnull
|
||||
public CompletableFuture<Result> getResultAsynchronously() {
|
||||
public @NonNull CompletableFuture<Result> getResultAsynchronously() {
|
||||
return CompletableFuture.supplyAsync(this::getResult, this.pipeline.getExecutor());
|
||||
}
|
||||
|
||||
|
|
@ -155,8 +155,7 @@ public final class ServiceSpigot<Context, Result> {
|
|||
*
|
||||
* @return New pump, for the result of this request
|
||||
*/
|
||||
@Nonnull
|
||||
public ServicePump<Result> forward() {
|
||||
public @NonNull ServicePump<Result> forward() {
|
||||
return this.pipeline.pump(this.getResult());
|
||||
}
|
||||
|
||||
|
|
@ -165,8 +164,7 @@ public final class ServiceSpigot<Context, Result> {
|
|||
*
|
||||
* @return New pump, for the result of this request
|
||||
*/
|
||||
@Nonnull
|
||||
public CompletableFuture<ServicePump<Result>> forwardAsynchronously() {
|
||||
public @NonNull CompletableFuture<ServicePump<Result>> forwardAsynchronously() {
|
||||
return this.getResultAsynchronously().thenApply(pipeline::pump);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@
|
|||
package cloud.commandframework.services.types;
|
||||
|
||||
import cloud.commandframework.services.State;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
|
|
@ -49,9 +49,8 @@ public interface ConsumerService<Context>
|
|||
throw new PipeBurst();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
default State handle(@Nonnull final Context context) {
|
||||
default @NonNull State handle(@NonNull final Context context) {
|
||||
try {
|
||||
this.accept(context);
|
||||
} catch (final PipeBurst burst) {
|
||||
|
|
@ -67,7 +66,7 @@ public interface ConsumerService<Context>
|
|||
* @param context Context to consume
|
||||
*/
|
||||
@Override
|
||||
void accept(@Nonnull Context context);
|
||||
void accept(@NonNull Context context);
|
||||
|
||||
|
||||
class PipeBurst extends RuntimeException {
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@
|
|||
package cloud.commandframework.services.types;
|
||||
|
||||
import cloud.commandframework.services.ChunkedRequestContext;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -38,11 +38,10 @@ import java.util.Map;
|
|||
* @param <Chunked> Chunk request context
|
||||
*/
|
||||
public interface PartialResultService<Context, Result, Chunked extends ChunkedRequestContext<Context, Result>>
|
||||
extends Service<Chunked, Map<Context, Result>> {
|
||||
extends Service<Chunked, @Nullable Map<@NonNull Context, @NonNull Result>> {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
default Map<Context, Result> handle(@Nonnull final Chunked context) {
|
||||
default @Nullable Map<@NonNull Context, @NonNull Result> handle(@NonNull final Chunked context) {
|
||||
if (!context.isCompleted()) {
|
||||
this.handleRequests(context.getRemaining()).forEach(context::storeResult);
|
||||
}
|
||||
|
|
@ -59,7 +58,6 @@ public interface PartialResultService<Context, Result, Chunked extends ChunkedRe
|
|||
* @param requests Requests
|
||||
* @return Map of request-result pairs
|
||||
*/
|
||||
@Nonnull
|
||||
Map<Context, Result> handleRequests(@Nonnull List<Context> requests);
|
||||
@NonNull Map<@NonNull Context, @NonNull Result> handleRequests(@NonNull List<Context> requests);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ package cloud.commandframework.services.types;
|
|||
|
||||
import cloud.commandframework.services.ExecutionOrder;
|
||||
import cloud.commandframework.services.PipelineException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +39,7 @@ import java.util.function.Function;
|
|||
* @param <Result> Response type, this is what is produced by the service ("provided")
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Service<Context, Result> extends Function<Context, Result> {
|
||||
public interface Service<Context, Result> extends Function<@NonNull Context, @Nullable Result> {
|
||||
|
||||
/**
|
||||
* Provide a response for the given context. If the service implementation cannot provide a
|
||||
|
|
@ -52,11 +52,10 @@ public interface Service<Context, Result> extends Function<Context, Result> {
|
|||
* @throws Exception Any exception that occurs during the handling can be thrown, and will be
|
||||
* wrapped by a {@link PipelineException}
|
||||
*/
|
||||
@Nullable
|
||||
Result handle(@Nonnull Context context) throws Exception;
|
||||
@Nullable Result handle(@NonNull Context context) throws Exception;
|
||||
|
||||
@Override
|
||||
default Result apply(@Nonnull Context context) {
|
||||
default @Nullable Result apply(@NonNull Context context) {
|
||||
try {
|
||||
return this.handle(context);
|
||||
} catch (final Exception exception) {
|
||||
|
|
@ -70,8 +69,7 @@ public interface Service<Context, Result> extends Function<Context, Result> {
|
|||
*
|
||||
* @return Execution order
|
||||
*/
|
||||
@Nullable
|
||||
default ExecutionOrder order() {
|
||||
default @Nullable ExecutionOrder order() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@
|
|||
package cloud.commandframework.services.types;
|
||||
|
||||
import cloud.commandframework.services.State;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Service implementation that alters the state of the owning application in some way. A
|
||||
|
|
@ -49,7 +48,6 @@ public interface SideEffectService<Context> extends Service<Context, State> {
|
|||
* wrapped by a {@link cloud.commandframework.services.PipelineException}
|
||||
*/
|
||||
@Override
|
||||
@Nonnull
|
||||
State handle(@Nonnull Context context) throws Exception;
|
||||
@NonNull State handle(@NonNull Context context) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,12 +25,10 @@ package cloud.commandframework.services.mock;
|
|||
|
||||
import cloud.commandframework.services.annotations.ServiceImplementation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class AnnotatedMethodTest {
|
||||
|
||||
@ServiceImplementation(MockService.class)
|
||||
public MockService.MockResult handle(@Nonnull final MockService.MockContext context) {
|
||||
public MockService.MockResult handle(final MockService.MockContext context) {
|
||||
return new MockService.MockResult(context.getString().length());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,17 +23,14 @@
|
|||
//
|
||||
package cloud.commandframework.services.mock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CompletingPartialResultService implements MockPartialResultService {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> handleRequests(
|
||||
@Nonnull List<MockChunkedRequest.Animal> requests) {
|
||||
public Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> handleRequests(List<MockChunkedRequest.Animal> requests) {
|
||||
final Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> map = new HashMap<>();
|
||||
for (final MockChunkedRequest.Animal animal : requests) {
|
||||
if (animal.getName().equals("cow")) {
|
||||
|
|
|
|||
|
|
@ -23,14 +23,10 @@
|
|||
//
|
||||
package cloud.commandframework.services.mock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DefaultMockService implements MockService {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MockResult handle(@Nonnull final MockContext mockContext)
|
||||
public MockResult handle(final MockContext mockContext)
|
||||
throws Exception {
|
||||
if (mockContext.getString().equals("pls throw exception")) {
|
||||
throw new TotallyIntentionalException();
|
||||
|
|
|
|||
|
|
@ -23,17 +23,14 @@
|
|||
//
|
||||
package cloud.commandframework.services.mock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DefaultPartialRequestService implements MockPartialResultService {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> handleRequests(
|
||||
@Nonnull final List<MockChunkedRequest.Animal> requests) {
|
||||
public Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> handleRequests(final List<MockChunkedRequest.Animal> requests) {
|
||||
final Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> map =
|
||||
new HashMap<>(requests.size());
|
||||
for (final MockChunkedRequest.Animal animal : requests) {
|
||||
|
|
|
|||
|
|
@ -25,13 +25,10 @@ package cloud.commandframework.services.mock;
|
|||
|
||||
import cloud.commandframework.services.State;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class DefaultSideEffectService implements MockSideEffectService {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public State handle(@Nonnull final MockPlayer mockPlayer) {
|
||||
public State handle(final MockPlayer mockPlayer) {
|
||||
mockPlayer.setHealth(0);
|
||||
return State.ACCEPTED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,12 +25,10 @@ package cloud.commandframework.services.mock;
|
|||
|
||||
import cloud.commandframework.services.types.ConsumerService;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class InterruptingMockConsumer implements MockConsumerService {
|
||||
|
||||
@Override
|
||||
public void accept(@Nonnull final MockService.MockContext mockContext) {
|
||||
public void accept(final MockService.MockContext mockContext) {
|
||||
ConsumerService.interrupt();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,13 +25,12 @@ package cloud.commandframework.services.mock;
|
|||
|
||||
import cloud.commandframework.services.ChunkedRequestContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
|
||||
public class MockChunkedRequest
|
||||
extends ChunkedRequestContext<MockChunkedRequest.Animal, MockChunkedRequest.Sound> {
|
||||
|
||||
public MockChunkedRequest(@Nonnull final Collection<Animal> requests) {
|
||||
public MockChunkedRequest(final Collection<Animal> requests) {
|
||||
super(requests);
|
||||
}
|
||||
|
||||
|
|
@ -39,11 +38,10 @@ public class MockChunkedRequest
|
|||
|
||||
private final String name;
|
||||
|
||||
public Animal(@Nonnull final String name) {
|
||||
public Animal(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
|
@ -54,11 +52,10 @@ public class MockChunkedRequest
|
|||
|
||||
private final String sound;
|
||||
|
||||
public Sound(@Nonnull final String sound) {
|
||||
public Sound(final String sound) {
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getSound() {
|
||||
return this.sound;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,15 +26,11 @@ package cloud.commandframework.services.mock;
|
|||
import cloud.commandframework.services.ExecutionOrder;
|
||||
import cloud.commandframework.services.annotations.Order;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Order(ExecutionOrder.FIRST)
|
||||
public class MockOrderedFirst implements MockService {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MockResult handle(@Nonnull final MockContext mockContext) {
|
||||
public MockResult handle(final MockContext mockContext) {
|
||||
return new MockResult(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,15 +26,11 @@ package cloud.commandframework.services.mock;
|
|||
import cloud.commandframework.services.ExecutionOrder;
|
||||
import cloud.commandframework.services.annotations.Order;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Order(ExecutionOrder.LAST)
|
||||
public class MockOrderedLast implements MockService {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MockResult handle(@Nonnull final MockContext mockContext) {
|
||||
public MockResult handle(final MockContext mockContext) {
|
||||
return new MockResult(2);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,13 +26,10 @@ package cloud.commandframework.services.mock;
|
|||
import cloud.commandframework.services.State;
|
||||
import cloud.commandframework.services.types.SideEffectService;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class MockResultConsumer implements SideEffectService<MockService.MockResult> {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public State handle(@Nonnull final MockService.MockResult mockResultConsumer) {
|
||||
public State handle(final MockService.MockResult mockResultConsumer) {
|
||||
return State.ACCEPTED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ package cloud.commandframework.services.mock;
|
|||
|
||||
import cloud.commandframework.services.types.Service;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface MockService extends Service<MockService.MockContext, MockService.MockResult> {
|
||||
|
||||
class MockContext {
|
||||
|
|
@ -34,21 +32,19 @@ public interface MockService extends Service<MockService.MockContext, MockServic
|
|||
private final String string;
|
||||
private String state = "";
|
||||
|
||||
public MockContext(@Nonnull final String string) {
|
||||
public MockContext( final String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getString() {
|
||||
return this.string;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public void setState(@Nonnull final String state) {
|
||||
public void setState( final String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,15 +23,12 @@
|
|||
//
|
||||
package cloud.commandframework.services.mock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class SecondaryMockService implements MockService, Predicate<MockService.MockContext> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MockResult handle(@Nonnull final MockContext mockContext) {
|
||||
public MockResult handle(final MockContext mockContext) {
|
||||
return new MockResult(999);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,13 +25,10 @@ package cloud.commandframework.services.mock;
|
|||
|
||||
import cloud.commandframework.services.State;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class SecondaryMockSideEffectService implements MockSideEffectService {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public State handle(@Nonnull final MockPlayer mockPlayer) {
|
||||
public State handle(final MockPlayer mockPlayer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,12 +23,10 @@
|
|||
//
|
||||
package cloud.commandframework.services.mock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class StateSettingConsumerService implements MockConsumerService {
|
||||
|
||||
@Override
|
||||
public void accept(@Nonnull final MockService.MockContext mockContext) {
|
||||
public void accept(final MockService.MockContext mockContext) {
|
||||
mockContext.setState("");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue