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; } }
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); } }
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; }
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; } }
public boolean hasCfg(String key) { String s = properties.getProperty(key); return s != null && s.trim().length() > 0; }
public String stringCfg(String key, String defval) { String s = properties.getProperty(key); return s != null ? s.trim() : defval; }