コード例 #1
0
  /**
   * Creates the value for the given option from the given raw value.
   *
   * @param value the value
   * @return the created value
   */
  public static <T> T create(String value, TypedOption<T> option) {
    Objects.requireNonNull(option);
    if (value == null) {
      value = option.getDefaultValue();
    }

    if (value == null) {
      return null;
    }

    try {
      if (option.getConverter() != null) {
        return Converters.create(value, option.getConverter());
      } else {
        return Converters.create(option.getType(), value);
      }
    } catch (Exception e) {
      throw new InvalidValueException(option, value, e);
    }
  }
コード例 #2
0
  /**
   * Creates the value for the given argument from the given raw value.
   *
   * @param value the value
   * @return the created value
   */
  public static <T> T create(String value, TypedArgument<T> argument) {
    Objects.requireNonNull(argument);
    if (value == null) {
      value = argument.getDefaultValue();
    }

    if (value == null) {
      return null;
    }

    try {
      if (argument.getConverter() != null) {
        return Converters.create(value, argument.getConverter());
      } else {
        return Converters.create(argument.getType(), value);
      }
    } catch (Exception e) {
      throw new InvalidValueException(argument, value, e);
    }
  }