Example #1
0
  public static <T extends Enum> T toEnum(Class<T> cls, String value, Enum defaultEnum) {

    T[] enumConstants = cls.getEnumConstants();
    for (T e : enumConstants) {
      if (e.name().equals(value)) {
        return e;
      }
    }

    value = value.toUpperCase().replace('-', '_');
    for (T e : enumConstants) {
      if (e.name().equals(value)) {
        return e;
      }
    }

    value = Str.underBarCase(value);
    for (T e : enumConstants) {
      if (e.name().equals(value)) {
        return e;
      }
    }

    return (T) defaultEnum;
  }
Example #2
0
  private static String _sysProp(String key, Object defaultValue) {
    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);

      if (property == null) {
        String newKey = Str.underBarCase(key);
        property = env.get(newKey);

        if (property == null && defaultValue != DEFAULT_NULL_NOT_EMPTY) {
          property = Conversions.toString(defaultValue);
        }
      }
    }

    return property;
  }
Example #3
0
  public static <T extends Enum> T sysProp(Class<T> cls, String key, T defaultValue) {

    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);
    }

    if (property == null) {
      String newKey = Str.underBarCase(key);
      property = env.get(newKey);
    }

    if (property == null) {
      return defaultValue;
    }

    return Conversions.toEnum(cls, property);
  }
Example #4
0
  public static BigInteger sysPropBigInteger(String key, BigInteger defaultValue) {

    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);
    }

    if (property == null) {
      String newKey = Str.underBarCase(key);
      property = env.get(newKey);
    }

    if (property == null) {
      return defaultValue;
    }

    return Conversions.toBigInteger(property);
  }
Example #5
0
  public static byte sysProp(String key, byte defaultValue) {

    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);
    }

    if (property == null) {
      String newKey = Str.underBarCase(key);
      property = env.get(newKey);
    }

    if (property == null) {
      return defaultValue;
    }

    return Conversions.toByte(property);
  }
Example #6
0
  public static Path sysProp(String key, Path defaultValue) {

    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);
    }

    if (property == null) {
      String newKey = Str.underBarCase(key);
      property = env.get(newKey);
    }

    if (property == null) {
      return defaultValue;
    }

    return IO.path(property);
  }
Example #7
0
  public static File sysProp(String key, File defaultValue) {

    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);
    }

    if (property == null) {
      String newKey = Str.underBarCase(key);
      property = env.get(newKey);
    }

    if (property == null) {
      return defaultValue;
    }

    return new File(property);
  }