/** * Constructs a {@link PropertiesBuilder} based on a standard * {@link Properties} representation. * <p> * Note: The provided properties are added as default values to the * {@link PropertiesBuilder}. * * @param properties the {@link Properties} to use as the basis for the * {@link PropertiesBuilder} */ public PropertiesBuilder(Properties properties) { this(); for (String key : properties.stringPropertyNames()) { this.properties.put(key, new Property(key, null, properties.getProperty(key))); } }
/** * Removes the specified named property value from {@link PropertiesBuilder}. * <p> * If the specified property is not contained by the {@link PropertiesBuilder}, * nothing happens. If the specified property is defined, only the value * is removed. Its default value will remain defined. * * @param name The name of the property value to remove. */ @Deprecated public void removePropertyValue(String name) { Property property = properties.get(name); if (property != null) { property.setValue(null); } }
/** * Sets the specified named property to use an {@link Iterator}. * (to provide successive requests for the property with values from the said * {@link Iterator} when the {@link PropertiesBuilder} is realized) * * @param name the name of the property * @param iterator an {@link Iterator} that will provide successive property * values for the property when the {@link PropertiesBuilder} * is realized * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used. */ public PropertiesBuilder setProperty(String name, Iterator<?> iterator) { if (containsProperty(name)) { properties.get(name).setValue(iterator); } else { properties.put(name, new Property(name, iterator, null)); } return this; }
/** * Sets the specified named default property to use an {@link Iterator} to * provide successive property values when the {@link PropertiesBuilder} is realized. * * @param name the name of the property * @param defaultIterator the default {@link Iterator} that will provide * successive property values for the property when * the {@link PropertiesBuilder} is realized * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used */ @Deprecated public PropertiesBuilder setDefaultProperty(String name, Iterator<?> defaultIterator) { if (containsProperty(name)) { properties.get(name).setDefaultValue(defaultIterator); } else { properties.put(name, new Property(name, null, defaultIterator)); } return this; }
/** * Sets the specified named default property to have the specified value. * * @param name the name of the property * @param defaultValue the default value of the property * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used */ @Deprecated public PropertiesBuilder setDefaultProperty(String name, Object defaultValue) { if (containsProperty(name)) { properties.get(name).setDefaultValue(defaultValue); } else { properties.put(name, new Property(name, null, defaultValue)); } return this; }
/** * Sets the specified named property to have the specified value. * * @param name the name of the property * @param value the value of the property * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used */ public PropertiesBuilder setProperty(String name, Object value) { if (containsProperty(name)) { properties.get(name).setValue(value); } else { properties.put(name, new Property(name, value, null)); } return this; }
/** * Obtains the current value of the specified property. If the property has * a value specified, that value will be used. If not the default value of * the property will be used. If the property is not known, <code>null</code> * will be returned. * * @param name the name of the property * * @return an {@link Object} */ public Object getProperty(String name) { if (properties.containsKey(name)) { Property property = properties.get(name); return property.hasValue() ? property.getValue() : property.getDefaultValue(); } else { return null; } }
/** * Constructs a {@link PropertiesBuilder} with properties based on a * {@link Map} of name-value pairs. * <p> * Note: The provided properties are added as default values to the * {@link PropertiesBuilder}. * * @param properties the {@link Map} of properties to use as the basis for * the {@link PropertiesBuilder} */ public PropertiesBuilder(Map<String, String> properties) { this(); for (String name : properties.keySet()) { this.properties.put(name, new Property(name, null, properties.get(name))); } }
/** * Constructs a {@link PropertiesBuilder} based on the properties defined * in another {@link PropertiesBuilder}. * * @param propertiesBuilder the {@link PropertiesBuilder} on which to base * the new {@link PropertiesBuilder} */ public PropertiesBuilder(PropertiesBuilder propertiesBuilder) { this(); for (String name : propertiesBuilder.getPropertyNames()) { this.properties.put(name, new Property(propertiesBuilder.properties.get(name))); } }
/** * Constructs a {@link Property} based on another {@link Property}. * * @param property the {@link Property} from which to construct * (copy) the new {@link Property} */ public Property(Property property) { this.name = property.getName(); this.value = property.getValue(); this.defaultValue = property.getDefaultValue(); }