private Integer parseBoolean(String value) { boolean v = ConfigurationParseHelper.parseBoolean( value, "Invalid value for " + cfgKey + ": " + value ); return v ? TRUE : FALSE; }
private Integer parseBoolean(String value) { boolean v = ConfigurationParseHelper.parseBoolean( value, "Invalid value for " + cfgKey + ": " + value ); return v ? TRUE : FALSE; }
/** * Extracts a boolean value from configuration properties * * @param cfg configuration Properties * @param key the property key * @param defaultValue a boolean. * @return the defaultValue if the property was not defined * @throws SearchException for invalid format or values. */ public static final boolean getBooleanValue(Properties cfg, String key, boolean defaultValue) { String propValue = cfg.getProperty( key ); if ( propValue == null ) { return defaultValue; } else { return parseBoolean( propValue, "Property '" + key + "' needs to be either literal 'true' or 'false'" ); } }
/** * Extracts a boolean value from configuration properties * * @param cfg configuration Properties * @param key the property key * @param defaultValue a boolean. * @return the defaultValue if the property was not defined * @throws SearchException for invalid format or values. */ public static final boolean getBooleanValue(Properties cfg, String key, boolean defaultValue) { String propValue = cfg.getProperty( key ); if ( propValue == null ) { return defaultValue; } else { return parseBoolean( propValue, "Property '" + key + "' needs to be either literal 'true' or 'false'" ); } }
@Test public void testBooleanParsers() { assertTrue( ConfigurationParseHelper.parseBoolean( "true", null ) ); assertTrue( ConfigurationParseHelper.parseBoolean( " True ", null ) ); assertFalse( ConfigurationParseHelper.parseBoolean( "false", null ) ); assertFalse( ConfigurationParseHelper.parseBoolean( " False ", null ) ); boolean exceptionLaunched = false; try { ConfigurationParseHelper.parseBoolean( "5", "error" ); } catch (SearchException e) { exceptionLaunched = true; } assertTrue( exceptionLaunched ); exceptionLaunched = false; try { ConfigurationParseHelper.parseBoolean( null, "error" ); } catch (SearchException e) { exceptionLaunched = true; } assertTrue( exceptionLaunched ); }