Package org.arakhne.afc.attrs.collection
Class BufferedAttributeCollection
- java.lang.Object
-
- org.arakhne.afc.attrs.collection.AbstractAttributeProvider
-
- org.arakhne.afc.attrs.collection.AbstractAttributeCollection
-
- org.arakhne.afc.attrs.collection.BufferedAttributeCollection
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Attribute>
,AttributeCollection
,AttributeProvider
,JsonableObject
public abstract class BufferedAttributeCollection extends AbstractAttributeCollection
This class implements an abstract attribute provider that use a memory cache.- 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
-
-
Constructor Summary
Constructors Constructor Description BufferedAttributeCollection()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BufferedAttributeCollection
clone()
Make a deep copy of this object and replies the copy.void
flush()
Force this provider to synchronized the memory state of the attributes with a remote storage area.void
freeMemory()
Clean the internal memory-storage structures if they exist.abstract 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.Attribute
getAttributeObject(String name)
Replies the attribute with the given name.boolean
hasAttribute(String name)
Replies if the given attribute exists.protected abstract AttributeValue
loadValue(String name)
Load a value from the data source.boolean
removeAllAttributes()
Remove all the attributes.protected abstract boolean
removeAllValues()
Remove all the values from the data source.boolean
removeAttribute(String name)
Remove the given attribute.protected abstract AttributeValue
removeValue(String name)
Remove a value from the data source.boolean
renameAttribute(String oldname, String newname, boolean overwrite)
Rename the attribute .protected abstract void
saveValue(String name, AttributeValue value)
Save a value into the data source.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.protected Attribute
setAttributeFromRawValue(String name, AttributeType type, Object value)
Set the attribute value.protected Attribute
setAttributeFromRawValue(String name, AttributeValue value)
Set the attribute value.Attribute
setAttributeType(String name, AttributeType type)
Set the type of the attribute with the given name.-
Methods inherited from class org.arakhne.afc.attrs.collection.AbstractAttributeCollection
addAttributeChangeListener, fireAttributeAddedEvent, fireAttributeChangedEvent, fireAttributeClearedEvent, fireAttributeRemovedEvent, fireAttributeRenamedEvent, isEventFirable, removeAttributeChangeListener, renameAttribute, setEventFirable
-
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.AttributeCollection
addAttributes, addAttributes, setAttributes, setAttributes
-
Methods inherited from interface org.arakhne.afc.attrs.collection.AttributeProvider
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, getAttributeCount, toMap, toMap
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface org.arakhne.afc.vmutil.json.JsonableObject
toJson
-
-
-
-
Method Detail
-
clone
@Pure public BufferedAttributeCollection clone()
Make a deep copy of this object and replies the copy.- Specified by:
clone
in interfaceAttributeCollection
- Specified by:
clone
in interfaceAttributeProvider
- Overrides:
clone
in classAbstractAttributeCollection
- Returns:
- the deep copy.
-
loadValue
protected abstract AttributeValue loadValue(String name) throws AttributeException
Load a value from the data source.- Parameters:
name
- is the name of the attribute to load- Returns:
- the value of the attribute.
- Throws:
AttributeException
- on error or when the attribute does not exist
-
getAllAttributeNames
@Pure public abstract 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.
-
saveValue
protected abstract void saveValue(String name, AttributeValue value) throws AttributeException
Save a value into the data source.- Parameters:
name
- is the name of the attribute to savevalue
- is the value of the attribute.- Throws:
AttributeException
- on error.
-
removeValue
protected abstract AttributeValue removeValue(String name) throws AttributeException
Remove a value from the data source.- Parameters:
name
- is the name of the attribute to remove- Returns:
- the removed value
- Throws:
AttributeException
- on error
-
removeAllValues
protected abstract boolean removeAllValues() throws AttributeException
Remove all the values from the data source.- Returns:
true
on success, otherwhisefalse
- Throws:
AttributeException
- on error
-
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
-
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
-
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
-
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.
-
setAttributeFromRawValue
protected Attribute setAttributeFromRawValue(String name, AttributeValue value) throws AttributeException
Set the attribute value.- Parameters:
name
- is the name of the attributevalue
- is the raw value to store.- Returns:
- the new created attribute
- Throws:
AttributeException
- on error.
-
setAttributeFromRawValue
protected Attribute setAttributeFromRawValue(String name, AttributeType type, Object value) throws AttributeException
Set the attribute value.- Parameters:
name
- is the name of the attributetype
- is the type of the attributevalue
- is the raw value to store.- Returns:
- the new created attribute
- 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.- Parameters:
name
- is the name of the attributetype
- is the desired type.- Returns:
- the changed attribute or
null
- Throws:
AttributeException
- on error.
-
setAttribute
public Attribute setAttribute(String name, AttributeValue value) throws AttributeException
Description copied from interface:AttributeCollection
Set the value for the given attribute.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- Parameters:
value
- is the value to store.- Returns:
- the changed attribute or
null
- Throws:
AttributeException
- on error.
-
removeAttribute
public boolean removeAttribute(String name)
Description copied from interface:AttributeCollection
Remove the given attribute.- Parameters:
name
- is the name of the attribute to remove.- Returns:
true
on success, otherwhisefalse
-
removeAllAttributes
public boolean removeAllAttributes()
Description copied from interface:AttributeCollection
Remove all the attributes.- Returns:
false
if something wrong appends
-
renameAttribute
public boolean renameAttribute(String oldname, String newname, boolean overwrite)
Description copied from interface:AttributeCollection
Rename the attribute .- 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
-
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.
-
-