Javolution 6.0.0 java
javolution.util.FastMap< K, V > Class Template Reference
Inheritance diagram for javolution.util.FastMap< K, V >:
[legend]
Collaboration diagram for javolution.util.FastMap< K, V >:
[legend]

Public Member Functions

 FastMap ()
 
 FastMap (Equality<? super K > keyEquality)
 
 FastMap (Equality<? super K > keyEquality, Equality<? super V > valueEquality)
 
FastMap< K, V > atomic ()
 
FastMap< K, V > shared ()
 
FastMap< K, V > parallel ()
 
FastMap< K, V > sequential ()
 
FastMap< K, V > unmodifiable ()
 
FastSet< K > keySet ()
 
FastCollection< V > values ()
 
FastSet< Entry< K, V > > entrySet ()
 
void perform (Consumer<? extends Map< K, V >> action)
 
void update (Consumer<? extends Map< K, V >> action)
 
int size ()
 
boolean isEmpty ()
 
boolean containsKey (Object key)
 
boolean containsValue (Object value)
 
get (Object key)
 
put (K key, V value)
 
void putAll (Map<? extends K, ? extends V > map)
 
remove (Object key)
 
void clear ()
 
putIfAbsent (K key, V value)
 
boolean remove (Object key, Object value)
 
boolean replace (K key, V oldValue, V newValue)
 
replace (K key, V value)
 
FastMap< K, V > putAll (FastMap<? extends K, ? extends V > that)
 
String toString ()
 

Protected Member Functions

 FastMap (MapService< K, V > service)
 
MapService< K, V > service ()
 

Package Functions

public< T extends Map< K, V > > Immutable< T > toImmutable ()
 

Private Attributes

final MapService< K, V > service
 

Static Private Attributes

static final long serialVersionUID = 0x600L
 

Detailed Description

A high-performance hash map with real-time behavior. Related to FastCollection, fast map supports various views.

  • atomic - Thread-safe view for which all reads are mutex-free and map updates (e.g. putAll) are atomic.
  • shared - View allowing concurrent modifications.
  • parallel - A view allowing parallel processing including updates.
  • sequential - View disallowing parallel processing.
  • unmodifiable - View which does not allow any modifications.
  • entrySet - FastSet view over the map entries allowing entries to be added/removed.
  • keySet - FastSet view over the map keys allowing keys to be added (map entry with
    null
    value).
  • values - FastCollection view over the map values (add not supported).


The iteration order over the map keys, values or entries is deterministic (unlike java.util.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.

[code] 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> treeMap = new FastSortedMap<Foo, Bar>(); FastMap<Foo, Bar> concurrentSkipListMap = new FastSortedMap<Foo, Bar>().shared(); FastMap<Foo, Bar> identityHashMap = new FastMap<Foo, Bar>(Equalities.IDENTITY); [/code]

and adds more ...

[code] FastMap<Foo, Bar> atomicMap = new FastMap<Foo, Bar>().atomic(); // Mutex-free access, all updates (e.g. putAll) atomics (unlike ConcurrentHashMap). FastMap<Foo, Bar> atomicTree = new FastSortedMap<Foo, Bar>().atomic(); // Mutex-free access, all updates (e.g. putAll) atomics. FastMap<Foo, Bar> parallelMap = new FastMap<Foo, Bar>().parallel(); // Map actions (perform/update) performed concurrently. FastMap<Foo, Bar> linkedConcurrentHashMap = new FastMap<Foo, Bar>().shared(); // No equivalent in java.util ! FastMap<String, Bar> lexicalHashMap = new FastMap<String, Bar>(Equalities.LEXICAL); // Allows for value retrieval using any CharSequence key. FastMap<String, Bar> fastStringHashMap = new FastMap<String, Bar>(Equalities.LEXICAL_FAST); // Same with faster hashcode calculations. ... [/code]

Of course all views (entry, key, values) over a fast map are fast collections and allow parallel processing. [code] Consumer<Collection<String>> removeNull = new Consumer<Collection<String>>() {
public void accept(Collection<String> view) { Iterator<String> it = view.iterator(); while (it.hasNext()) { if (it.next() == null) it.remove(); } } }; FastMap<Person, String> names = ... names.values().update(removeNull); // Remove all entries with null values. names.atomic().values().update(removeNull); // Same but performed atomically. names.parallel().values().update(removeNull); // Same but performed in parallel. [/code]

Author
Jean-Marie Dautelle
Version
6.0, July 21, 2013

Definition at line 97 of file FastMap.java.

Constructor & Destructor Documentation

◆ FastMap() [1/4]

Creates an empty fast map.

Definition at line 110 of file FastMap.java.

110  {
111  this(Equalities.STANDARD);
112  }

◆ FastMap() [2/4]

javolution.util.FastMap< K, V >.FastMap ( Equality<? super K >  keyEquality)

Creates an empty fast map using the specified comparator for keys equality.

Definition at line 118 of file FastMap.java.

118  {
119  this(keyEquality, Equalities.STANDARD);
120  }

◆ FastMap() [3/4]

javolution.util.FastMap< K, V >.FastMap ( Equality<? super K >  keyEquality,
Equality<? super V >  valueEquality 
)

Creates an empty fast map using the specified comparators for keys equality and values equality.

Definition at line 126 of file FastMap.java.

127  {
128  service = new FastMapImpl<K, V>(keyEquality, valueEquality);
129  }

◆ FastMap() [4/4]

javolution.util.FastMap< K, V >.FastMap ( MapService< K, V >  service)
protected

Creates a map backed up by the specified service implementation.

Definition at line 134 of file FastMap.java.

134  {
135  this.service = service;
136  }

Member Function Documentation

◆ atomic()

FastMap<K, V> javolution.util.FastMap< K, V >.atomic ( )

Returns an atomic view over this map. All operations that write or access multiple elements in the map (such as putAll(), keySet().retainAll(), ...) are atomic. Iterators on atomic collections are thread-safe (no ConcurrentModificationException possible).

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 150 of file FastMap.java.

150  {
151  return new FastMap<K, V>(new AtomicMapImpl<K, V>(service));
152  }

◆ clear()

void javolution.util.FastMap< K, V >.clear ( )

Removes all this map's entries.

Definition at line 343 of file FastMap.java.

343  {
344  service.clear();
345  }

◆ containsKey()

boolean javolution.util.FastMap< K, V >.containsKey ( Object  key)

Indicates if this map contains the specified key.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 301 of file FastMap.java.

301  {
302  return service.containsKey(key);
303  }

◆ containsValue()

boolean javolution.util.FastMap< K, V >.containsValue ( Object  value)

Indicates if this map contains the specified value.

Definition at line 308 of file FastMap.java.

308  {
309  return service.containsValue(value);
310  }

◆ entrySet()

FastSet<Entry<K, V> > javolution.util.FastMap< K, V >.entrySet ( )

Returns a set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set support adding/removing entries. As far as the set is concerned, two entries are considered equals if they have the same keys regardless of their values.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 236 of file FastMap.java.

236  {
237  return new FastSet<Entry<K, V>>(service.entrySet());
238  }

Referenced by javolution.util.FastMap< Object, javolution.util.Index >.toString().

Here is the caller graph for this function:

◆ get()

V javolution.util.FastMap< K, V >.get ( Object  key)

Returns the value for the specified key.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 315 of file FastMap.java.

315  {
316  return service.get(key);
317  }

Referenced by javolution.context.internal.LocalContextImpl.getValue(), and javolution.xml.internal.XMLContextImpl.searchFormat().

Here is the caller graph for this function:

◆ isEmpty()

boolean javolution.util.FastMap< K, V >.isEmpty ( )

Indicates if this map is empty

Definition at line 294 of file FastMap.java.

294  {
295  return service.isEmpty();
296  }

◆ keySet()

FastSet<K> javolution.util.FastMap< K, V >.keySet ( )

Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports adding new keys for which the corresponding entry value is always

null

.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 206 of file FastMap.java.

206  {
207  return new FastSet<K>(service.keySet());
208  }

◆ parallel()

FastMap<K, V> javolution.util.FastMap< K, V >.parallel ( )

Returns a parallel map. Parallel maps affect closure-based operations over the map or any of its views (entry, key, values, etc.), all others operations behaving the same. Parallel maps do not require this map to be thread-safe (internal synchronization).

See also
#perform(Consumer)
#update(Consumer)
FastCollection::parallel()

Definition at line 178 of file FastMap.java.

178  {
179  return new FastMap<K, V>(new ParallelMapImpl<K, V>(service));
180  }

◆ perform()

void javolution.util.FastMap< K, V >.perform ( Consumer<? extends Map< K, V >>  action)

Executes the specified read-only action on this map. That logic may be performed concurrently on sub-maps if this map is parallel.

Parameters
actionthe read-only action.
Exceptions
UnsupportedOperationExceptionif the action tries to update this map.
ClassCastExceptionif the action type is not compatible with this map (e.g. action on sorted map and this is a hash map).
See also
#update(Consumer)

Definition at line 258 of file FastMap.java.

258  {
259  service().perform((Consumer<MapService<K, V>>) action, service());
260  }

◆ put()

V javolution.util.FastMap< K, V >.put ( key,
value 
)

Associates the specified value with the specified key.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 322 of file FastMap.java.

322  {
323  return service.put(key, value);
324  }

Referenced by javolution.xml.internal.XMLContextImpl.searchFormat(), javolution.xml.internal.XMLContextImpl.setFormat(), and javolution.context.internal.LocalContextImpl.supersede().

Here is the caller graph for this function:

◆ putAll() [1/2]

FastMap<K, V> javolution.util.FastMap< K, V >.putAll ( FastMap<? extends K, ? extends V >  that)

Returns this map with the specified map's entries added.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 387 of file FastMap.java.

387  {
388  putAll((Map<? extends K, ? extends V>) that);
389  return this;
390  }

◆ putAll() [2/2]

void javolution.util.FastMap< K, V >.putAll ( Map<? extends K, ? extends V >  map)

Adds the specified map entries to this map.

Definition at line 329 of file FastMap.java.

329  {
330  service.putAll(map);
331  }

Referenced by javolution.util.FastMap< Object, javolution.util.Index >.putAll().

Here is the caller graph for this function:

◆ putIfAbsent()

V javolution.util.FastMap< K, V >.putIfAbsent ( key,
value 
)

Associates the specified value with the specified key only if the specified key has no current mapping.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 355 of file FastMap.java.

355  {
356  return service.putIfAbsent(key, value);
357  }

◆ remove() [1/2]

V javolution.util.FastMap< K, V >.remove ( Object  key)

Removes the entry for the specified key.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 336 of file FastMap.java.

336  {
337  return service.remove(key);
338  }

◆ remove() [2/2]

boolean javolution.util.FastMap< K, V >.remove ( Object  key,
Object  value 
)

Removes the entry for a key only if currently mapped to a given value.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 362 of file FastMap.java.

362  {
363  return service.remove(key, value);
364  }

◆ replace() [1/2]

boolean javolution.util.FastMap< K, V >.replace ( key,
oldValue,
newValue 
)

Replaces the entry for a key only if currently mapped to a given value.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 369 of file FastMap.java.

369  {
370  return service.replace(key, oldValue, newValue);
371  }

◆ replace() [2/2]

V javolution.util.FastMap< K, V >.replace ( key,
value 
)

Replaces the entry for a key only if currently mapped to some value.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 376 of file FastMap.java.

376  {
377  return service.replace(key, value);
378  }

◆ sequential()

FastMap<K, V> javolution.util.FastMap< K, V >.sequential ( )

Returns a sequential view of this collection. Using this view, all closure-based iterations are performed sequentially.

Definition at line 186 of file FastMap.java.

186  {
187  return new FastMap<K, V>(new SequentialMapImpl<K, V>(service));
188  }

◆ service()

MapService<K, V> javolution.util.FastMap< K, V >.service ( )
protected

Returns this map service implementation.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 420 of file FastMap.java.

420  {
421  return service;
422  }

◆ shared()

FastMap<K, V> javolution.util.FastMap< K, V >.shared ( )

Returns a thread-safe view over this map. The shared view allows for concurrent read as long as there is no writer. The default implementation is based on readers-writers locks giving priority to writers. Iterators on shared collections are thread-safe (no ConcurrentModificationException possible).

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 164 of file FastMap.java.

164  {
165  return new FastMap<K, V>(new SharedMapImpl<K, V>(service));
166  }

◆ size()

int javolution.util.FastMap< K, V >.size ( )

Returns the number of entries/keys/values in this map.

Definition at line 287 of file FastMap.java.

287  {
288  return service.size();
289  }

◆ toImmutable()

public<T extends Map<K, V> > Immutable<T> javolution.util.FastMap< K, V >.toImmutable ( )
package

Returns an immutable reference over this map. The immutable value is an 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).

Definition at line 398 of file FastMap.java.

398  {
399  return new Immutable<T>() {
400  @SuppressWarnings("unchecked")
401  final T value = (T) unmodifiable();
402 
403  @Override
404  public T value() {
405  return value;
406  }
407  };
408  }

◆ toString()

String javolution.util.FastMap< K, V >.toString ( )

Returns the string representation of this map entries.

Definition at line 413 of file FastMap.java.

413  {
414  return TextContext.getFormat(FastCollection.class).format(entrySet());
415  }

◆ unmodifiable()

FastMap<K, V> javolution.util.FastMap< K, V >.unmodifiable ( )

Returns an unmodifiable view over this map. Any attempt to modify the map through this view will result into a java.lang.UnsupportedOperationException being raised.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 195 of file FastMap.java.

195  {
196  return new FastMap<K, V>(new UnmodifiableMapImpl<K, V>(service));
197  }

Referenced by javolution.util.FastMap< Object, javolution.util.Index >.toImmutable().

Here is the caller graph for this function:

◆ update()

void javolution.util.FastMap< K, V >.update ( Consumer<? extends Map< K, V >>  action)

Executes the specified update action on this map. That logic may be performed concurrently on sub-maps if this map is parallel. For atomic maps the update is atomic (either concurrent readers see the full result of the action or nothing).

Parameters
actionthe update action.
Exceptions
ClassCastExceptionif the action type is not compatible with this map (e.g. action on sorted map and this is a hash map).
See also
#perform(Consumer)

Definition at line 276 of file FastMap.java.

276  {
277  service().update((Consumer<MapService<K, V>>) action, service());
278  }

◆ values()

FastCollection<V> javolution.util.FastMap< K, V >.values ( )

Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports removing values (hence entries) but not adding new values.

Definition at line 216 of file FastMap.java.

216  {
217  return new FastCollection<V>() {
218  private static final long serialVersionUID = 0x600L; // Version.
219  private final CollectionService<V> serviceValues = service.values();
220 
221  @Override
222  protected CollectionService<V> service() {
223  return serviceValues;
224  }
225  };
226  }

Member Data Documentation

◆ serialVersionUID

final long javolution.util.FastMap< K, V >.serialVersionUID = 0x600L
staticprivate

◆ service

final MapService<K, V> javolution.util.FastMap< K, V >.service
private

Holds the actual map service implementation.

Reimplemented in javolution.util.FastSortedMap< K, V >.

Definition at line 105 of file FastMap.java.

Referenced by javolution.util.FastMap< Object, javolution.util.Index >.atomic(), javolution.util.FastMap< Object, javolution.util.Index >.clear(), javolution.util.FastMap< Object, javolution.util.Index >.containsKey(), javolution.util.FastMap< Object, javolution.util.Index >.containsValue(), javolution.util.FastMap< Object, javolution.util.Index >.entrySet(), javolution.util.FastMap< Object, javolution.util.Index >.FastMap(), javolution.util.FastMap< Object, javolution.util.Index >.get(), javolution.util.FastMap< Object, javolution.util.Index >.isEmpty(), javolution.util.FastMap< Object, javolution.util.Index >.keySet(), javolution.util.FastMap< Object, javolution.util.Index >.parallel(), javolution.util.FastMap< Object, javolution.util.Index >.perform(), javolution.util.FastMap< Object, javolution.util.Index >.put(), javolution.util.FastMap< Object, javolution.util.Index >.putAll(), javolution.util.FastMap< Object, javolution.util.Index >.putIfAbsent(), javolution.util.FastMap< Object, javolution.util.Index >.remove(), javolution.util.FastMap< Object, javolution.util.Index >.replace(), javolution.util.FastMap< Object, javolution.util.Index >.sequential(), javolution.util.FastMap< Object, javolution.util.Index >.service(), javolution.util.FastMap< Object, javolution.util.Index >.shared(), javolution.util.FastMap< Object, javolution.util.Index >.size(), javolution.util.FastMap< Object, javolution.util.Index >.unmodifiable(), javolution.util.FastMap< Object, javolution.util.Index >.update(), and javolution.util.FastMap< Object, javolution.util.Index >.values().


The documentation for this class was generated from the following file:
javolution.util.FastMap.putAll
void putAll(Map<? extends K, ? extends V > map)
Definition: FastMap.java:329
javolution.util.FastMap.entrySet
FastSet< Entry< K, V > > entrySet()
Definition: FastMap.java:236
javolution.util.FastMap.serialVersionUID
static final long serialVersionUID
Definition: FastMap.java:100
javolution.util.FastMap.service
final MapService< K, V > service
Definition: FastMap.java:105
javolution.util.FastMap.unmodifiable
FastMap< K, V > unmodifiable()
Definition: FastMap.java:195