Ejemplo n.º 1
0
  @Override
  @SuppressWarnings("unchecked")
  public <T extends Enum<T>> T promptEnum(final String message, final Class<T> type) {
    String value = "";
    while ((value == null) || value.trim().isEmpty()) {
      value = promptWithCompleter(message, new CompleterAdaptor(new EnumCompleter(type)));
    }

    T result = (T) Enums.valueOf(type, value.trim());
    if (result == null) {
      result = promptChoiceTyped(message, Arrays.asList(type.getEnumConstants()));
    }
    return result;
  }
Ejemplo n.º 2
0
  @Override
  @SuppressWarnings("unchecked")
  public <T extends Enum<T>> T promptEnum(
      final String message, final Class<T> type, final T defaultIfEmpty) {
    T result;
    do {
      String query = " [" + defaultIfEmpty + "] ";
      String value =
          promptWithCompleter(message + query, new CompleterAdaptor(new EnumCompleter(type)));

      if ((value == null) || value.trim().isEmpty()) {
        result = defaultIfEmpty;
      } else {
        result = (T) Enums.valueOf(type, value.trim());
        if (result == null) {
          result =
              promptChoiceTyped(
                  message + query, Arrays.asList(type.getEnumConstants()), defaultIfEmpty);
        }
      }
    } while (result == null);

    return result;
  }