Package org.apache.sis.feature
Class CharacteristicTypeMap
java.lang.Object
org.apache.sis.internal.util.AbstractMap<String,DefaultAttributeType<?>>
org.apache.sis.feature.CharacteristicTypeMap
- All Implemented Interfaces:
Map<String,
DefaultAttributeType<?>>
Implementation of the map returned by
DefaultAttributeType.characteristics()
.
Information provided by this implementation are also used by CharacteristicMap
.
Comparison with standard hash map
The straightforward approach would be to store the attributes directly as values in a standardHashMap
.
But instead of that, we store attributes in an array and the array indices in a HashMap
. This level of
indirection is useless if we consider only the DefaultAttributeType.characteristics()
method, since a
standard HashMap<String,AttributeType>
would work as well or better. However, this level of indirection
become useful for CharacteristicMap
(the map returned by AbstractAttribute.characteristics()
),
since it allows a more efficient storage. We do this effort because some applications may create a very large
amount of attribute instances.- Since:
- 0.5
- Version:
- 0.8
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.internal.util.AbstractMap
AbstractMap.EntryIterator<K,
V>, AbstractMap.IteratorAdapter<K, V>, AbstractMap.KeyIterator -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final DefaultAttributeType<?>[]
Characteristics of another attribute type (thesource
attribute given to the constructor).The names of attribute types listed in thecharacterizedBy
array, together where their index in the array.private static final WeakValueHashMap
<DefaultAttributeType<?>[], CharacteristicTypeMap> For sharing the sameCharacteristicTypeMap
instances among the attribute types having the same characteristics. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
CharacteristicTypeMap
(DefaultAttributeType<?> source, DefaultAttributeType<?>[] characterizedBy) Creates a new map for the given attribute characteristics. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(Object key) Returnstrue
if this map contains an attribute characteristic of the given name.boolean
containsValue
(Object key) Returnstrue
if this map contains the given attribute characteristic.(package private) static CharacteristicTypeMap
create
(DefaultAttributeType<?> source, DefaultAttributeType<?>[] characterizedBy) Creates a new map or return an existing map for the given attribute characteristics.protected AbstractMap.EntryIterator
<String, DefaultAttributeType<?>> Returns an iterator over the entries.Returns the attribute characteristic for the given name, ornull
if none.boolean
isEmpty()
Returnstrue
if there are no attribute characteristics.int
size()
Returns the number of attribute characteristics.Methods inherited from class org.apache.sis.internal.util.AbstractMap
addKey, addValue, clear, entrySet, equals, getOrDefault, hashCode, keySet, put, putAll, remove, toString, values
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
SHARED
For sharing the sameCharacteristicTypeMap
instances among the attribute types having the same characteristics. -
characterizedBy
Characteristics of another attribute type (thesource
attribute given to the constructor). This array shall not be modified. -
indices
The names of attribute types listed in thecharacterizedBy
array, together where their index in the array. This map shall not be modified.
-
-
Constructor Details
-
CharacteristicTypeMap
private CharacteristicTypeMap(DefaultAttributeType<?> source, DefaultAttributeType<?>[] characterizedBy) Creates a new map for the given attribute characteristics.This constructor does not clone the
characterizedBy
array. If that array is a user-provided argument, then cloning that array is caller responsibility.- Parameters:
source
- the attribute which is characterized bycharacterizedBy
.characterizedBy
- characteristics ofsource
. Should not be empty.- Throws:
IllegalArgumentException
- if two characteristics have the same name.
-
-
Method Details
-
create
static CharacteristicTypeMap create(DefaultAttributeType<?> source, DefaultAttributeType<?>[] characterizedBy) Creates a new map or return an existing map for the given attribute characteristics.This method does not clone the
characterizedBy
array. If that array is a user-provided argument, then cloning that array is caller responsibility.- Parameters:
source
- the attribute which is characterized bycharacterizedBy
.characterizedBy
- characteristics ofsource
. Should not be empty.- Returns:
- a map for this given characteristics.
- Throws:
IllegalArgumentException
- if two characteristics have the same name.
-
isEmpty
public boolean isEmpty()Returnstrue
if there are no attribute characteristics.- Specified by:
isEmpty
in interfaceMap<String,
DefaultAttributeType<?>> - Overrides:
isEmpty
in classAbstractMap<String,
DefaultAttributeType<?>> - Returns:
true
if this map contains no element.
-
size
public int size()Returns the number of attribute characteristics.- Specified by:
size
in interfaceMap<String,
DefaultAttributeType<?>> - Overrides:
size
in classAbstractMap<String,
DefaultAttributeType<?>>
-
containsKey
Returnstrue
if this map contains an attribute characteristic of the given name.- Specified by:
containsKey
in interfaceMap<String,
DefaultAttributeType<?>> - Overrides:
containsKey
in classAbstractMap<String,
DefaultAttributeType<?>> - Parameters:
key
- the key for which to test the presence of a value.- Returns:
true
if the map contains a non-null value for the given key.
-
containsValue
Returnstrue
if this map contains the given attribute characteristic.- Specified by:
containsValue
in interfaceMap<String,
DefaultAttributeType<?>> - Overrides:
containsValue
in classAbstractMap<String,
DefaultAttributeType<?>> - Parameters:
key
- the value for which to test the presence.- Returns:
true
if the map contains the given value.
-
get
Returns the attribute characteristic for the given name, ornull
if none. -
entryIterator
Returns an iterator over the entries. This is not the iterator returned by public API likeMap.entrySet().iterator()
.- Specified by:
entryIterator
in classAbstractMap<String,
DefaultAttributeType<?>> - Returns:
- an iterator over the entries in this map, or
null
.
-