Beispiel #1
0
  /**
   * Convenience routine for getting the value of an {@link Option} which is known to be a {@link
   * String}.
   *
   * @param optionName The name of the {@link Option} to fetch.
   * @return A {@link String} if the option holds a {@link String}, returns null otherwise.
   */
  public static String getString(String optionName) {
    // Ensure that the options stash is created
    init();

    String returnValue = null;
    Option<?> opt = get(optionName);
    if (opt != null) {
      if (isArgument(optionName)) {
        if (opt.getValue().size() == 1) {
          Object obj = opt.getValue().get(0);
          if (obj != null && obj instanceof String) {
            returnValue = (String) obj;
          }
        }
      } else if (isEnum(optionName)) {
        if (!opt.isMultiValue()) {
          if (opt.getValue().size() == 1) {
            Object obj = opt.getValue().get(0);
            if (obj != null && obj instanceof String) {
              returnValue = (String) obj;
            }
          }
        }
      }
    }
    return returnValue;
  }
Beispiel #2
0
  /**
   * Convenience routine for finding out if an {@link Option} is a multi-value type or not.
   *
   * @param optionName The name of the {@link Option} to check.
   * @return True if the {@link Option} is a multi-value, false otherwise.
   */
  public static boolean isMultiValue(String optionName) {
    // Ensure that the options stash is created
    init();

    Option<?> opt = get(optionName);
    if (opt != null) {
      return opt.isMultiValue();
    } else {
      return false;
    }
  }