public class ConstrainedMap extends Object implements Map<String,Object>, Iterable<ConstrainedMap.Entry<?>>
MapMetaData.Builder
class.
Example of usage:
MapMetaData.Builder builder = new MapMetaData.Builder(); builder.property(...) .property(...) .property(...); MapMetaData metadata = builder.build(); new ConstrainedMap(ValidatorFactory.getDefault().newValidator(metadata));
ConstrainedMap
is thread-safe. It makes this map useful for
maintaining configurations in the multi-threaded environment. The method
newTransaction()
allows to change map values in transactional way
and keep integrity.
Validator
Modifier and Type | Class and Description |
---|---|
class |
ConstrainedMap.Entry<V>
This map entry holds metadata information and provides advanced
operations.
|
class |
ConstrainedMap.Transaction
This class allows to perform modification operations of this map on a
snapshot that is created at the moment of construction of the
transaction.
|
Constructor and Description |
---|
ConstrainedMap(Validator<Map<String,Object>> validator)
Constructs a new
ConstrainedMap with the specified
validator of map entries. |
Modifier and Type | Method and Description |
---|---|
void |
addListener(PropertyChangeListener listener)
Adds the specified listener to receive value change events from this map.
|
void |
clear()
Resets all the values of this map to its default values.
|
boolean |
containsKey(Object key)
Determines if this map contains an entry for the specified key.
|
boolean |
containsValue(Object value)
Determines if this map contains one or more keys with the specified
value.
|
protected Map<String,String> |
doLoad(BufferedReader in)
Reads a key-value pairs from the specified input character stream in a
simple line-oriented format.
|
protected void |
doSave(BufferedWriter out,
Locale locale,
String comment)
Writes a key-value pairs from this map to the specified output character
stream in a simple line-oriented format.
|
Set<Map.Entry<String,Object>> |
entrySet()
Returns set view of the entries contained in this map.
|
boolean |
equals(Object obj)
Determines if this map equals to the specified one.
|
Object |
get(Object key)
Returns value to which the specified key is mapped.
|
<V> ConstrainedMap.Entry<V> |
getEntry(String key)
Returns map entry for the specified key.
|
String |
getLocalizedValue(Object key)
Returns localized string representation of value to which the specified
key is mapped.
|
String |
getLocalizedValue(Object key,
Locale locale)
Returns localized string representation of value to which the specified
key is mapped.
|
Map<String,String> |
getLocalizedValues()
Returns localized string representations of this map values.
|
Map<String,String> |
getLocalizedValues(Locale locale)
Returns localized string representations of this map values.
|
String |
getRawValue(Object key)
Returns default string representation of value to which the specified
key is mapped.
|
Map<String,String> |
getRawValues()
Returns default string representations of this map values.
|
Validator<Map<String,Object>> |
getValidator()
Returns validator of this map.
|
<V> V |
getValue(Object key)
Returns value to which the specified key is mapped.
|
Map<String,Object> |
getValues()
Returns a snapshot of this map.
|
int |
hashCode()
Returns a hash code value for this map.
|
boolean |
isEmpty()
Determines if this map contains no entries.
|
Iterator<ConstrainedMap.Entry<?>> |
iterator()
Returns iterator of the map entries.
|
Iterator<ConstrainedMap.Entry<?>> |
iterator(PropertyFilter filter)
Returns iterator of the map entries with the specified property filter.
|
Set<String> |
keySet()
Returns set view of the keys contained in this map.
|
ConstrainedMap |
load(File file)
Loads this map values from the specified file.
|
ConstrainedMap |
load(File file,
Locale locale)
Loads this map values from the specified file.
|
ConstrainedMap |
load(InputStream stream)
Loads this map values from the specified input stream.
|
ConstrainedMap |
load(InputStream stream,
Locale locale)
Loads this map values from the specified input stream.
|
ConstrainedMap |
load(Reader reader)
Loads this map values from the specified input character stream.
|
ConstrainedMap |
load(Reader reader,
Locale locale)
Loads this map values from the specified input character stream.
|
ConstrainedMap.Transaction |
newTransaction()
Creates a new transaction initialized with default locale.
|
ConstrainedMap.Transaction |
newTransaction(Locale locale)
Creates a new transaction initialized with the specified locale.
|
Object |
put(String key,
Object value)
Assigns the specified value for the specified key in this map.
|
void |
putAll(Map<? extends String,? extends Object> values)
Assigns the specified map values to this map values.
|
Object |
remove(Object key)
Resets value of the specified key to its default value.
|
void |
removeListener(PropertyChangeListener listener)
Removes the specified listener so that it no longer receives events from
this map.
|
Object |
resetValue(Object key)
Resets value of the specified key to its default value.
|
Object |
resetValue(Object key,
Locale locale)
Resets value of the specified key to its default value.
|
void |
resetValues()
Resets all the values of this map to its default values.
|
void |
resetValues(Locale locale)
Resets all the values of this map to its default values.
|
ConstrainedMap |
save(File file,
Locale locale,
String comment)
Saves this map key-value pairs to the specified file.
|
ConstrainedMap |
save(File file,
String comment)
Saves this map key-value pairs to the specified file.
|
ConstrainedMap |
save(OutputStream stream,
Locale locale,
String comment)
Saves this map key-value pairs to the specified output stream.
|
ConstrainedMap |
save(OutputStream stream,
String comment)
Saves this map key-value pairs to the specified output stream.
|
ConstrainedMap |
save(Writer writer,
Locale locale,
String comment)
Saves this map key-value pairs to the specified output character stream.
|
ConstrainedMap |
save(Writer writer,
String comment)
Saves this map key-value pairs to the specified output character stream.
|
Object |
setLocalizedValue(Object key,
String value)
Assigns the specified value for the specified key in this map.
|
Object |
setLocalizedValue(Object key,
String value,
Locale locale)
Assigns the specified value for the specified key in this map.
|
void |
setLocalizedValues(Map<String,String> values)
Assigns the specified map values to this map values.
|
void |
setLocalizedValues(Map<String,String> values,
Locale locale)
Assigns the specified map values to this map values.
|
Object |
setRawValue(Object key,
String value)
Assigns the specified value for the specified key in this map.
|
Object |
setRawValue(Object key,
String value,
Locale locale)
Assigns the specified value for the specified key in this map.
|
void |
setRawValues(Map<String,String> values)
Assigns the specified map values to this map values.
|
void |
setRawValues(Map<String,String> values,
Locale locale)
Assigns the specified map values to this map values.
|
<V> V |
setValue(Object key,
Object value)
Assigns the specified value for the specified key in this map.
|
<V> V |
setValue(Object key,
Object value,
Locale locale)
Assigns the specified value for the specified key in this map.
|
void |
setValues(Map<String,Object> values)
Assigns the specified map values to this map values.
|
void |
setValues(Map<String,Object> values,
Locale locale)
Assigns the specified map values to this map values.
|
int |
size()
Returns the number of entries in this map.
|
String |
toString()
Returns string representing this map.
|
Collection<Object> |
values()
Returns collection view of the values contained in this map.
|
protected static void |
writeComment(BufferedWriter out,
String comment)
Writes the specified comment to the specified output character stream.
|
protected static void |
writeKey(BufferedWriter out,
String key)
Writes the entry key to the specified output character stream.
|
protected static void |
writeValue(BufferedWriter out,
String value)
Writes the entry value to the specified output character stream.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
forEach, spliterator
public final Validator<Map<String,Object>> getValidator()
public final int size()
size
in interface Map<String,Object>
Map.size()
public final boolean isEmpty()
isEmpty
in interface Map<String,Object>
true
if this map contains no entries;
false
otherwise.Map.isEmpty()
public final boolean containsKey(Object key)
containsKey
in interface Map<String,Object>
key
- Key whose presence in this map to be tested.true
if this map contains an entry for the
specified key; false
otherwise.Map.containsKey(Object)
public final boolean containsValue(Object value)
containsValue
in interface Map<String,Object>
value
- Value whose presence in this map to be tested.true
if this map contains one or more keys with the
specified value; false
otherwise.Map.containsValue(Object)
public final Object get(Object key)
get
in interface Map<String,Object>
key
- Key whose associated value to be returned.IllegalArgumentException
- if this map contains no entry for the
specified key.Map.get(Object)
,
getValue(Object)
public final Object put(String key, Object value)
put
in interface Map<String,Object>
key
- Key for which the specified value to be assigned.value
- Value to be assigned for the specified key.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.Map.put(Object, Object)
,
setValue(Object, Object)
public final Object remove(Object key)
remove
in interface Map<String,Object>
key
- Key for which the specified value to be reseted.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.Map.remove(Object)
,
resetValue(Object)
public final void putAll(Map<? extends String,? extends Object> values)
putAll
in interface Map<String,Object>
values
- Values to be stored in this map.ValidationException
- if violations occured.Map.putAll(Map)
,
setValues(Map)
public final void clear()
clear
in interface Map<String,Object>
ValidationException
- if violations occured.Map.clear()
,
resetValues()
public final <V> ConstrainedMap.Entry<V> getEntry(String key)
V
- The value type.key
- Key for which entry to be returned.IllegalArgumentException
- if this map contains no entry for the
specified key.public final <V> V getValue(Object key)
V
- The value type.key
- Key whose associated value to be returned.IllegalArgumentException
- if this map contains no entry for the
specified key.public final <V> V setValue(Object key, Object value)
V
- The value type.key
- Key for which the specified value to be assigned.value
- Value to be assigned for the specified key.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.setValue(Object, Object, Locale)
public final <V> V setValue(Object key, Object value, Locale locale)
V
- The value type.key
- Key for which the specified value to be assigned.value
- Value to be assigned for the specified key.locale
- Locale to be used for error messages.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.ConstrainedMap.Entry.setValue(Object, Locale)
public final String getRawValue(Object key)
key
- Key whose associated default string representation of value
to be returned.IllegalArgumentException
- if this map contains no entry for the
specified key.ConstrainedMap.Entry.getRawValue()
public final Object setRawValue(Object key, String value)
key
- Key for which the specified value to be assigned.value
- Default string representation of value to be assigned for
the specified key.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.setRawValue(Object, String, Locale)
public final Object setRawValue(Object key, String value, Locale locale)
key
- Key for which the specified value to be assigned.value
- Default string representation of value to be assigned for
the specified key.locale
- Locale to be used for error messages.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.ConstrainedMap.Entry.setRawValue(String, Locale)
public final String getLocalizedValue(Object key)
key
- Key whose associated localized string representation of value
to be returned.IllegalArgumentException
- if this map contains no entry for the
specified key.getLocalizedValue(Object, Locale)
public final String getLocalizedValue(Object key, Locale locale)
key
- Key whose associated localized string representation of value
to be returned.locale
- Desired locale.IllegalArgumentException
- if this map contains no entry for the
specified key.ConstrainedMap.Entry.getLocalizedValue(Locale)
public final Object setLocalizedValue(Object key, String value)
key
- Key for which the specified value to be assigned.value
- Localized string representation of value to be assigned for
the specified key.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.setLocalizedValue(Object, String, Locale)
public final Object setLocalizedValue(Object key, String value, Locale locale)
key
- Key for which the specified value to be assigned.value
- Localized string representation of value to be assigned for
the specified key.locale
- Desired locale.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.ConstrainedMap.Entry.setLocalizedValue(String, Locale)
public final Object resetValue(Object key)
key
- Key for which the specified value to be reseted.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.resetValue(Object, Locale)
public final Object resetValue(Object key, Locale locale)
key
- Key for which the specified value to be reseted.locale
- Locale to be used for error messages.IllegalArgumentException
- if this map contains no entry for the
specified key.ValidationException
- if violations occured.ConstrainedMap.Entry.resetValue(Locale)
public final Map<String,Object> getValues()
public final void setValues(Map<String,Object> values)
values
- Values to be stored in this map.ValidationException
- if violations occured.setValues(Map, Locale)
public final void setValues(Map<String,Object> values, Locale locale)
values
- Values to be stored in this map.locale
- Locale to be used for error messages.ValidationException
- if violations occured.ConstrainedMap.Transaction.setValues(Map)
public final Map<String,String> getRawValues()
public final void setRawValues(Map<String,String> values)
values
- Default string representations of values to be stored in
this map.ValidationException
- if violations occured.setRawValues(Map, Locale)
public final void setRawValues(Map<String,String> values, Locale locale)
values
- Default string representations of values to be stored in
this map.locale
- Locale to be used for error messages.ValidationException
- if violations occured.ConstrainedMap.Transaction.setRawValues(Map)
public final Map<String,String> getLocalizedValues()
getLocalizedValues(Locale)
public final Map<String,String> getLocalizedValues(Locale locale)
locale
- Desired locale.public final void setLocalizedValues(Map<String,String> values)
values
- Localized string representations of values to be stored in
this map.ValidationException
- if violations occured.setLocalizedValues(Map, Locale)
public final void setLocalizedValues(Map<String,String> values, Locale locale)
values
- Localized string representations of values to be stored in
this map.locale
- Desired locale.ValidationException
- if violations occured.ConstrainedMap.Transaction.setLocalizedValues(Map)
public final void resetValues()
ValidationException
- if violations occured.resetValues(Locale)
public final void resetValues(Locale locale)
locale
- Locale to be used for error messages.ValidationException
- if violations occured.ConstrainedMap.Transaction.resetValues()
public final ConstrainedMap.Transaction newTransaction()
newTransaction(Locale)
public final ConstrainedMap.Transaction newTransaction(Locale locale)
locale
- Locale to be used for error messages and value conversions
into and from string representation.public final Set<String> keySet()
keySet
in interface Map<String,Object>
Map.keySet()
public final Collection<Object> values()
values
in interface Map<String,Object>
Map.values()
public final Set<Map.Entry<String,Object>> entrySet()
entrySet
in interface Map<String,Object>
Map.entrySet()
public final Iterator<ConstrainedMap.Entry<?>> iterator()
iterator
in interface Iterable<ConstrainedMap.Entry<?>>
public final Iterator<ConstrainedMap.Entry<?>> iterator(PropertyFilter filter)
filter
- Filter to be used for filtering entries.public int hashCode()
public boolean equals(Object obj)
public String toString()
public ConstrainedMap load(File file) throws IOException
file
- File from which to read the values.IOException
- if an error occurred when reading from the file.ValidationException
- if violations occur.load(File, Locale)
public ConstrainedMap load(File file, Locale locale) throws IOException
file
- File from which to read the values.locale
- Locale to be used for error messages.IOException
- if an error occurred when reading from the file.ValidationException
- if violations occur.load(Reader, Locale)
public ConstrainedMap load(InputStream stream) throws IOException
stream
- Input stream from which to read the values.IOException
- if an error occurred when reading from the stream.ValidationException
- if violations occur.load(InputStream, Locale)
public ConstrainedMap load(InputStream stream, Locale locale) throws IOException
stream
- Input stream from which to read the values.locale
- Locale to be used for error messages.IOException
- if an error occurred when reading from the stream.ValidationException
- if violations occur.load(Reader, Locale)
public ConstrainedMap load(Reader reader) throws IOException
reader
- Input character stream from which to read the values.IOException
- if an error occurred when reading from the stream.ValidationException
- if violations occur.load(Reader, Locale)
public ConstrainedMap load(Reader reader, Locale locale) throws IOException
reader
- Input character stream from which to read the values.locale
- Locale to be used for error messages.IOException
- if an error occurred when reading from the stream.ValidationException
- if violations occur.doLoad(BufferedReader)
protected Map<String,String> doLoad(BufferedReader in) throws IOException
in
- Input character stream.IOException
- if an error occurred when reading from the stream.public ConstrainedMap save(File file, String comment) throws IOException
file
- File to which to write the key-value pairs.comment
- A comment to be written in the first line.IOException
- if an error occurred when writing to the file.save(File, Locale, String)
public ConstrainedMap save(File file, Locale locale, String comment) throws IOException
file
- File to which to write the key-value pairs.locale
- Locale to be used for comments of key-value pairs.comment
- A comment to be written in the first line.IOException
- if an error occurred when writing to the file.save(Writer, Locale, String)
public ConstrainedMap save(OutputStream stream, String comment) throws IOException
stream
- Output stream to which to write the key-value pairs.comment
- A comment to be written in the first line.IOException
- if an error occurred when writing to the stream.save(OutputStream, Locale, String)
public ConstrainedMap save(OutputStream stream, Locale locale, String comment) throws IOException
stream
- Output stream to which to write the key-value pairs.locale
- Locale to be used for comments of key-value pairs.comment
- A comment to be written in the first line.IOException
- if an error occurred when writing to the stream.save(Writer, Locale, String)
public ConstrainedMap save(Writer writer, String comment) throws IOException
writer
- Output character stream to which to write the key-value pairs.comment
- A comment to be written in the first line.IOException
- if an error occurred when writing to the stream.save(Writer, Locale, String)
public ConstrainedMap save(Writer writer, Locale locale, String comment) throws IOException
writer
- Output character stream to which to write the key-value pairs.locale
- Locale to be used for comments of key-value pairs.comment
- A comment to be written in the first line.IOException
- if an error occurred when writing to the stream.doSave(BufferedWriter, Locale, String)
protected void doSave(BufferedWriter out, Locale locale, String comment) throws IOException
out
- Output character stream.locale
- Locale to be used for comments of key-value pairs.comment
- A comment to be written in the first line.IOException
- if an error occurred when writing to the stream.protected static void writeComment(BufferedWriter out, String comment) throws IOException
out
- Output character stream.comment
- A comment to be written.IOException
- if an error occurred when writing to the stream.protected static void writeKey(BufferedWriter out, String key) throws IOException
out
- Output character stream.key
- An entry key to be written.IOException
- if an error occurred when writing to the stream.protected static void writeValue(BufferedWriter out, String value) throws IOException
out
- Output character stream.value
- An entry value to be written.IOException
- if an error occurred when writing to the stream.public final void addListener(PropertyChangeListener listener)
listener
- Listener to be added.public final void removeListener(PropertyChangeListener listener)
listener
- Listener to be removed.Copyright © 2011–2020 FoxLabs. All rights reserved.