@Override public String remaining() throws ParameterException { try { String value = StringUtil.joinString(arguments, " ", index); markConsumed(); return value; } catch (IndexOutOfBoundsException e) { throw new MissingParameterException(); } }
@Override public Boolean nextBoolean() throws ParameterException { try { return next().equalsIgnoreCase("true"); } catch (IndexOutOfBoundsException e) { if (nonNullBoolean) { // Special case return false; } throw new MissingParameterException(); } }
/** * Get the right {@link ArgumentStack}. * * @param parameter the parameter * @param existing the existing scoped context * @return the context to use */ private static ArgumentStack getScopedContext(Parameter parameter, ArgumentStack existing) { if (parameter.getFlag() != null) { CommandContext context = existing.getContext(); if (parameter.isValueFlag()) { return new StringArgumentStack(context, context.getFlag(parameter.getFlag()), false); } else { String v = context.hasFlag(parameter.getFlag()) ? "true" : "false"; return new StringArgumentStack(context, v, true); } } return existing; }
/** * 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; }
@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) + "'"); } }
@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) + "'"); } }