Config
, Serializable
public interface Mutable extends Config
Allows a Config
object to change its property values at runtime.
Example:
public interface MyConfig extends Config, Mutable { @DefaultValue("18") int minAge(); } public void example() { MyConfig cfg = ConfigFactory.create(MyConfig.class); int before = cfg.minAge(); // before = 18 int old = cfg.setProperty("minAge", "21"); // old = 18 int after = cfg.minAge(); // after = 21 int old2 = cfg.removeProperty("minAge"); // old2 = 21 int end = cfg.minAge(); // end = null }
Config.ConverterClass, Config.DecryptorClass, Config.DefaultValue, Config.DisableableFeature, Config.DisableFeature, Config.EncryptedValue, Config.HotReload, Config.HotReloadType, Config.Key, Config.LoadPolicy, Config.LoadType, Config.PreprocessorClasses, Config.Separator, Config.Sources, Config.TokenizerClass
Modifier and Type | Method | Description |
---|---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener) |
Adds a
PropertyChangeListener to the Mutable interface. |
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener) |
Adds a PropertyChangeListener to the listener list for a specific
property.
|
void |
clear() |
Clears all properties.
|
void |
load(InputStream inStream) |
Reads a property list (key and element pairs) from the input byte stream.
|
void |
load(Reader reader) |
Reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.
|
String |
removeProperty(String key) |
Removes a given property.
|
void |
removePropertyChangeListener(PropertyChangeListener listener) |
Removes a
PropertyChangeListener from the Mutable interface. |
String |
setProperty(String key,
String value) |
Sets a given property to the specified value.
|
String setProperty(String key, String value)
Sets a given property to the specified value.
Differently than Properties.setProperty(String, String)
, if key
is set to null
then this call is
equivalent to removeProperty(String)
.
key
- the key to be placed into the property list.value
- the value corresponding to key
, or null
if the property must be removed.null
if it did not have one.String removeProperty(String key)
key
- the key of the property to remove.null
if it did not have one.Hashtable.remove(Object)
void clear()
void load(InputStream inStream) throws IOException
inStream
- the input stream.IOException
- if an error occurred when reading from the input stream.IllegalArgumentException
- if the input stream contains a malformed Unicode escape sequence.Properties.load(java.io.InputStream)
void load(Reader reader) throws IOException
reader
- the input character stream.IOException
- if an error occurred when reading from the input stream.IllegalArgumentException
- if a malformed Unicode escape appears in the input.Properties.load(java.io.Reader)
void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
to the Mutable interface.listener
- the listener to be added.void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
from the Mutable interface.listener
- the property change listener to be removedvoid addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
propertyName
or listener
is null
,
no exception is thrown and no action is taken.propertyName
- one of the property names listed abovelistener
- the property change listener to be addedCopyright © 2012–2020 Luigi R. Viggiano. All rights reserved.