org.javimmutable.collections.hash
Class EmptyHashMap<K,V>

java.lang.Object
  extended by org.javimmutable.collections.common.AbstractJImmutableMap<K,V>
      extended by org.javimmutable.collections.hash.EmptyHashMap<K,V>
Type Parameters:
K -
V -
All Implemented Interfaces:
Iterable<JImmutableMap.Entry<K,V>>, Cursorable<JImmutableMap.Entry<K,V>>, Insertable<JImmutableMap.Entry<K,V>>, JImmutableMap<K,V>, Mapped<K,V>

@Immutable
public class EmptyHashMap<K,V>
extends AbstractJImmutableMap<K,V>

Singleton implementation of JImmutableMap that contains no elements. When a value is assigned to the map a JImmutableHashMap is created that manages hash collisions using a tree if key is Comparable or a list otherwise.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.javimmutable.collections.JImmutableMap
JImmutableMap.Entry<K,V>
 
Method Summary
 JImmutableMap<K,V> assign(K key, V value)
          Sets the value associated with a specific key.
 Cursor<JImmutableMap.Entry<K,V>> cursor()
           
 JImmutableMap<K,V> delete(K key)
          Deletes the entry for the specified key (if any).
 JImmutableMap<K,V> deleteAll()
           
 Holder<V> find(K key)
          Search for a value within the map and return a Holder indicating if the value was found and, if it was found, the value itself.
 Holder<JImmutableMap.Entry<K,V>> findEntry(K key)
          Search for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself.
 V getValueOr(K key, V defaultValue)
          Return the value associated with key or defaultValue if no value is associated.
 int size()
          Return the number of entries in the map.
 
Methods inherited from class org.javimmutable.collections.common.AbstractJImmutableMap
equals, get, getMap, hashCode, insert, isEmpty, iterator, keysCursor, toString, valuesCursor
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

find

@Nonnull
public Holder<V> find(@Nonnull
                              K key)
Description copied from interface: JImmutableMap
Search for a value within the map and return a Holder indicating if the value was found and, if it was found, the value itself. Holder allows null values to be returned unambiguously.

Parameters:
key - non-null key to search for
Returns:
empty Holder if not found, otherwise filled Holder with value

findEntry

@Nonnull
public Holder<JImmutableMap.Entry<K,V>> findEntry(@Nonnull
                                                          K key)
Description copied from interface: JImmutableMap
Search for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself.

Parameters:
key - non-null key to search for
Returns:
empty Holder if not found, otherwise filled Holder with Entry

assign

@Nonnull
public JImmutableMap<K,V> assign(@Nonnull
                                         K key,
                                         V value)
Description copied from interface: JImmutableMap
Sets the value associated with a specific key. Key must be non-null but value can be null. If the key already has a value in the map the old value is discarded and the new value is stored in its place. Returns a new PersistentMap reflecting any changes. The original map is always left unchanged.

Parameters:
key - non-null key
value - possibly null value
Returns:
new map reflecting the change

delete

@Nonnull
public JImmutableMap<K,V> delete(@Nonnull
                                         K key)
Description copied from interface: JImmutableMap
Deletes the entry for the specified key (if any). Returns a new map if the value was deleted or the current map if the key was not contained in the map.

Parameters:
key - non-null key
Returns:
same or different map depending on whether key was removed

size

public int size()
Description copied from interface: JImmutableMap
Return the number of entries in the map.

Returns:

deleteAll

@Nonnull
public JImmutableMap<K,V> deleteAll()
Returns:
an equivalent collection with no values

cursor

@Nonnull
public Cursor<JImmutableMap.Entry<K,V>> cursor()

getValueOr

public V getValueOr(K key,
                    V defaultValue)
Description copied from interface: Mapped
Return the value associated with key or defaultValue if no value is associated. Note that if defaultValue is an acceptable value to the container then this method will be ambiguous and find() should be used instead.

Parameters:
key - identifies the value to retrieve
defaultValue - value to return if no entry exists for key
Returns:
value associated with key or defaultValue if no value is associated


Copyright © 2014 Burton Computer Corporation. All rights reserved.