Package org.arakhne.afc.attrs.collection
Class MultiAttributeProvider
- java.lang.Object
-
- org.arakhne.afc.attrs.collection.AbstractAttributeProvider
-
- org.arakhne.afc.attrs.collection.MultiAttributeProvider
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Attribute>
,AttributeProvider
,JsonableObject
- Direct Known Subclasses:
MultiAttributeCollection
public class MultiAttributeProvider extends AbstractAttributeProvider
This class contains a collection of attribute containers and tries to gather the data. This class contains a collection of AttributeContainers and exhibites the values of the attributes of all these containers. 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.
- 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 Modifier and Type Class Description (package private) static class
MultiAttributeProvider.ManyValueAttributeValue
This class provides an implementation of attribute value that may be marked with an indicators that many values are possibles for the attribute.
-
Constructor Summary
Constructors Constructor Description MultiAttributeProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addAttributeContainer(AttributeProvider container)
Add a container in this set.(package private) static void
assign(MultiAttributeProvider.ManyValueAttributeValue v1, AttributeValue v2)
Assign the value v2 to v1 and change v1 according to the types of v1 and v2.(package private) static AttributeValue
canonize(MultiAttributeProvider.ManyValueAttributeValue v)
Replace any indicator put byassign(ManyValueAttributeValue, AttributeValue)
to retreive a standard attribute value.MultiAttributeProvider
clone()
Make a deep copy of this object and replies the copy.protected Collection<AttributeProvider>
containers()
Replies a collection on the containers.void
freeMemory()
Clean the internal memory-storage structures if they exist.Collection<String>
getAllAttributeNames()
Replies all the attribute names.Collection<Attribute>
getAllAttributes()
Replies all the attributes.Map<AttributeType,Collection<Attribute>>
getAllAttributesByType()
Replies all the attributes sorted by type.AttributeValue
getAttribute(String name)
Replies the value for the given attribute.AttributeValue
getAttribute(String name, AttributeValue defaultValue)
Replies the value for the given attribute.int
getAttributeContainerCount()
Replies the number of attribute containers in this MultiAttributeContainer.int
getAttributeCount()
Replies the count of attributes.Attribute
getAttributeObject(String name)
Replies the attribute with the given name.boolean
hasAttribute(String name)
Replies if the given attribute exists.boolean
removeAttributeContainer(AttributeProvider container)
Remove a container in this set.void
toMap(Map<String,Object> mapToFill)
Fill the given map with the values stored in this attribute provider.-
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
toMap
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
cache
transient Map<String,AttributeValue> cache
Cache of the attribute values.
-
-
Method Detail
-
toMap
public void toMap(Map<String,Object> mapToFill)
Description copied from interface:AttributeProvider
Fill the given map with the values stored in this attribute provider.- Parameters:
mapToFill
- is the map to fill, nevernull
.
-
assign
static void assign(MultiAttributeProvider.ManyValueAttributeValue v1, AttributeValue v2)
Assign the value v2 to v1 and change v1 according to the types of v1 and v2. Do not forget to invokecanonize(ManyValueAttributeValue)
onv1
.- Parameters:
v1
- first value.v2
- second value.
-
canonize
static AttributeValue canonize(MultiAttributeProvider.ManyValueAttributeValue v)
Replace any indicator put byassign(ManyValueAttributeValue, AttributeValue)
to retreive a standard attribute value.- Parameters:
v
- is the value to canonize.- Returns:
- the canonized value.
-
containers
@Pure protected Collection<AttributeProvider> containers()
Replies a collection on the containers.- Returns:
- a collection on the containers.
-
addAttributeContainer
public boolean addAttributeContainer(AttributeProvider container)
Add a container in this set.- Parameters:
container
- the container.- Returns:
true
if the container has been added, otherwisefalse
-
removeAttributeContainer
public boolean removeAttributeContainer(AttributeProvider container)
Remove a container in this set.- Parameters:
container
- the container.- Returns:
true
if the container has been removed, otherwisefalse
-
getAttributeContainerCount
@Pure public int getAttributeContainerCount()
Replies the number of attribute containers in this MultiAttributeContainer.- Returns:
- the number of attribute containers in this MultiAttributeContainer.
-
clone
@Pure public MultiAttributeProvider clone()
Description copied from class:AbstractAttributeProvider
Make a deep copy of this object and replies the copy.- Specified by:
clone
in interfaceAttributeProvider
- Overrides:
clone
in classAbstractAttributeProvider
- Returns:
- the deep copy.
-
freeMemory
public void freeMemory()
Description copied from interface:AttributeProvider
Clean the internal memory-storage structures if they exist.This function permits to limit the memory usage without removing the attribute value from a hard storage area (database, files...). The attribute which are freed by this method could be reloaded in memory with a call to a getting method.
-
getAllAttributes
@Pure public Collection<Attribute> getAllAttributes()
Description copied from interface:AttributeProvider
Replies all the attributes.- Returns:
- the list of all attributes
-
getAllAttributesByType
@Pure public Map<AttributeType,Collection<Attribute>> getAllAttributesByType()
Description copied from interface:AttributeProvider
Replies all the attributes sorted by type.The keys of the returned hashtable are the types and the values are array of attributes (
Vector
).- Returns:
- the attributes grouped by type.
-
getAttribute
@Pure public AttributeValue getAttribute(String name)
Description copied from interface:AttributeProvider
Replies the value for the given attribute.- Parameters:
name
- the name.- Returns:
- the value or
null
-
getAttribute
@Pure public AttributeValue getAttribute(String name, AttributeValue defaultValue)
Description copied from interface:AttributeProvider
Replies the value for the given attribute.- Parameters:
name
- the name.defaultValue
- is the default value replied if the attribute has no value.- Returns:
- the value or
null
-
getAttributeCount
@Pure public int getAttributeCount()
Description copied from interface:AttributeProvider
Replies the count of attributes.- Returns:
- the count of attributes.
-
getAllAttributeNames
@Pure public Collection<String> getAllAttributeNames()
Description copied from interface:AttributeProvider
Replies all the attribute names. This function never load the attribute values even if they are not inside the storage layer.- Returns:
- the list of all attribute names.
-
getAttributeObject
@Pure public Attribute getAttributeObject(String name)
Description copied from interface:AttributeProvider
Replies the attribute with the given name.- Parameters:
name
- the name.- Returns:
- the attribute or
null
-
hasAttribute
@Pure public boolean hasAttribute(String name)
Description copied from interface:AttributeProvider
Replies if the given attribute exists.- Parameters:
name
- the name.- Returns:
true
is an attribute with the given name exists, otherwisefalse
-
-