/** * Returns a String explaining the runtime parameter usage. It will take the form * * <pre> * command - description <dataType> [<required>] * </pre> * * @return a String explaining the runtime parameter usage. */ public String getParameterUsageTable() { int minLen = 0; final Collection<ApplicationParameter> params = getParameters(); final HashMap<ApplicationParameter, String> verboseKeys = new HashMap<ApplicationParameter, String>(params.size()); for (ApplicationParameter param : params) { final String[] keys = param.getKeys(); final StringBuilder keyString = new StringBuilder(64); for (int i = 0; i < keys.length; i++) { keyString.append(keys[i]); if (i < keys.length - 1) keyString.append(", "); } verboseKeys.put(param, keyString.toString()); minLen = Math.max(minLen, keyString.length()); } final StringBuilder builder = new StringBuilder(256); for (Iterator<ApplicationParameter> it = params.iterator(); it.hasNext(); ) { final ApplicationParameter param = it.next(); final String str = verboseKeys.get(param); builder.append(str); for (int i = str.length(); i < minLen; i++) builder.append(' '); builder.append(" - ").append(param.getName()); if (param.isRequired()) builder.append("[required]"); builder.append(" (").append(param.getType()).append(')'); if (it.hasNext()) builder.append('\n'); } return builder.toString(); }
/** * Sets the available application parameters. * * @param parameters the available application parameters. */ public void setParameters(final ApplicationParameter... parameters) { _parameterKeyMap.clear(); _parameters.clear(); for (ApplicationParameter param : parameters) { _parameters.put(param.getName(), param); for (String key : param.getKeys()) { if (_parameterKeyMap.containsKey(key)) throw new RuntimeException("Duplicate parameter key: " + key); _parameterKeyMap.put(key, param); } } }