/** * Searches for the property with the specified key in this property map. If the key is not found * in this property map, the parent property map, and its parents, recursively, are then checked. * <br/> * If the key maps to any object value, it will be returned as is. If the property is not found, * <code>null</code> will be returned. * * @param key Property key. * @return Object in this property map with the specified key value. */ public final Object getObject(final String key) { return get(key); }
/** * Searches for the property with the specified key in this property map. If the key is not found * in this property map, the parent property map, and its parents, recursively, are then checked. * <br/> * If the key maps to any object value, it will be returned as is. If the property is not found, * <code>null</code> will be returned. * * @param key Key of the property to get from properties. * @return Object in this property map with the specified key value. */ protected synchronized Object get(final String key) { Object value = _map.get(key); if ((value == null) && (_parent != null)) { value = _parent.get(key); } return value; }
/** * Searches for the property with the specified key in this property map. If the key is not found * in this property map, the parent property map, and its parents, recursively, are then checked. * <br/> * If the key maps to a string value that is not empty, it will be returned as is. In all other * cases the given default value will be returned. * * @param key Property key. * @param defaultValue Default value. * @return String value in this property map with the specified key value. */ public final String getString(final String key, final String defaultValue) { Object objectValue = get(key); if ((objectValue instanceof String) && !"".equals(objectValue)) { return (String) objectValue; } return defaultValue; }
/** * Searches for the property with the specified key in this property map. If the key is not found * in this property map, the parent property map, and its parents, recursively, are then checked. * <br/> * If the key maps to a integer value, it will be returned as is. For string values that can be * interpreted as signed decimal integer, the respective integer value will be returned. In all * other cases the given default value will be returned. * * @param key Property key. * @param defaultValue Default value. * @return Integer value in this property map with the specified key value. */ public final int getInteger(final String key, final int defaultValue) { Object objectValue = get(key); if (objectValue instanceof Integer) { return ((Integer) objectValue).intValue(); } else if (objectValue instanceof String) { String stringValue = (String) objectValue; try { return Integer.parseInt(stringValue); } catch (NumberFormatException ex) { return defaultValue; } } return defaultValue; }
/** * Searches for the property with the specified key in this property map. If the key is not found * in this property map, the parent property map, and its parents, recursively, are then checked. * <br/> * If the key maps to a boolean value, it will be returned as is. For string values that are * equal, ignore case, to 'true' or 'false', the respective boolean value will be returned. In all * other cases the given default value will be returned. * * @param key Property key. * @param defaultValue Default value. * @return Boolean value in this property map with the specified key value. */ public final boolean getBoolean(final String key, final boolean defaultValue) { Object objectValue = get(key); if (objectValue instanceof Boolean) { return ((Boolean) objectValue).booleanValue(); } else if (objectValue instanceof String) { String stringValue = (String) objectValue; if ("true".equalsIgnoreCase(stringValue)) { return true; } else if ("false".equalsIgnoreCase(stringValue)) { return false; } } return defaultValue; }
/** * Searches for the property with the specified key in this property map. If the key is not found * in this property map, the parent property map, and its parents, recursively, are then checked. * <br/> * If the key maps to a string array, it will be returned as is. A simple string will be converted * into a string array by splitting it into substrings at every occurence of ',' character. If the * property is not found, <code>null</code> will be returned. For all other types a * PropertiesException will be thrown. * * @param key Property key. * @return String array in this property map with the specified key value. */ public final String[] getStringArray(final String key) { Object objectValue = get(key); if (objectValue == null) { return null; } else if (objectValue instanceof String[]) { return (String[]) objectValue; } else if (objectValue instanceof String) { return StringUtils.split((String) objectValue, ','); } Object[] args = new Object[] {key, objectValue}; String msg = "Properties value is not a String[]: {0}={1}"; throw new PropertiesException(MessageFormat.format(msg, args)); }
/** * Searches for the property with the specified key in this property map. If the key is not found * in this property map, the parent property map, and its parents, recursively, are then checked. * <br/> * If the key maps to a string value, it will be returned as is. If the property is not found, * <code>null</code> will be returned. For all other types a PropertiesException will be thrown. * * @param key Property key. * @return String value in this property map with the specified key value. */ public final String getString(final String key) { Object objectValue = get(key); if (objectValue == null) { return null; } else if (objectValue instanceof String) { return (String) objectValue; } Object[] args = new Object[] {key, objectValue}; String msg = "Properties value is not a string: {0}={1}"; throw new PropertiesException(MessageFormat.format(msg, args)); }
Object objectValue = get(key);
Object objectValue = get(key);
Object objectValue = get(key);
Object objectValue = get(key);
Object objectValue = get(key);