ru.cwcode.commands.extra.command.argument.KeyArgument Maven / Gradle / Ivy
package ru.cwcode.commands.extra.command.argument;
import ru.cwcode.commands.Argument;
import ru.cwcode.commands.api.Sender;
import ru.cwcode.commands.extra.RepositoryAccessor;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class KeyArgument extends Argument {
private final RepositoryAccessor repositoryAccessor;
public KeyArgument(RepositoryAccessor repositoryAccessor) {
this.repositoryAccessor = repositoryAccessor;
}
@Override
public boolean valid(String raw) {
return false;
}
@Override
public boolean valid(Sender sender, String raw, List arguments) {
return repositoryAccessor.keys((S) sender).contains(repositoryAccessor.stringToKey(raw));
}
@Override
public Collection completions(Sender sender) {
return repositoryAccessor.keys((S) sender).stream()
.map(repositoryAccessor::keyToString)
.collect(Collectors.toList());
}
@Override
public String argumentName() {
return "ID";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy