Package org.arakhne.afc.attrs.collection
Class MultiAttributeCollection
- java.lang.Object
-
- org.arakhne.afc.attrs.collection.AbstractAttributeProvider
-
- org.arakhne.afc.attrs.collection.MultiAttributeProvider
-
- org.arakhne.afc.attrs.collection.MultiAttributeCollection
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Attribute>
,AttributeCollection
,AttributeProvider
,JsonableObject
public class MultiAttributeCollection extends MultiAttributeProvider implements AttributeCollection
This class contains a collection of attribute providers and tries to gather the data. This class contains a collection of AttributeProviders and exhibites the values of the attributes of all these providers. This class follows the following rules (in that order) to retreive the value of an attribute:- If the attribute is defined in none of the containers, throws the standard exception;
- If the attribute is defined in only one of the containers, replies the attribute value itself;
- If the attribute is defined in more than one container:
- if all the values are equal, then replies one of the attribute values;
- if the values are not equal and all the values have equivalent types (as replied
by
AttributeType.isAssignableFrom(AttributeType)
), then replies an attribute value with a "undefined" value and of the type of one of the values; - if the values are not equal and one of the value has not an equivalent type to
the others (as replied by
AttributeType.isAssignableFrom(AttributeType)
), then replies an attribute value with a "undefined" value and of the type OBJECT.
If an attribute is set from this AttributeProviderContainer, all the containers inside it are changed.
- Since:
- 4.0
- Version:
- 17.0 2020-01-04 14:41:51
- Author:
- Stéphane GALLAND
- See Also:
- Serialized Form
- Maven Group Id:
- org.arakhne.afc.advanced
- Maven Artifact Id:
- attributes
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.arakhne.afc.attrs.collection.MultiAttributeProvider
MultiAttributeProvider.ManyValueAttributeValue
-
-
Field Summary
Fields Modifier and Type Field Description (package private) AtomicBoolean
runProviderEvents
Boolean indicates that enable event handling from the providers, or not.-
Fields inherited from class org.arakhne.afc.attrs.collection.MultiAttributeProvider
cache, names
-
-
Constructor Summary
Constructors Constructor Description MultiAttributeCollection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttributeChangeListener(AttributeChangeListener listener)
Add a listener on the attribute value changes.boolean
addAttributeContainer(AttributeProvider container)
Add a container in this set.void
addAttributes(Map<String,Object> content)
Put the values given as parameter in this attribute provider.void
addAttributes(AttributeProvider content)
Put the values given as parameter in this attribute provider.MultiAttributeCollection
clone()
Make a deep copy of this object and replies the copy.protected void
fireAttributeChange(AttributeChangeEvent event)
Notifies the listeners about the change of an attribute.void
flush()
Force this provider to synchronized the memory state of the attributes with a remote storage area.boolean
isEventFirable()
Replies if the events are fired by this container.boolean
removeAllAttributes()
Remove all the attributes.boolean
removeAttribute(String name)
Remove the given attribute.void
removeAttributeChangeListener(AttributeChangeListener listener)
Remove a listener on the attribute value changes.boolean
removeAttributeContainer(AttributeProvider container)
Remove a container in this set.boolean
renameAttribute(String oldname, String newname)
Rename the attribute.boolean
renameAttribute(String oldname, String newname, boolean overwrite)
Rename the attribute .Attribute
setAttribute(String name, boolean value)
Set the value for the given attribute.Attribute
setAttribute(String name, double value)
Set the value for the given attribute.Attribute
setAttribute(String name, float value)
Set the value for the given attribute.Attribute
setAttribute(String name, int value)
Set the value for the given attribute.Attribute
setAttribute(String name, long value)
Set the value for the given attribute.Attribute
setAttribute(String name, Class<?> value)
Set the value for the given attribute.Attribute
setAttribute(String name, Enum<?> value)
Set the value for the given attribute.Attribute
setAttribute(String name, String value)
Set the value for the given attribute.Attribute
setAttribute(String name, InetAddress value)
Set the value for the given attribute.Attribute
setAttribute(String name, InetSocketAddress value)
Set the value for the given attribute.Attribute
setAttribute(String name, URI value)
Set the value for the given attribute.Attribute
setAttribute(String name, URL value)
Set the value for the given attribute.Attribute
setAttribute(String name, Date value)
Set the value for the given attribute.Attribute
setAttribute(String name, UUID value)
Set the value for the given attribute.Attribute
setAttribute(String name, AttributeValue value)
Set the value for the given attribute.Attribute
setAttribute(Attribute value)
Set the value for the given attribute.void
setAttributes(Map<String,Object> content)
Set the content of this collection from the given map.void
setAttributes(AttributeProvider content)
Set the content of this collection from the given map.Attribute
setAttributeType(String name, AttributeType type)
Set the type of the attribute with the given name.void
setEventFirable(boolean isFirable)
Set if the events are fired by this container.-
Methods inherited from class org.arakhne.afc.attrs.collection.MultiAttributeProvider
assign, canonize, containers, freeMemory, getAllAttributeNames, getAllAttributes, getAllAttributesByType, getAttribute, getAttribute, getAttributeContainerCount, getAttributeCount, getAttributeObject, hasAttribute, toMap
-
Methods inherited from class org.arakhne.afc.attrs.collection.AbstractAttributeProvider
attributes, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttributeAsBool, getAttributeAsDate, getAttributeAsDouble, getAttributeAsEnumeration, getAttributeAsEnumeration, getAttributeAsFloat, getAttributeAsInetAddress, getAttributeAsInt, getAttributeAsJavaClass, getAttributeAsLong, getAttributeAsString, getAttributeAsURI, getAttributeAsURL, getAttributeAsUUID, iterator, protectNull, toJson, toString, unprotectNull
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.arakhne.afc.attrs.collection.AttributeProvider
attributes, freeMemory, getAllAttributeNames, getAllAttributes, getAllAttributesByType, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttributeAsBool, getAttributeAsDate, getAttributeAsDouble, getAttributeAsEnumeration, getAttributeAsEnumeration, getAttributeAsFloat, getAttributeAsInetAddress, getAttributeAsInt, getAttributeAsJavaClass, getAttributeAsLong, getAttributeAsString, getAttributeAsURI, getAttributeAsURL, getAttributeAsUUID, getAttributeCount, getAttributeObject, hasAttribute, toMap, toMap
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface org.arakhne.afc.vmutil.json.JsonableObject
toJson
-
-
-
-
Field Detail
-
runProviderEvents
AtomicBoolean runProviderEvents
Boolean indicates that enable event handling from the providers, or not.
-
-
Method Detail
-
isEventFirable
@Pure public boolean isEventFirable()
Description copied from interface:AttributeCollection
Replies if the events are fired by this container.- Specified by:
isEventFirable
in interfaceAttributeCollection
- Returns:
true
if the events are fired; otherwisefalse
if events are not fired.
-
setEventFirable
public void setEventFirable(boolean isFirable)
Description copied from interface:AttributeCollection
Set if the events are fired by this container.- Specified by:
setEventFirable
in interfaceAttributeCollection
- Parameters:
isFirable
- istrue
if the events are fired; otherwisefalse
if events are not fired.
-
clone
public MultiAttributeCollection clone()
Description copied from class:AbstractAttributeProvider
Make a deep copy of this object and replies the copy.- Specified by:
clone
in interfaceAttributeCollection
- Specified by:
clone
in interfaceAttributeProvider
- Overrides:
clone
in classMultiAttributeProvider
- Returns:
- the deep copy.
-
addAttributeContainer
public boolean addAttributeContainer(AttributeProvider container)
Description copied from class:MultiAttributeProvider
Add a container in this set.- Overrides:
addAttributeContainer
in classMultiAttributeProvider
- Parameters:
container
- the container.- Returns:
true
if the container has been added, otherwisefalse
-
removeAttributeContainer
public boolean removeAttributeContainer(AttributeProvider container)
Description copied from class:MultiAttributeProvider
Remove a container in this set.- Overrides:
removeAttributeContainer
in classMultiAttributeProvider
- Parameters:
container
- the container.- Returns:
true
if the container has been removed, otherwisefalse
-
addAttributeChangeListener
public void addAttributeChangeListener(AttributeChangeListener listener)
Description copied from interface:AttributeCollection
Add a listener on the attribute value changes.- Specified by:
addAttributeChangeListener
in interfaceAttributeCollection
- Parameters:
listener
- the listener.
-
removeAttributeChangeListener
public void removeAttributeChangeListener(AttributeChangeListener listener)
Description copied from interface:AttributeCollection
Remove a listener on the attribute value changes.- Specified by:
removeAttributeChangeListener
in interfaceAttributeCollection
- Parameters:
listener
- the listener.
-
fireAttributeChange
protected void fireAttributeChange(AttributeChangeEvent event)
Notifies the listeners about the change of an attribute.- Parameters:
event
- the event.
-
flush
public void flush()
Description copied from interface:AttributeCollection
Force this provider to synchronized the memory state of the attributes with a remote storage area.- Specified by:
flush
in interfaceAttributeCollection
-
removeAllAttributes
public boolean removeAllAttributes()
Description copied from interface:AttributeCollection
Remove all the attributes.- Specified by:
removeAllAttributes
in interfaceAttributeCollection
- Returns:
false
if something wrong appends
-
removeAttribute
public boolean removeAttribute(String name)
Description copied from interface:AttributeCollection
Remove the given attribute.- Specified by:
removeAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to remove.- Returns:
true
on success, otherwhisefalse
-
renameAttribute
public boolean renameAttribute(String oldname, String newname)
Description copied from interface:AttributeCollection
Rename the attribute.If a attribute named
newname
already exists, this function will replyfalse
.This function is equivalent to
renameAttribute(oldname, newname, false)
.- Specified by:
renameAttribute
in interfaceAttributeCollection
- Parameters:
oldname
- is the name of the attribute to rename.newname
- is the new name of the attribute.- Returns:
false
if something wrong appends
-
renameAttribute
public boolean renameAttribute(String oldname, String newname, boolean overwrite)
Description copied from interface:AttributeCollection
Rename the attribute .- Specified by:
renameAttribute
in interfaceAttributeCollection
- Parameters:
oldname
- is the name of the attribute to rename.newname
- is the new name of the attribute.overwrite
- must betrue
if the value of an existing attribute named bynewname
must be overwritten by the value of the attribute namedoldname
.- Returns:
false
if something wrong appends
-
addAttributes
public void addAttributes(AttributeProvider content) throws AttributeException
Description copied from interface:AttributeCollection
Put the values given as parameter in this attribute provider. Any previous content of this attribute collection will remain if the keys are not inside the given content. If the values from the given content will be used to overwrite any existing value.- Specified by:
addAttributes
in interfaceAttributeCollection
- Parameters:
content
- is the content to add inside.- Throws:
AttributeException
- if one attribute from the content cannot be inserted.- See Also:
AttributeCollection.addAttributes(AttributeProvider)
-
addAttributes
public void addAttributes(Map<String,Object> content)
Description copied from interface:AttributeCollection
Put the values given as parameter in this attribute provider. Any previous content of this attribute collection will remain if the keys are not inside the given content. If the values from the given content will be used to overwrite any existing value.- Specified by:
addAttributes
in interfaceAttributeCollection
- Parameters:
content
- is the content to add inside.- See Also:
AttributeCollection.setAttributes(Map)
-
setAttributes
public void setAttributes(AttributeProvider content) throws AttributeException
Description copied from interface:AttributeCollection
Set the content of this collection from the given map. Any previous content of this attribute collection will be lost. This function is equivalent to:this.removeAllAttributes(); this.addAttributes(content);
- Specified by:
setAttributes
in interfaceAttributeCollection
- Parameters:
content
- is the content.- Throws:
AttributeException
- if one attribute from the content cannot be inserted.- See Also:
AttributeCollection.addAttributes(AttributeProvider)
-
setAttributes
public void setAttributes(Map<String,Object> content)
Description copied from interface:AttributeCollection
Set the content of this collection from the given map. Any previous content of this attribute collection will be lost. This function is equivalent to:this.removeAllAttributes(); this.addAttributes(content);
- Specified by:
setAttributes
in interfaceAttributeCollection
- Parameters:
content
- is the content.- See Also:
AttributeCollection.addAttributes(Map)
-
setAttribute
public Attribute setAttribute(String name, AttributeValue value) throws AttributeException
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
- Throws:
AttributeException
- on error.
-
setAttribute
public Attribute setAttribute(String name, boolean value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, int value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, long value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, float value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, double value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, String value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, InetAddress value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, InetSocketAddress value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, Enum<?> value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, Class<?> value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, UUID value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, URL value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, URI value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(String name, Date value)
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attribute to set.value
- is the value to store.- Returns:
- the changed attribute or
null
-
setAttribute
public Attribute setAttribute(Attribute value) throws AttributeException
Description copied from interface:AttributeCollection
Set the value for the given attribute.- Specified by:
setAttribute
in interfaceAttributeCollection
- Parameters:
value
- is the value to store.- Returns:
- the changed attribute or
null
- Throws:
AttributeException
- on error.
-
setAttributeType
public Attribute setAttributeType(String name, AttributeType type) throws AttributeException
Description copied from interface:AttributeCollection
Set the type of the attribute with the given name.- Specified by:
setAttributeType
in interfaceAttributeCollection
- Parameters:
name
- is the name of the attributetype
- is the desired type.- Returns:
- the changed attribute or
null
- Throws:
AttributeException
- on error.
-
-