Class CharacteristicTypeMap

All Implemented Interfaces:
Map<String, DefaultAttributeType<?>>

final class CharacteristicTypeMap extends AbstractMap<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 standard HashMap. 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
  • Field Details

    • SHARED

      private static final WeakValueHashMap<DefaultAttributeType<?>[], CharacteristicTypeMap> SHARED
      For sharing the same CharacteristicTypeMap instances among the attribute types having the same characteristics.
    • characterizedBy

      final DefaultAttributeType<?>[] characterizedBy
      Characteristics of another attribute type (the source attribute given to the constructor). This array shall not be modified.
    • indices

      final Map<String,Integer> indices
      The names of attribute types listed in the characterizedBy 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 by characterizedBy.
      characterizedBy - characteristics of source. Should not be empty.
      Throws:
      IllegalArgumentException - if two characteristics have the same name.
  • Method Details