@Test public void testGetBooleanDefaultValueWithWrongValue() { System.setProperty("key", "abc"); assertTrue(SystemPropertyUtil.getBoolean("key", true)); System.setProperty("key", "123"); assertFalse(SystemPropertyUtil.getBoolean("key", false)); }
public static boolean getBoolean(String key, boolean def) { String value = get(key); if (value == null) { return def; } value = value.trim().toLowerCase(); if (value.isEmpty()) { return def; } if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) { return true; } if ("false".equals(value) || "no".equals(value) || "0".equals(value)) { return false; } logger.warn( "Unable to parse the boolean system property '{}':{} - using the default value: {}", key, value, def ); return def; }
SystemPropertyUtil { public static boolean getBoolean(String key, boolean def) { String value = get(key); if (value == null) { return def; } value = value.trim().toLowerCase(); if (value.isEmpty()) { return def; } if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) { return true; } if ("false".equals(value) || "no".equals(value) || "0".equals(value)) { return false; } logger.warn( "Unable to parse the boolean system property '{}':{} - using the default value: {}", key, value, def ); return def; } }
SystemPropertyUtil { public static boolean getBoolean(String key, boolean def) { String value = get(key); if (value == null) { return def; } value = value.trim().toLowerCase(); if (value.isEmpty()) { return def; } if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) { return true; } if ("false".equals(value) || "no".equals(value) || "0".equals(value)) { return false; } logger.warn( "Unable to parse the boolean system property '{}':{} - using the default value: {}", key, value, def ); return def; } private  SystemPropertyUtil(); }
SystemPropertyUtil { public static boolean getBoolean(String key, boolean def) { String value = get(key); if (value == null) { return def; } value = value.trim().toLowerCase(); if (value.isEmpty()) { return def; } if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) { return true; } if ("false".equals(value) || "no".equals(value) || "0".equals(value)) { return false; } logger.warn( "Unable to parse the boolean system property '{}':{} - using the default value: {}", key, value, def ); return def; } private  SystemPropertyUtil(); static boolean contains(String key); static String get(String key); static String get(final String key, String def); static boolean getBoolean(String key, boolean def); static int getInt(String key, int def); static long getLong(String key, long def); }
SystemPropertyUtil { public static boolean getBoolean(String key, boolean def) { String value = get(key); if (value == null) { return def; } value = value.trim().toLowerCase(); if (value.isEmpty()) { return def; } if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) { return true; } if ("false".equals(value) || "no".equals(value) || "0".equals(value)) { return false; } logger.warn( "Unable to parse the boolean system property '{}':{} - using the default value: {}", key, value, def ); return def; } private  SystemPropertyUtil(); static boolean contains(String key); static String get(String key); static String get(final String key, String def); static boolean getBoolean(String key, boolean def); static int getInt(String key, int def); static long getLong(String key, long def);  }