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

Type Parameters:
K -
V -
All Superinterfaces:
Cursorable<JImmutableMap.Entry<K,JImmutableList<V>>>, Insertable<JImmutableMap.Entry<K,V>>, Iterable<JImmutableMap.Entry<K,JImmutableList<V>>>, Mapped<K,JImmutableList<V>>
All Known Implementing Classes:
AbstractJImmutableListMap, JImmutableHashListMap, JImmutableInsertOrderListMap, JImmutableTreeListMap

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

Interface for maps that map keys to lists of values.


Method Summary
 JImmutableListMap<K,V> assign(K key, JImmutableList<V> value)
          Sets the list associated with a specific key.
 JImmutableListMap<K,V> delete(K key)
          Deletes the entry for the specified key (if any).
 JImmutableListMap<K,V> deleteAll()
           
 JImmutableList<V> getList(K key)
          Return the list associated with key or an empty list if no list is associated.
 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.
 JImmutableListMap<K,V> insert(K key, V value)
          Add value to the list for the specified key.
 boolean isEmpty()
           
 Cursor<K> keysCursor()
          Creates a Cursor to access all of the Map's keys.
 int size()
          Return the number of keys in the map.
 Cursor<V> valuesCursor(K key)
          Creates a Cursor to access all of the specified key's list.
 
Methods inherited from interface org.javimmutable.collections.Mapped
find, get, getValueOr
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface org.javimmutable.collections.Cursorable
cursor
 

Method Detail

getList

@Nonnull
JImmutableList<V> getList(@Nonnull
                                  K key)
Return the list associated with key or an empty list if no list is associated.

Parameters:
key - identifies the value to retrieve
Returns:
list associated with key or an empty list if no value is associated

assign

@Nonnull
JImmutableListMap<K,V> assign(@Nonnull
                                      K key,
                                      @Nonnull
                                      JImmutableList<V> value)
Sets the list associated with a specific key. Key and value must be non-null. If the key already has a list in the map the old list is discarded and the new list is stored in its place. Returns a new JImmutableListMap reflecting any changes. The original map is always left unchanged.

Parameters:
key - non-null key
value - list of possibly null values to use for this key
Returns:
new map reflecting the change

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:

insert

@Nonnull
JImmutableListMap<K,V> insert(@Nonnull
                                      K key,
                                      @Nullable
                                      V value)
Add value to the list for the specified key. Note that this can create duplicate values in the list.

Parameters:
value -
value -
Returns:

delete

@Nonnull
JImmutableListMap<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 keys in the map.

Returns:

isEmpty

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

deleteAll

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

keysCursor

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

Returns:

valuesCursor

@Nonnull
Cursor<V> valuesCursor(@Nonnull
                               K key)
Creates a Cursor to access all of the specified key's list. If no list exists for key an empty cursor is returned.

Returns:
a (possibly empty) cursor for traversing the values associated with key


Copyright © 2014 Burton Computer Corporation. All rights reserved.