java.lang.Object | |
↳ | org.apache.commons.collections.map.Flat3Map |
A Map
implementation that stores data in simple fields until
the size is greater than 3.
This map is designed for performance and can outstrip HashMap. It also has good garbage collection characteristics.
The performance gains on puts are due to not needing to create a Map Entry object. This is a large saving not only in performance but in garbage collection.
Whilst in flat mode this map is also easy for the garbage collector to dispatch. This is because it contains no complex objects or arrays which slow the progress.
Do not use Flat3Map
if the size is likely to grow beyond 3.
Note that Flat3Map is not synchronized and is not thread-safe.
If you wish to use this map from multiple threads concurrently, you must use
appropriate synchronization. The simplest approach is to wrap this map
using synchronizedMap(Map)
. This class may throw
exceptions when accessed by concurrent threads without synchronization.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor.
| |||||||||||
Constructor copying elements from another map.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clears the map, resetting the size to zero and nullifying references
to avoid garbage collection issues.
| |||||||||||
Clones the map without cloning the keys or values.
| |||||||||||
Checks whether the map contains the specified key.
| |||||||||||
Checks whether the map contains the specified value.
| |||||||||||
Gets the entrySet view of the map.
| |||||||||||
Compares this map with another.
| |||||||||||
Gets the value mapped to the key specified.
| |||||||||||
Gets the standard Map hashCode.
| |||||||||||
Checks whether the map is currently empty.
| |||||||||||
Gets the keySet view of the map.
| |||||||||||
Gets an iterator over the map.
| |||||||||||
Puts a key-value mapping into this map.
| |||||||||||
Puts all the values from the specified map into this map.
| |||||||||||
Removes the specified mapping from this map.
| |||||||||||
Gets the size of the map.
| |||||||||||
Gets the map as a String.
| |||||||||||
Gets the values view of the map.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create an instance of the map used for storage when in delegation mode.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
| |||||||||||
From interface
org.apache.commons.collections.IterableMap
|
Constructor.
Constructor copying elements from another map.
map | the map to copy |
---|
NullPointerException | if the map is null |
---|
Clears the map, resetting the size to zero and nullifying references to avoid garbage collection issues.
Checks whether the map contains the specified key.
key | the key to search for |
---|
Checks whether the map contains the specified value.
value | the value to search for |
---|
Gets the entrySet view of the map.
Changes made to the view affect this map.
The Map Entry is not an independent object and changes as the
iterator progresses.
To simply iterate through the entries, use mapIterator()
.
Compares this map with another.
obj | the object to compare to |
---|
Gets the value mapped to the key specified.
key | the key |
---|
Gets the standard Map hashCode.
Checks whether the map is currently empty.
Gets the keySet view of the map.
Changes made to the view affect this map.
To simply iterate through the keys, use mapIterator()
.
Gets an iterator over the map. Changes made to the iterator affect this map.
A MapIterator returns the keys in the map. It also provides convenient methods to get the key and value, and set the value. It avoids the need to create an entrySet/keySet/values object. It also avoids creating the Map Entry object.
Puts a key-value mapping into this map.
key | the key to add |
---|---|
value | the value to add |
Puts all the values from the specified map into this map.
map | the map to add |
---|
NullPointerException | if the map is null |
---|
Removes the specified mapping from this map.
key | the mapping to remove |
---|
Gets the size of the map.
Gets the values view of the map.
Changes made to the view affect this map.
To simply iterate through the values, use mapIterator()
.
Create an instance of the map used for storage when in delegation mode.
This can be overridden by subclasses to provide a different map implementation. Not every AbstractHashedMap is suitable, identity and reference based maps would be poor choices.