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) AtomicBooleanrunProviderEventsBoolean 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 voidaddAttributeChangeListener(AttributeChangeListener listener)Add a listener on the attribute value changes.booleanaddAttributeContainer(AttributeProvider container)Add a container in this set.voidaddAttributes(Map<String,Object> content)Put the values given as parameter in this attribute provider.voidaddAttributes(AttributeProvider content)Put the values given as parameter in this attribute provider.MultiAttributeCollectionclone()Make a deep copy of this object and replies the copy.protected voidfireAttributeChange(AttributeChangeEvent event)Notifies the listeners about the change of an attribute.voidflush()Force this provider to synchronized the memory state of the attributes with a remote storage area.booleanisEventFirable()Replies if the events are fired by this container.booleanremoveAllAttributes()Remove all the attributes.booleanremoveAttribute(String name)Remove the given attribute.voidremoveAttributeChangeListener(AttributeChangeListener listener)Remove a listener on the attribute value changes.booleanremoveAttributeContainer(AttributeProvider container)Remove a container in this set.booleanrenameAttribute(String oldname, String newname)Rename the attribute.booleanrenameAttribute(String oldname, String newname, boolean overwrite)Rename the attribute .AttributesetAttribute(String name, boolean value)Set the value for the given attribute.AttributesetAttribute(String name, double value)Set the value for the given attribute.AttributesetAttribute(String name, float value)Set the value for the given attribute.AttributesetAttribute(String name, int value)Set the value for the given attribute.AttributesetAttribute(String name, long value)Set the value for the given attribute.AttributesetAttribute(String name, Class<?> value)Set the value for the given attribute.AttributesetAttribute(String name, Enum<?> value)Set the value for the given attribute.AttributesetAttribute(String name, String value)Set the value for the given attribute.AttributesetAttribute(String name, InetAddress value)Set the value for the given attribute.AttributesetAttribute(String name, InetSocketAddress value)Set the value for the given attribute.AttributesetAttribute(String name, URI value)Set the value for the given attribute.AttributesetAttribute(String name, URL value)Set the value for the given attribute.AttributesetAttribute(String name, Date value)Set the value for the given attribute.AttributesetAttribute(String name, UUID value)Set the value for the given attribute.AttributesetAttribute(String name, AttributeValue value)Set the value for the given attribute.AttributesetAttribute(Attribute value)Set the value for the given attribute.voidsetAttributes(Map<String,Object> content)Set the content of this collection from the given map.voidsetAttributes(AttributeProvider content)Set the content of this collection from the given map.AttributesetAttributeType(String name, AttributeType type)Set the type of the attribute with the given name.voidsetEventFirable(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:AttributeCollectionReplies if the events are fired by this container.- Specified by:
isEventFirablein interfaceAttributeCollection- Returns:
trueif the events are fired; otherwisefalseif events are not fired.
-
setEventFirable
public void setEventFirable(boolean isFirable)
Description copied from interface:AttributeCollectionSet if the events are fired by this container.- Specified by:
setEventFirablein interfaceAttributeCollection- Parameters:
isFirable- istrueif the events are fired; otherwisefalseif events are not fired.
-
clone
public MultiAttributeCollection clone()
Description copied from class:AbstractAttributeProviderMake a deep copy of this object and replies the copy.- Specified by:
clonein interfaceAttributeCollection- Specified by:
clonein interfaceAttributeProvider- Overrides:
clonein classMultiAttributeProvider- Returns:
- the deep copy.
-
addAttributeContainer
public boolean addAttributeContainer(AttributeProvider container)
Description copied from class:MultiAttributeProviderAdd a container in this set.- Overrides:
addAttributeContainerin classMultiAttributeProvider- Parameters:
container- the container.- Returns:
trueif the container has been added, otherwisefalse
-
removeAttributeContainer
public boolean removeAttributeContainer(AttributeProvider container)
Description copied from class:MultiAttributeProviderRemove a container in this set.- Overrides:
removeAttributeContainerin classMultiAttributeProvider- Parameters:
container- the container.- Returns:
trueif the container has been removed, otherwisefalse
-
addAttributeChangeListener
public void addAttributeChangeListener(AttributeChangeListener listener)
Description copied from interface:AttributeCollectionAdd a listener on the attribute value changes.- Specified by:
addAttributeChangeListenerin interfaceAttributeCollection- Parameters:
listener- the listener.
-
removeAttributeChangeListener
public void removeAttributeChangeListener(AttributeChangeListener listener)
Description copied from interface:AttributeCollectionRemove a listener on the attribute value changes.- Specified by:
removeAttributeChangeListenerin 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:AttributeCollectionForce this provider to synchronized the memory state of the attributes with a remote storage area.- Specified by:
flushin interfaceAttributeCollection
-
removeAllAttributes
public boolean removeAllAttributes()
Description copied from interface:AttributeCollectionRemove all the attributes.- Specified by:
removeAllAttributesin interfaceAttributeCollection- Returns:
falseif something wrong appends
-
removeAttribute
public boolean removeAttribute(String name)
Description copied from interface:AttributeCollectionRemove the given attribute.- Specified by:
removeAttributein interfaceAttributeCollection- Parameters:
name- is the name of the attribute to remove.- Returns:
trueon success, otherwhisefalse
-
renameAttribute
public boolean renameAttribute(String oldname, String newname)
Description copied from interface:AttributeCollectionRename the attribute.If a attribute named
newnamealready exists, this function will replyfalse.This function is equivalent to
renameAttribute(oldname, newname, false).- Specified by:
renameAttributein interfaceAttributeCollection- Parameters:
oldname- is the name of the attribute to rename.newname- is the new name of the attribute.- Returns:
falseif something wrong appends
-
renameAttribute
public boolean renameAttribute(String oldname, String newname, boolean overwrite)
Description copied from interface:AttributeCollectionRename the attribute .- Specified by:
renameAttributein interfaceAttributeCollection- Parameters:
oldname- is the name of the attribute to rename.newname- is the new name of the attribute.overwrite- must betrueif the value of an existing attribute named bynewnamemust be overwritten by the value of the attribute namedoldname.- Returns:
falseif something wrong appends
-
addAttributes
public void addAttributes(AttributeProvider content) throws AttributeException
Description copied from interface:AttributeCollectionPut 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:
addAttributesin 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:AttributeCollectionPut 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:
addAttributesin 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:AttributeCollectionSet 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:
setAttributesin 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:AttributeCollectionSet 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:
setAttributesin 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the value for the given attribute.- Specified by:
setAttributein 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:AttributeCollectionSet the type of the attribute with the given name.- Specified by:
setAttributeTypein interfaceAttributeCollection- Parameters:
name- is the name of the attributetype- is the desired type.- Returns:
- the changed attribute or
null - Throws:
AttributeException- on error.
-
-