/** * Check to see if all arguments, including flag arguments, were consumed. * * @param scoped the argument scope * @throws UnconsumedParameterException thrown if parameters were not consumed */ private void checkUnconsumed(ContextArgumentStack scoped) throws UnconsumedParameterException { CommandContext context = scoped.getContext(); String unconsumed; String unconsumedFlags = getUnusedFlags(context); if ((unconsumed = scoped.getUnconsumed()) != null) { throw new UnconsumedParameterException(unconsumed + " " + unconsumedFlags); } if (unconsumedFlags != null) { throw new UnconsumedParameterException(unconsumedFlags); } }
@Override public Boolean nextBoolean() throws ParameterException { try { return next().equalsIgnoreCase("true"); } catch (IndexOutOfBoundsException e) { throw new MissingParameterException(); } }
CommandContext context = scoped.getContext(); ParameterData parameter = parameters[i]; return !parameter.isValueFlag() || context.hasFlag(parameter.getFlag()); } else { int numberFree = context.argsLength() - scoped.position(); for (int j = i; j < parameters.length; j++) { if (parameters[j].isNonFlagConsumer() && !parameters[j].isOptional()) {
/** * Get the default value for a parameter. * * @param i the index of the parameter * @param scoped the scoped context * @return a value * @throws ParameterException on an error * @throws CommandException on an error */ private Object getDefaultValue(int i, ContextArgumentStack scoped) throws ParameterException, CommandException, InvocationTargetException { CommandContext context = scoped.getContext(); ParameterData parameter = parameters[i]; String[] defaultValue = parameter.getDefaultValue(); if (defaultValue != null) { try { return parameter.getBinding().bind(parameter, new StringArgumentStack(context, defaultValue, false), false); } catch (MissingParameterException e) { throw new ParametricException( "The default value of the parameter using the binding " + parameter.getBinding().getClass() + " in the method\n" + method.toGenericString() + "\nis invalid"); } } return null; }
ContextArgumentStack arguments = new ContextArgumentStack(context); ParameterData parameter = null;
@Override public Integer nextInt() throws ParameterException { try { return Integer.parseInt(next()); } catch (NumberFormatException e) { throw new ParameterException( "Expected a number, got '" + context.getString(index - 1) + "'"); } }
@Override public Double nextDouble() throws ParameterException { try { return Double.parseDouble(next()); } catch (NumberFormatException e) { throw new ParameterException( "Expected a number, got '" + context.getString(index - 1) + "'"); } }