use of dev.rosewood.rosegarden.command.framework.ArgumentParser in project RoseGarden by Rosewood-Development.
the class EnumArgumentHandler method handleInternal.
@Override
protected T handleInternal(RoseCommandArgumentInfo argumentInfo, ArgumentParser argumentParser) {
String input = argumentParser.next();
T[] enumConstants = this.getHandledType().getEnumConstants();
Optional<T> value = Stream.of(enumConstants).filter(x -> x.name().equalsIgnoreCase(input)).findFirst();
if (!value.isPresent()) {
String messageKey;
StringPlaceholders placeholders = StringPlaceholders.builder("enum", this.handledType.getSimpleName()).addPlaceholder("input", input).addPlaceholder("types", Stream.of(enumConstants).map(x -> x.name().toLowerCase()).collect(Collectors.joining(", "))).build();
if (enumConstants.length <= 10) {
messageKey = "argument-handler-enum-list";
} else {
messageKey = "argument-handler-enum";
}
throw new HandledArgumentException(messageKey, placeholders);
}
return value.get();
}
Aggregations