public final class EditableProperties extends AbstractMap<String,String> implements Cloneable
Properties
but designed to retain additional
information needed for safe hand-editing.
Useful for various *.properties in a project:
Collections.synchronizedMap(java.util.Map<K, V>)
.
This class exists here only for historical reasons. It delegates to EditableProperties
.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
EditableProperties()
Deprecated.
Use
EditableProperties.EditableProperties(boolean) for clarity instead. |
EditableProperties(boolean alphabetize)
Creates empty instance.
|
EditableProperties(Map<String,String> map)
Creates instance from an existing map.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone() |
EditableProperties |
cloneProperties()
Create an exact copy of this properties object.
|
Set<Map.Entry<String,String>> |
entrySet()
Returns a set view of the mappings ordered according to their file
position.
|
String |
get(Object key) |
String[] |
getComment(String key)
Returns comment associated with the property.
|
String |
getProperty(String key)
Convenience method to get a property as a string.
|
void |
load(InputStream stream)
Load properties from a stream.
|
String |
put(String key,
String value) |
void |
setComment(String key,
String[] comment,
boolean separate)
Create comment for the property.
|
String |
setProperty(String key,
String value)
Convenience method to set a property.
|
String |
setProperty(String key,
String[] value)
Sets a property to a value broken into segments for readability.
|
void |
store(OutputStream stream)
Store properties to a stream.
|
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, remove, size, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
@Deprecated public EditableProperties()
EditableProperties.EditableProperties(boolean)
for clarity instead.public EditableProperties(boolean alphabetize)
alphabetize
- alphabetize new items according to key or notpublic Set<Map.Entry<String,String>> entrySet()
AbstractMap.entrySet()
for more details.public void load(InputStream stream) throws IOException
stream
- an input streamIOException
- if the contents are malformed or the stream could not be readpublic void store(OutputStream stream) throws IOException
stream
- an output streamIOException
- if the stream could not be written topublic String getProperty(String key)
EditableProperties.get(java.lang.Object)
; only here because of pre-generic code.key
- a property name; cannot be null nor emptypublic String setProperty(String key, String value)
EditableProperties.put(java.lang.String, java.lang.String)
; only here because of pre-generic code.key
- a property name; cannot be null nor emptyvalue
- the desired value; cannot be nullpublic String setProperty(String key, String[] value)
EditableProperties.setProperty(String,String)
with the difference that each item
will be stored on its own line of text. EditableProperties.getProperty(java.lang.String)
will simply concatenate
all the items into one string, so generally separators
(such as : for path-like properties) must be included in
the items (for example, at the end of all but the last item).key
- a property name; cannot be null nor emptyvalue
- the desired value; cannot be null; can be empty arraypublic String[] getComment(String key)
key
- a property name; cannot be null nor emptypublic void setComment(String key, String[] comment, boolean separate)
Note: if a comment includes non-ISO-8859-1 characters, they will be written
to disk using Unicode escapes (and EditableProperties.getComment(java.lang.String)
will interpret
such escapes), but of course they will be unreadable for humans.
key
- a property name; cannot be null nor emptycomment
- lines of comment which will be written just above
the property; no reformatting; comment lines must start with
comment delimiter; cannot be null; cannot be emty arrayseparate
- whether the comment should be separated from previous
item by empty linepublic Object clone()
clone
in class AbstractMap<String,String>
public EditableProperties cloneProperties()