@Override
public <T> T apply(Object... args) throws VerbException {
int currentArgCount = (args == null)? 0 : args.length;
int minimumArgCount = verbDefinition.getMinimumArgCount();
if(currentArgCount < minimumArgCount){
throw new VerbException("Verb["+name+"] expected at least "+ minimumArgCount + " arguments but was invoked with "+currentArgCount+": " + Arrays.toString(args));
}
int maximumArgCount = verbDefinition.getMaximumArgCount();
if(currentArgCount > maximumArgCount){
throw new VerbException("Verb["+name+"] expected at most "+ maximumArgCount + " arguments but was invoked with "+currentArgCount+": " + Arrays.toString(args));
}
try {
return verbDefinition.apply(args);
} catch (ClassCastException e) {
throw new VerbException("Verb["+name+"] failed with ClassCastException. Do argument values match expected types? "+e.getMessage()+ ". Args: " + Arrays.toString(args));
}
}