@Test public void getValidIntegerValue() throws Exception { String key = GlobalConstants.CommonKey.BREAKER_REQUEST_THRESHOLD; int defaultValue = 20; Properties properties = SystemConfig.getProperties(); int threshold = PropertiesUtils.getValidIntegerValue(properties, key, defaultValue); if (threshold <= 0) { threshold = defaultValue; } Assert.assertEquals(defaultValue, threshold); }
public static int getValidIntegerValue(Properties properties, String key, int defaultValue) { if (properties == null) { return defaultValue; } int result = defaultValue; if (properties.containsKey(key)) { String value = properties.getProperty(key); if (value != null) { value = value.trim(); } if (MathUtils.isInteger(value)) { result = Integer.parseInt(value); } } return result; }
PropertiesUtils { public static int getValidIntegerValue(Properties properties, String key, int defaultValue) { if (properties == null) { return defaultValue; } int result = defaultValue; if (properties.containsKey(key)) { String value = properties.getProperty(key); if (value != null) { value = value.trim(); } if (MathUtils.isInteger(value)) { result = Integer.parseInt(value); } } return result; } }
PropertiesUtils { public static int getValidIntegerValue(Properties properties, String key, int defaultValue) { if (properties == null) { return defaultValue; } int result = defaultValue; if (properties.containsKey(key)) { String value = properties.getProperty(key); if (value != null) { value = value.trim(); } if (MathUtils.isInteger(value)) { result = Integer.parseInt(value); } } return result; }  }
PropertiesUtils { public static int getValidIntegerValue(Properties properties, String key, int defaultValue) { if (properties == null) { return defaultValue; } int result = defaultValue; if (properties.containsKey(key)) { String value = properties.getProperty(key); if (value != null) { value = value.trim(); } if (MathUtils.isInteger(value)) { result = Integer.parseInt(value); } } return result; }  static Properties getProperties(String filePath); static int getValidIntegerValue(Properties properties, String key, int defaultValue); static long getValidLongValue(Properties properties, String key, long defaultValue); static double getValidDoubleValue(Properties properties, String key, double defaultValue); static String getStringValue(Properties properties, String key, String defaultValue); static boolean getValidBooleanValue(Properties properties, String key, boolean defaultValue); }
PropertiesUtils { public static int getValidIntegerValue(Properties properties, String key, int defaultValue) { if (properties == null) { return defaultValue; } int result = defaultValue; if (properties.containsKey(key)) { String value = properties.getProperty(key); if (value != null) { value = value.trim(); } if (MathUtils.isInteger(value)) { result = Integer.parseInt(value); } } return result; }  static Properties getProperties(String filePath); static int getValidIntegerValue(Properties properties, String key, int defaultValue); static long getValidLongValue(Properties properties, String key, long defaultValue); static double getValidDoubleValue(Properties properties, String key, double defaultValue); static String getStringValue(Properties properties, String key, String defaultValue); static boolean getValidBooleanValue(Properties properties, String key, boolean defaultValue);  }