@Realtime @Parallelizable(mutexFree=false, comment="Shared views may use read-write locks.") public class FastMap<K,V> extends Object implements Map<K,V>, ConcurrentMap<K,V>, Serializable
A high-performance map with real-time
behavior;
smooth capacity increase/decrease and minimal memory footprint.
Fast maps support multiple views which can be chained.
unmodifiable()
- View which does not allow any modifications.shared()
- View allowing concurrent modifications.entrySet()
- FastSet
view over the map entries allowing
new entries to be added.keySet()
- FastSet
view over the map keys allowing
new keys to be added (null
value).values()
- FastCollection
view over the map values. The iteration order over the fast map keys, values or entries is deterministic
(unlike HashMap
). It is either the insertion order (default)
or the key order for the FastSortedMap
subclass.
This class permits null
keys.
Fast maps can advantageously replace any of the standard java.util
maps.
FastMap<Foo, Bar> hashMap = new FastMap<Foo, Bar>(); FastMap<Foo, Bar> concurrentHashMap = new FastMap<Foo, Bar>().shared(); // FastMap implements ConcurrentMap interface. FastMap<Foo, Bar> linkedHashMap = new FastMap<Foo, Bar>(); // Deterministic iteration order (insertion order). FastMap<Foo, Bar> linkedConcurrentHashMap = new FastMap<Foo, Bar>().shared(); // No equivalent in java.util ! FastMap<Foo, Bar> treeMap = new FastSortedMap<Foo, Bar>(); FastMap<Foo, Bar> concurrentSkipListMap = new FastSortedMap<Foo, Bar>().shared(); FastMap<Foo, Bar> identityHashMap = new FastMap<Foo, Bar>(Comparators.IDENTITY); FastMap<String, Bar> lexicalHashMap = new FastMap<String, Bar>(Comparators.LEXICAL); // Allows for value retrieval using any CharSequence key. FastMap<String, Bar> fastStringHashMap = new FastMap<String, Bar>(Comparators.LEXICAL_FAST); // Use constant-time hashcode calculation. ...
As for fast collections, an immutable
.
reference (or const reference) can be obtained
when the originator
guarantees that the map source cannot be modified.
Modifier | Constructor and Description |
---|---|
|
FastMap()
Creates an empty fast map.
|
|
FastMap(EqualityComparator<? super K> keyEquality)
Creates an empty fast map using the specified comparator for keys
equality.
|
|
FastMap(EqualityComparator<? super K> keyEquality,
EqualityComparator<? super V> valueEquality)
Creates an empty fast map using the specified comparators for keys
equality and values equality.
|
protected |
FastMap(MapService<K,V> service)
Creates a map backed up by the specified service implementation.
|
Modifier and Type | Method and Description |
---|---|
void |
atomic(Runnable update)
Executes the specified update in an atomic manner.
|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
FastSet<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in
this map.
|
V |
get(Object key) |
boolean |
isEmpty() |
FastSet<K> |
keySet()
Returns a set view of the keys contained in this map.
|
V |
put(K key,
V value) |
FastMap<K,V> |
putAll(FastMap<? extends K,? extends V> that)
Returns this map with the specified map's entries added.
|
void |
putAll(Map<? extends K,? extends V> map) |
V |
putIfAbsent(K key,
V value)
ConcurrentMap Interface.
|
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
V |
replace(K key,
V value) |
boolean |
replace(K key,
V oldValue,
V newValue) |
protected MapService<K,V> |
service()
Returns this map service implementation.
|
FastMap<K,V> |
shared()
Returns a thread-safe view over this map.
|
int |
size()
Map interface.
|
<T extends Map<K,V>> |
toImmutable()
Returns an immutable reference over this map.
|
FastMap<K,V> |
unmodifiable()
Returns an unmodifiable view over this map.
|
FastCollection<V> |
values()
Returns a collection view of the values contained in this map.
|
public FastMap()
public FastMap(EqualityComparator<? super K> keyEquality)
public FastMap(EqualityComparator<? super K> keyEquality, EqualityComparator<? super V> valueEquality)
protected FastMap(MapService<K,V> service)
public FastMap<K,V> unmodifiable()
UnsupportedOperationException
being raised.public FastMap<K,V> shared()
immutable
maps to be replaced at each update rather than shared views.public FastSet<K> keySet()
public FastCollection<V> values()
public FastSet<Map.Entry<K,V>> entrySet()
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
@Realtime(limit=LINEAR) public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public V putIfAbsent(K key, V value)
putIfAbsent
in interface ConcurrentMap<K,V>
public boolean remove(Object key, Object value)
remove
in interface ConcurrentMap<K,V>
public boolean replace(K key, V oldValue, V newValue)
replace
in interface ConcurrentMap<K,V>
public FastMap<K,V> putAll(FastMap<? extends K,? extends V> that)
@Parallelizable(mutexFree=false, comment="The map is locked during atomic updates") public void atomic(Runnable update)
shared
maps.update
- the update action to be executed on this map.public <T extends Map<K,V>> Immutable<T> toImmutable()
unmodifiable
view of this map
for which the caller guarantees that no change will ever be made
(e.g. there is no reference left to the original map).protected MapService<K,V> service()
Copyright © 2005-2013 Javolution. All Rights Reserved.