예제 #1
0
  public Long kiloCfg(String key, Long defval) {
    String s = properties.getProperty(key);

    long multi = 1L;

    if (s != null) {
      Matcher matcher = kiloRe.matcher(s);

      if (matcher.matches()) {
        s = matcher.group(1);
        multi = kilos.get(matcher.group(2));
      }
    }

    try {
      if (s != null) {
        return Long.parseLong(s.trim()) * multi;
      } else {
        return defval;
      }
    } catch (NumberFormatException e) {
      log.error(
          "Cannot parse key '"
              + key
              + "' -> '"
              + s
              + "'. Returning default value of "
              + defval
              + ".",
          e);
      return defval;
    }
  }
예제 #2
0
  protected List<String> listCfg(Properties properties, String key, String... defVals) {
    String s = properties.getProperty(key);

    if (s != null) {
      String[] ss = s.split(",");
      List<String> lst = new ArrayList<String>(ss.length);
      for (String str : ss) {
        str = str.trim();
        if (str.length() > 0) {
          lst.add(str);
        }
      }
      return lst;
    } else {
      return Arrays.asList(defVals);
    }
  }
예제 #3
0
  public Boolean boolCfg(String key, Boolean defval) {
    String s = properties.getProperty(key);

    if (s != null) {
      s = s.trim();

      if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase(("yes"))) {
        return true;
      } else if (s.equalsIgnoreCase("false") || s.equalsIgnoreCase("no")) {
        return false;
      } else {
        log.error(
            "Invalid value for '" + key + "' -> '" + s + "'. Setting default value of '" + defval);
      }
    }

    return defval;
  }
예제 #4
0
  public Integer intCfg(String key, Integer defval) {
    String s = properties.getProperty(key);

    try {
      if (s != null) {
        return Integer.parseInt(s.trim());
      } else {
        return defval;
      }
    } catch (NumberFormatException e) {
      log.error(
          "Cannot parse key '"
              + key
              + "' -> '"
              + s
              + "'. Returning default value of "
              + defval
              + ".",
          e);
      return defval;
    }
  }
예제 #5
0
  public boolean hasCfg(String key) {
    String s = properties.getProperty(key);

    return s != null && s.trim().length() > 0;
  }
예제 #6
0
  public String stringCfg(String key, String defval) {
    String s = properties.getProperty(key);

    return s != null ? s.trim() : defval;
  }