org.javimmutable.collections
Interface JImmutableMap<K,V>

Type Parameters:
K -
V -
All Superinterfaces:
Cursorable<JImmutableMap.Entry<K,V>>, Insertable<JImmutableMap.Entry<K,V>>, Iterable<JImmutableMap.Entry<K,V>>, Mapped<K,V>
All Known Implementing Classes:
AbstractJImmutableMap, EmptyHashMap, JImmutableHashMap, JImmutableInsertOrderMap, JImmutableTreeMap

@Immutable
public interface JImmutableMap<K,V>
extends Insertable<JImmutableMap.Entry<K,V>>, Mapped<K,V>, Iterable<JImmutableMap.Entry<K,V>>, Cursorable<JImmutableMap.Entry<K,V>>

Interface for persistent data structures that allow storage and retrieval of key/value pairs. null is always an allowed value within the map but is not an allowed key.


Nested Class Summary
static interface JImmutableMap.Entry<K,V>
          An immutable entry in the map.
 
Method Summary
 JImmutableMap<K,V> assign(K key, V value)
          Sets the value associated with a specific key.
 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.
 Map<K,V> getMap()
          Creates an unmodifiable java.util.Map reflecting the values of this PersistentMap.
 Insertable<JImmutableMap.Entry<K,V>> insert(JImmutableMap.Entry<K,V> value)
          Add key/value entry to the map, replacing any existing entry with same key.
 boolean isEmpty()
           
 Cursor<K> keysCursor()
          Creates a Cursor to access all of the Map's keys.
 int size()
          Return the number of entries in the map.
 Cursor<V> valuesCursor()
          Creates a Cursor to access all of the Map's values.
 
Methods inherited from interface org.javimmutable.collections.Mapped
get, getValueOr
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface org.javimmutable.collections.Cursorable
cursor
 

Method Detail

insert

@Nonnull
Insertable<JImmutableMap.Entry<K,V>> insert(@Nonnull
                                                    JImmutableMap.Entry<K,V> value)
Add key/value entry to the map, replacing any existing entry with same key.

Specified by:
insert in interface Insertable<JImmutableMap.Entry<K,V>>
Parameters:
value -
Returns:

find

@Nonnull
Holder<V> find(@Nonnull
                       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 allows null values to be returned unambiguously.

Specified by:
find in interface Mapped<K,V>
Parameters:
key - non-null key to search for
Returns:
empty Holder if not found, otherwise filled Holder with value

findEntry

@Nonnull
Holder<JImmutableMap.Entry<K,V>> findEntry(@Nonnull
                                                   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.

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

assign

@Nonnull
JImmutableMap<K,V> assign(@Nonnull
                                  K key,
                                  V value)
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
JImmutableMap<K,V> delete(@Nonnull
                                  K key)
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

int size()
Return the number of entries in the map.

Returns:

isEmpty

boolean isEmpty()
Returns:
true only if list contains no values

deleteAll

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

getMap

@Nonnull
Map<K,V> getMap()
Creates an unmodifiable java.util.Map reflecting the values of this PersistentMap.

Returns:
Map view of this PersistentMap

keysCursor

@Nonnull
Cursor<K> keysCursor()
Creates a Cursor to access all of the Map's keys.

Returns:

valuesCursor

@Nonnull
Cursor<V> valuesCursor()
Creates a Cursor to access all of the Map's values.

Returns:


Copyright © 2014 Burton Computer Corporation. All rights reserved.