public class PlaceholderMap
extends java.lang.Object
Path
s as PlaceholderMap.Key
s, there are
two modes how to use the keys:
equals
method to compare keys==
operator to compare keysPlaceholderStrategy
to automatically delete
entries that are no longer valid.Modifier and Type | Class and Description |
---|---|
static interface |
PlaceholderMap.Key
A key is a set of
Path s, it is used to identify
entries in a PlaceholderMap . |
Constructor and Description |
---|
PlaceholderMap(java.io.DataInputStream in,
PlaceholderStrategy strategy)
Creates a new map reading the content of the map directly from
in . |
PlaceholderMap(Path format,
int version)
Creates a new map.
|
PlaceholderMap(XElement in,
PlaceholderStrategy strategy)
Creates a new map reading the content of the map directly from
in . |
Modifier and Type | Method and Description |
---|---|
void |
add(PlaceholderMap.Key placeholder)
Adds the placeholder
placeholder to this map. |
boolean |
contains(PlaceholderMap.Key placeholder,
java.lang.String key)
Tells whether
key exists for placeholder . |
PlaceholderMap |
copy()
Creates a deep copy of this map.
|
PlaceholderMap.Key |
copyKey(PlaceholderMap.Key key)
Creates a copy of
key . |
PlaceholderMap |
filter(PlaceholderStrategy strategy)
May return this or a copy of this
PlaceholderMap to which strategy was applied. |
java.lang.Object |
get(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the data that is stored under
key . |
java.lang.Object[] |
getArray(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the map that is stored under
key |
boolean |
getBoolean(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the boolean that is stored under
key |
double |
getDouble(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the double that is stored under
key |
Path |
getFormat()
Gets the format of this map, the meaning of the format depends on the client.
|
int |
getInt(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the integer that is stored under
key |
java.lang.String[] |
getKeys(PlaceholderMap.Key placeholder)
Gets all keys that are in use for
placeholder in the order
they were first used to put an object into this map. |
long |
getLong(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the long that is stored under
key |
PlaceholderMap |
getMap(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the map that is stored under
key |
Path |
getPath(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the
Path that is stored under key |
PlaceholderMap.Key[] |
getPlaceholders()
Gets all placeholders that are known to this map in the order
they were
added to this map. |
PlaceholderStrategy |
getPlaceholderStrategy()
Gets the strategy that is observed for removing invalid placeholders.
|
java.lang.String |
getString(PlaceholderMap.Key placeholder,
java.lang.String key)
Gets the string that is stored under
key |
int |
getVersion()
Gets the version of the format used in this map.
|
boolean |
isEmpty()
Tells whether this map is completely empty.
|
PlaceholderMap.Key |
newKey(Path... placeholders)
Creates a new shared key for any set of placeholders.
|
PlaceholderMap.Key |
newKey(java.lang.String anchor,
Path... placeholders)
Creates a new shared key for any set of placeholders.
|
PlaceholderMap.Key |
newUniqueKey(Path... placeholders)
Creates a new non-shared key for any set of placeholders.
|
PlaceholderMap.Key |
newUniqueKey(java.lang.String anchor,
Path... placeholders)
Creates a new non-shared key for any set of placeholders.
|
void |
put(PlaceholderMap.Key placeholder,
java.lang.String key,
java.lang.Object value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent.It is the clients responsibility not to introduce cycles of object references. |
void |
putArray(PlaceholderMap.Key placeholder,
java.lang.String key,
java.lang.Object[] value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent. |
void |
putBoolean(PlaceholderMap.Key placeholder,
java.lang.String key,
boolean value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent. |
void |
putDouble(PlaceholderMap.Key placeholder,
java.lang.String key,
double value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent. |
void |
putInt(PlaceholderMap.Key placeholder,
java.lang.String key,
int value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent. |
void |
putLong(PlaceholderMap.Key placeholder,
java.lang.String key,
long value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent. |
void |
putMap(PlaceholderMap.Key placeholder,
java.lang.String key,
PlaceholderMap value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent. |
void |
putPath(PlaceholderMap.Key placeholder,
java.lang.String key,
Path value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent. |
void |
putString(PlaceholderMap.Key placeholder,
java.lang.String key,
java.lang.String value)
Stores the value
value in this map, adds
placeholder if necessary, overrides the value stored at
key if existent. |
void |
remove(PlaceholderMap.Key placeholder)
Removes
placeholder and all information that is associated with
placeholder from this map. |
java.lang.Object |
remove(PlaceholderMap.Key placeholder,
java.lang.String key)
Removes the value that is stored at
key . |
void |
removeAll(Path placeholder,
boolean recursive)
Removes all occurrences of
placeholders . |
void |
removeAll(java.util.Set<Path> placeholders,
boolean recursive)
Removes all occurrences of all elements of
placeholders . |
void |
setPlaceholderStrategy(PlaceholderStrategy strategy)
Sets the strategy that is used to automatically remove invalid placeholders.
|
java.lang.String |
toString() |
void |
validate(PlaceholderStrategy strategy,
boolean recursive)
Using
strategy removes all placeholders that are invalid. |
void |
write(java.io.DataOutputStream out)
Writes the contents of this map into
out . |
void |
write(XElement out)
Writes the contents of this map into
out . |
public PlaceholderMap(Path format, int version)
format
- the kind of data stored in this map, the exact meaning depends on the client
that is using this mapversion
- the version of the format, the exact meaning depends on the client
that is using this mappublic PlaceholderMap(java.io.DataInputStream in, PlaceholderStrategy strategy) throws java.io.IOException
in
.in
- the contentstrategy
- guard to identify the placeholders which are allowed to be stored, can be null
java.io.IOException
- in case of an I/O errorpublic PlaceholderMap(XElement in, PlaceholderStrategy strategy)
in
.in
- the content to readstrategy
- guard to identify the placeholders which are allowed to be stored, can be null
public void write(java.io.DataOutputStream out) throws java.io.IOException
out
.out
- the stream to write intojava.io.IOException
- in case of an I/O errorpublic void write(XElement out)
out
.out
- the element to fill, its attributes will not be modifiedpublic PlaceholderMap copy()
null
public PlaceholderMap filter(PlaceholderStrategy strategy)
PlaceholderMap
to which strategy
was applied. The
strategy of the result may or may not be set. This map is not modified by this method.strategy
- the strategy to applypublic PlaceholderMap.Key newKey(Path... placeholders)
placeholders
- the placeholders of the keypublic PlaceholderMap.Key newKey(java.lang.String anchor, Path... placeholders)
anchor
- if the anchor is set, then this key cannot be automatically deleted. It is the clients responsibility
to ensure that no two keys have the same anchor. If two keys have the same anchor, then one of them might override
the other one leading to data loss. Can be null
.placeholders
- the placeholders of the keypublic PlaceholderMap.Key newUniqueKey(Path... placeholders)
placeholders
- the placeholders of the keypublic PlaceholderMap.Key newUniqueKey(java.lang.String anchor, Path... placeholders)
placeholders
- the placeholders of the keyanchor
- if the anchor is set, then this key cannot be automatically deleted. It is the clients responsibility
to ensure that no two keys have the same anchor. If two keys have the same anchor, then one of them might override
the other one leading to data loss. Can be null
.public PlaceholderMap.Key copyKey(PlaceholderMap.Key key)
key
.key
- the key to copypublic void setPlaceholderStrategy(PlaceholderStrategy strategy)
PlaceholderMap
s that are
stored within this map.strategy
- the new strategy, can be null
public PlaceholderStrategy getPlaceholderStrategy()
null
public void validate(PlaceholderStrategy strategy, boolean recursive)
strategy
removes all placeholders that are invalid.strategy
- the strategy for checking the placeholders, a value or null
means that all placeholders are validrecursive
- if true
then validate(PlaceholderStrategy,boolean)
is also
called on all sub-maps of this mappublic void removeAll(Path placeholder, boolean recursive)
placeholders
.placeholder
- the placeholder to removerecursive
- if true
, this method is called recursively on
every sub-map in this mappublic void removeAll(java.util.Set<Path> placeholders, boolean recursive)
placeholders
.placeholders
- the placeholders to removerecursive
- if true
, this method is called recursively on
every sub-map in this mappublic int getVersion()
the format
public Path getFormat()
null
public void add(PlaceholderMap.Key placeholder)
placeholder
to this map. Nothing happens
if placeholder
is already in this map.placeholder
- the new placeholder, not null
public void remove(PlaceholderMap.Key placeholder)
placeholder
and all information that is associated with
placeholder
from this map.placeholder
- the placeholder to clearpublic PlaceholderMap.Key[] getPlaceholders()
added
to this map.public java.lang.String[] getKeys(PlaceholderMap.Key placeholder)
placeholder
in the order
they were first used to put an object into this map.placeholder
- some placeholdernull
if placeholder
is not
known to this mappublic boolean isEmpty()
true
if there are no data stored in this mappublic void putString(PlaceholderMap.Key placeholder, java.lang.String key, java.lang.String value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new value, not null
public void putPath(PlaceholderMap.Key placeholder, java.lang.String key, Path value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new value, not null
public void putInt(PlaceholderMap.Key placeholder, java.lang.String key, int value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new valuepublic void putLong(PlaceholderMap.Key placeholder, java.lang.String key, long value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new valuepublic void putBoolean(PlaceholderMap.Key placeholder, java.lang.String key, boolean value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new valuepublic void putDouble(PlaceholderMap.Key placeholder, java.lang.String key, double value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new valuepublic void putMap(PlaceholderMap.Key placeholder, java.lang.String key, PlaceholderMap value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new value, not null
public void putArray(PlaceholderMap.Key placeholder, java.lang.String key, java.lang.Object[] value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new value, not null
. May contain any data type
for which this map offers a put-method.public void put(PlaceholderMap.Key placeholder, java.lang.String key, java.lang.Object value)
value
in this map, adds
placeholder
if necessary, overrides the value stored at
key
if existent.placeholder
- the placeholder for which value
is storedkey
- the unique identifier of the valuevalue
- the new value, not null
java.lang.IllegalArgumentException
- if value
is neither
String
, Integer
, Long
, Double
, Boolean
PlaceholderMap
nor an array of Object
s containing the mentioned data typespublic java.lang.Object remove(PlaceholderMap.Key placeholder, java.lang.String key)
key
. Note that this
method will not remove placeholder
from this map even
if there is no data left associated with placeholder
.placeholder
- the placeholder in whose realm the data is deletedkey
- the unique identifier of the removed datanull
public boolean contains(PlaceholderMap.Key placeholder, java.lang.String key)
key
exists for placeholder
.placeholder
- the placeholder in whose realm key
should existkey
- the key to searchtrue
if there is some data storedpublic java.lang.String getString(PlaceholderMap.Key placeholder, java.lang.String key)
key
placeholder
- the placeholder in whose realm to searchkey
- the unique identifier of the searched datanull
java.lang.IllegalArgumentException
- if either the value is of the wrong type or missingpublic Path getPath(PlaceholderMap.Key placeholder, java.lang.String key)
Path
that is stored under key
placeholder
- the placeholder in whose realm to searchkey
- the unique identifier of the searched datanull
java.lang.IllegalArgumentException
- if either the value is of the wrong type or missingpublic int getInt(PlaceholderMap.Key placeholder, java.lang.String key)
key
placeholder
- the placeholder in whose realm to searchkey
- the unique identifier of the searched datanull
java.lang.IllegalArgumentException
- if either the value is of the wrong type or missingpublic long getLong(PlaceholderMap.Key placeholder, java.lang.String key)
key
placeholder
- the placeholder in whose realm to searchkey
- the unique identifier of the searched datanull
java.lang.IllegalArgumentException
- if either the value is of the wrong type or missingpublic boolean getBoolean(PlaceholderMap.Key placeholder, java.lang.String key)
key
placeholder
- the placeholder in whose realm to searchkey
- the unique identifier of the searched datanull
java.lang.IllegalArgumentException
- if either the value is of the wrong type or missingpublic double getDouble(PlaceholderMap.Key placeholder, java.lang.String key)
key
placeholder
- the placeholder in whose realm to searchkey
- the unique identifier of the searched datanull
java.lang.IllegalArgumentException
- if either the value is of the wrong type or missingpublic PlaceholderMap getMap(PlaceholderMap.Key placeholder, java.lang.String key)
key
placeholder
- the placeholder in whose realm to searchkey
- the unique identifier of the searched datanull
java.lang.IllegalArgumentException
- if either the value is of the wrong type or missingpublic java.lang.Object[] getArray(PlaceholderMap.Key placeholder, java.lang.String key)
key
placeholder
- the placeholder in whose realm to searchkey
- the unique identifier of the searched datanull
java.lang.IllegalArgumentException
- if either the value is of the wrong type or missingpublic java.lang.Object get(PlaceholderMap.Key placeholder, java.lang.String key)
key
.placeholder
- the realm in which to searchkey
- the key of the datanull
public java.lang.String toString()
toString
in class java.lang.Object