public class LocalAttributeMap<V> extends java.lang.Object implements MutableAttributeMap<V>, java.io.Serializable
Constructor and Description |
---|
LocalAttributeMap()
Creates a new attribute map, initially empty.
|
LocalAttributeMap(int size,
int loadFactor)
Creates a new attribute map, initially empty.
|
LocalAttributeMap(java.util.Map<java.lang.String,V> map)
Creates a new attribute map wrapping the specified map.
|
LocalAttributeMap(java.lang.String attributeName,
V attributeValue)
Creates a new attribute map with a single entry.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,V> |
asMap()
Returns this object's contents as a
Map . |
MutableAttributeMap<V> |
clear()
Remove all attributes in this map.
|
boolean |
contains(java.lang.String attributeName)
Does the attribute with the provided name exist in this map?
|
boolean |
contains(java.lang.String attributeName,
java.lang.Class<? extends V> requiredType)
Does the attribute with the provided name exist in this map and is its value of the specified required type?
|
protected java.util.Map<java.lang.String,V> |
createTargetMap()
Factory method that returns the target map storing the data in this attribute map.
|
protected java.util.Map<java.lang.String,V> |
createTargetMap(int size,
int loadFactor)
Factory method that returns the target map storing the data in this attribute map.
|
boolean |
equals(java.lang.Object o) |
java.lang.Object |
extract(java.lang.String attributeName)
Extract an attribute from this map, getting it and removing it in a single operation.
|
V |
get(java.lang.String attributeName)
Get an attribute value out of this map, returning
null if not found. |
<T extends V> |
get(java.lang.String attributeName,
java.lang.Class<T> requiredType)
Get an attribute value, asserting the value is of the required type.
|
<T extends V> |
get(java.lang.String attributeName,
java.lang.Class<T> requiredType,
T defaultValue)
Get an attribute value, asserting the value is of the required type and returning the default value if not found.
|
V |
get(java.lang.String attributeName,
V defaultValue)
Get an attribute value, returning the default value if no value is found.
|
<T extends V> |
getArray(java.lang.String attributeName,
java.lang.Class<? extends T[]> requiredType)
Returns an array attribute value in the map and makes sure it is of the required type.
|
java.lang.Boolean |
getBoolean(java.lang.String attributeName)
Returns a boolean attribute value in the map, returning
null if no value was found. |
java.lang.Boolean |
getBoolean(java.lang.String attributeName,
java.lang.Boolean defaultValue)
Returns a boolean attribute value in the map, returning the default value if no value was found.
|
java.util.Collection<V> |
getCollection(java.lang.String attributeName)
Returns a collection attribute value in the map.
|
<T extends java.util.Collection<V>> |
getCollection(java.lang.String attributeName,
java.lang.Class<T> requiredType)
Returns a collection attribute value in the map and make sure it is of the required type.
|
java.lang.Integer |
getInteger(java.lang.String attributeName)
Returns an integer attribute value in the map, returning
null if no value was found. |
java.lang.Integer |
getInteger(java.lang.String attributeName,
java.lang.Integer defaultValue)
Returns an integer attribute value in the map, returning the default value if no value was found.
|
java.lang.Long |
getLong(java.lang.String attributeName)
Returns a long attribute value in the map, returning
null if no value was found. |
java.lang.Long |
getLong(java.lang.String attributeName,
java.lang.Long defaultValue)
Returns a long attribute value in the map, returning the default value if no value was found.
|
protected java.util.Map<java.lang.String,V> |
getMapInternal()
Returns the wrapped, modifiable map implementation.
|
<T extends java.lang.Number> |
getNumber(java.lang.String attributeName,
java.lang.Class<T> requiredType)
Returns a number attribute value in the map that is of the specified type, returning
null if no
value was found. |
<T extends java.lang.Number> |
getNumber(java.lang.String attributeName,
java.lang.Class<T> requiredType,
T defaultValue)
Returns a number attribute value in the map of the specified type, returning the default value if no value was
found.
|
V |
getRequired(java.lang.String attributeName)
Get the value of a required attribute, throwing an exception of no attribute is found.
|
<T extends V> |
getRequired(java.lang.String attributeName,
java.lang.Class<T> requiredType)
Get the value of a required attribute and make sure it is of the required type.
|
<T extends V> |
getRequiredArray(java.lang.String attributeName,
java.lang.Class<? extends T[]> requiredType)
Returns an array attribute value in the map, throwing an exception if the attribute is not present or not an
array of the required type.
|
java.lang.Boolean |
getRequiredBoolean(java.lang.String attributeName)
Returns a boolean attribute value in the map, throwing an exception if the attribute is not present and of the
correct type.
|
java.util.Collection<V> |
getRequiredCollection(java.lang.String attributeName)
Returns a collection attribute value in the map, throwing an exception if the attribute is not present or not a
collection.
|
<T extends java.util.Collection<V>> |
getRequiredCollection(java.lang.String attributeName,
java.lang.Class<T> requiredType)
Returns a collection attribute value in the map, throwing an exception if the attribute is not present or not a
collection of the required type.
|
java.lang.Integer |
getRequiredInteger(java.lang.String attributeName)
Returns an integer attribute value in the map, throwing an exception if the attribute is not present and of the
correct type.
|
java.lang.Long |
getRequiredLong(java.lang.String attributeName)
Returns a long attribute value in the map, throwing an exception if the attribute is not present and of the
correct type.
|
<T extends java.lang.Number> |
getRequiredNumber(java.lang.String attributeName,
java.lang.Class<T> requiredType)
Returns a number attribute value in the map, throwing an exception if the attribute is not present and of the
correct type.
|
java.lang.String |
getRequiredString(java.lang.String attributeName)
Returns a string attribute value in the map, throwing an exception if the attribute is not present and of the
correct type.
|
java.lang.String |
getString(java.lang.String attributeName)
Returns a string attribute value in the map, returning
null if no value was found. |
java.lang.String |
getString(java.lang.String attributeName,
java.lang.String defaultValue)
Returns a string attribute value in the map, returning the default value if no value was found.
|
int |
hashCode() |
protected void |
initAttributes(java.util.Map<java.lang.String,V> attributes)
Initializes this attribute map.
|
boolean |
isEmpty()
Is this attribute map empty with a size of 0?
|
V |
put(java.lang.String attributeName,
V attributeValue)
Put the attribute into this map.
|
MutableAttributeMap<V> |
putAll(AttributeMap<? extends V> attributes)
Put all the attributes into this map.
|
java.lang.Object |
remove(java.lang.String attributeName)
Remove an attribute from this map.
|
MutableAttributeMap<V> |
removeAll(MutableAttributeMap<? extends V> attributes)
Remove all attributes in the map provided from this map.
|
MutableAttributeMap<V> |
replaceWith(AttributeMap<? extends V> attributes)
Replace the contents of this attribute map with the contents of the provided collection.
|
int |
size()
Returns the size of this map.
|
java.lang.String |
toString() |
AttributeMap<V> |
union(AttributeMap<? extends V> attributes)
Returns a new attribute map containing the union of this map with the provided map.
|
public LocalAttributeMap()
public LocalAttributeMap(int size, int loadFactor)
size
- the initial sizeloadFactor
- the load factorpublic LocalAttributeMap(java.lang.String attributeName, V attributeValue)
public LocalAttributeMap(java.util.Map<java.lang.String,V> map)
public java.util.Map<java.lang.String,V> asMap()
MapAdaptable
Map
. The returned map may or may not be modifiable depending on this
implementation.
Warning: this operation may be called frequently; if so care should be taken so that the map contents (if calculated) be cached as appropriate.
asMap
in interface MapAdaptable<java.lang.String,V>
public int size()
AttributeMap
size
in interface AttributeMap<V>
public V get(java.lang.String attributeName)
AttributeMap
null
if not found.get
in interface AttributeMap<V>
attributeName
- the attribute namepublic boolean isEmpty()
AttributeMap
isEmpty
in interface AttributeMap<V>
public boolean contains(java.lang.String attributeName)
AttributeMap
contains
in interface AttributeMap<V>
attributeName
- the attribute namepublic boolean contains(java.lang.String attributeName, java.lang.Class<? extends V> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
contains
in interface AttributeMap<V>
attributeName
- the attribute namerequiredType
- the required class of the attribute valuejava.lang.IllegalArgumentException
- when the value is not of the required typepublic V get(java.lang.String attributeName, V defaultValue)
AttributeMap
get
in interface AttributeMap<V>
attributeName
- the name of the attributedefaultValue
- the default valuepublic <T extends V> T get(java.lang.String attributeName, java.lang.Class<T> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
get
in interface AttributeMap<V>
attributeName
- the name of the attributerequiredType
- the required type of the attribute valuejava.lang.IllegalArgumentException
- when the value is not of the required typepublic <T extends V> T get(java.lang.String attributeName, java.lang.Class<T> requiredType, T defaultValue) throws java.lang.IllegalStateException
AttributeMap
get
in interface AttributeMap<V>
attributeName
- the name of the attributerequiredType
- the value required typedefaultValue
- the default valuejava.lang.IllegalStateException
public V getRequired(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
getRequired
in interface AttributeMap<V>
attributeName
- the name of the attributejava.lang.IllegalArgumentException
- when the attribute is not foundpublic <T extends V> T getRequired(java.lang.String attributeName, java.lang.Class<T> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
getRequired
in interface AttributeMap<V>
attributeName
- name of the attribute to getrequiredType
- the required type of the attribute valuejava.lang.IllegalArgumentException
- when the attribute is not found or not of the required typepublic java.lang.String getString(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
null
if no value was found.getString
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is present but not a stringpublic java.lang.String getString(java.lang.String attributeName, java.lang.String defaultValue) throws java.lang.IllegalArgumentException
AttributeMap
getString
in interface AttributeMap<V>
attributeName
- the attribute namedefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the attribute is present but not a stringpublic java.lang.String getRequiredString(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
getRequiredString
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is not present or present but not a stringpublic java.util.Collection<V> getCollection(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
getCollection
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is present but not a collectionpublic <T extends java.util.Collection<V>> T getCollection(java.lang.String attributeName, java.lang.Class<T> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
getCollection
in interface AttributeMap<V>
attributeName
- the attribute namerequiredType
- the required type of the attribute valuejava.lang.IllegalArgumentException
- if the attribute is present but not a collection of the required typepublic java.util.Collection<V> getRequiredCollection(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
getRequiredCollection
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is not present or is present but not a collectionpublic <T extends java.util.Collection<V>> T getRequiredCollection(java.lang.String attributeName, java.lang.Class<T> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
getRequiredCollection
in interface AttributeMap<V>
attributeName
- the attribute namerequiredType
- the required collection typejava.lang.IllegalArgumentException
- if the attribute is not present or is present but not a collection of the
required typepublic <T extends V> T[] getArray(java.lang.String attributeName, java.lang.Class<? extends T[]> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
getArray
in interface AttributeMap<V>
attributeName
- the attribute namerequiredType
- the required type of the attribute valuejava.lang.IllegalArgumentException
- if the attribute is present but not an array of the required typepublic <T extends V> T[] getRequiredArray(java.lang.String attributeName, java.lang.Class<? extends T[]> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
getRequiredArray
in interface AttributeMap<V>
attributeName
- the attribute namerequiredType
- the required array typejava.lang.IllegalArgumentException
- if the attribute is not present or is present but not a array of the required
typepublic <T extends java.lang.Number> T getNumber(java.lang.String attributeName, java.lang.Class<T> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
null
if no
value was found.getNumber
in interface AttributeMap<V>
attributeName
- the attribute namerequiredType
- the required number typejava.lang.IllegalArgumentException
- if the attribute is present but not a number of the required typepublic <T extends java.lang.Number> T getNumber(java.lang.String attributeName, java.lang.Class<T> requiredType, T defaultValue) throws java.lang.IllegalArgumentException
AttributeMap
getNumber
in interface AttributeMap<V>
attributeName
- the attribute namedefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the attribute is present but not a number of the required typepublic <T extends java.lang.Number> T getRequiredNumber(java.lang.String attributeName, java.lang.Class<T> requiredType) throws java.lang.IllegalArgumentException
AttributeMap
getRequiredNumber
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is not present or present but not a number of the required typepublic java.lang.Integer getInteger(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
null
if no value was found.getInteger
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is present but not an integerpublic java.lang.Integer getInteger(java.lang.String attributeName, java.lang.Integer defaultValue) throws java.lang.IllegalArgumentException
AttributeMap
getInteger
in interface AttributeMap<V>
attributeName
- the attribute namedefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the attribute is present but not an integerpublic java.lang.Integer getRequiredInteger(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
getRequiredInteger
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is not present or present but not an integerpublic java.lang.Long getLong(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
null
if no value was found.getLong
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is present but not a longpublic java.lang.Long getLong(java.lang.String attributeName, java.lang.Long defaultValue) throws java.lang.IllegalArgumentException
AttributeMap
getLong
in interface AttributeMap<V>
attributeName
- the attribute namedefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the attribute is present but not a longpublic java.lang.Long getRequiredLong(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
getRequiredLong
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is not present or present but not a longpublic java.lang.Boolean getBoolean(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
null
if no value was found.getBoolean
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is present but not a booleanpublic java.lang.Boolean getBoolean(java.lang.String attributeName, java.lang.Boolean defaultValue) throws java.lang.IllegalArgumentException
AttributeMap
getBoolean
in interface AttributeMap<V>
attributeName
- the attribute namedefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the attribute is present but not a booleanpublic java.lang.Boolean getRequiredBoolean(java.lang.String attributeName) throws java.lang.IllegalArgumentException
AttributeMap
getRequiredBoolean
in interface AttributeMap<V>
attributeName
- the attribute namejava.lang.IllegalArgumentException
- if the attribute is not present or present but is not a booleanpublic AttributeMap<V> union(AttributeMap<? extends V> attributes)
AttributeMap
union
in interface AttributeMap<V>
attributes
- the map to combine with this mappublic V put(java.lang.String attributeName, V attributeValue)
MutableAttributeMap
If the attribute value is an AttributeMapBindingListener
this map will publish
binding events
such as on "bind" and "unbind" if supported.
Note: not all MutableAttributeMap
implementations support this.
put
in interface MutableAttributeMap<V>
attributeName
- the attribute nameattributeValue
- the attribute valuenull
of there was no previous valuepublic MutableAttributeMap<V> putAll(AttributeMap<? extends V> attributes)
MutableAttributeMap
putAll
in interface MutableAttributeMap<V>
attributes
- the attributes to put into this mappublic MutableAttributeMap<V> removeAll(MutableAttributeMap<? extends V> attributes)
MutableAttributeMap
removeAll
in interface MutableAttributeMap<V>
attributes
- the attributes to remove from this mappublic java.lang.Object remove(java.lang.String attributeName)
MutableAttributeMap
remove
in interface MutableAttributeMap<V>
attributeName
- the name of the attribute to removepublic java.lang.Object extract(java.lang.String attributeName)
MutableAttributeMap
extract
in interface MutableAttributeMap<V>
attributeName
- the attribute namenull
of there was no valuepublic MutableAttributeMap<V> clear() throws java.lang.UnsupportedOperationException
MutableAttributeMap
clear
in interface MutableAttributeMap<V>
java.lang.UnsupportedOperationException
public MutableAttributeMap<V> replaceWith(AttributeMap<? extends V> attributes) throws java.lang.UnsupportedOperationException
MutableAttributeMap
replaceWith
in interface MutableAttributeMap<V>
attributes
- the attribute collectionjava.lang.UnsupportedOperationException
protected void initAttributes(java.util.Map<java.lang.String,V> attributes)
attributes
- the attributesprotected java.util.Map<java.lang.String,V> getMapInternal()
protected java.util.Map<java.lang.String,V> createTargetMap()
protected java.util.Map<java.lang.String,V> createTargetMap(int size, int loadFactor)
size
- the initial size of the maploadFactor
- the load factorpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object