org.javimmutable.collections.listmap
Class AbstractJImmutableListMap<K,V>

java.lang.Object
  extended by org.javimmutable.collections.listmap.AbstractJImmutableListMap<K,V>
All Implemented Interfaces:
Iterable<JImmutableMap.Entry<K,JImmutableList<V>>>, Cursorable<JImmutableMap.Entry<K,JImmutableList<V>>>, Insertable<JImmutableMap.Entry<K,V>>, JImmutableListMap<K,V>, Mapped<K,JImmutableList<V>>
Direct Known Subclasses:
JImmutableHashListMap, JImmutableInsertOrderListMap, JImmutableTreeListMap

@Immutable
public abstract class AbstractJImmutableListMap<K,V>
extends Object
implements JImmutableListMap<K,V>


Constructor Summary
protected AbstractJImmutableListMap(JImmutableMap<K,JImmutableList<V>> contents)
           
 
Method Summary
 JImmutableListMap<K,V> assign(K key, JImmutableList<V> value)
          Sets the list associated with a specific key.
protected  JImmutableList<V> copyList(JImmutableList<V> original)
          Overridable by derived classes to create a compatible copy of the specified list.
protected abstract  JImmutableListMap<K,V> create(JImmutableMap<K,JImmutableList<V>> map)
          Implemented by derived classes to create a new instance of the appropriate class.
 Cursor<JImmutableMap.Entry<K,JImmutableList<V>>> cursor()
           
 JImmutableListMap<K,V> delete(K key)
          Deletes the entry for the specified key (if any).
 JImmutableListMap<K,V> deleteAll()
           
protected  JImmutableList<V> emptyList()
          Overridable by derived classes to create a new empty list
 boolean equals(Object o)
           
 Holder<JImmutableList<V>> find(K key)
          Return a Holder containing the value associated wth the key or an empty Holder if no value is associated with the key.
 JImmutableList<V> get(K key)
          Return the value associated with key or null if no value is associated.
 JImmutableList<V> getList(K key)
          Return the list associated with key or an empty list if no list is associated.
 JImmutableList<V> getValueOr(K key, JImmutableList<V> defaultValue)
          Return the value associated with key or defaultValue if no value is associated.
 int hashCode()
           
 Insertable<JImmutableMap.Entry<K,V>> insert(JImmutableMap.Entry<K,V> e)
          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.
protected  JImmutableList<V> insertInList(JImmutableList<V> list, V value)
          Overridable by derived classes to insert a value into a list in some way.
 boolean isEmpty()
           
 Iterator<JImmutableMap.Entry<K,JImmutableList<V>>> iterator()
           
 Cursor<K> keysCursor()
          Creates a Cursor to access all of the Map's keys.
 int size()
          Return the number of keys in the map.
 String toString()
           
 Cursor<V> valuesCursor(K key)
          Creates a Cursor to access all of the specified key's list.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractJImmutableListMap

protected AbstractJImmutableListMap(JImmutableMap<K,JImmutableList<V>> contents)
Method Detail

getList

@Nonnull
public JImmutableList<V> getList(@Nonnull
                                         K key)
Description copied from interface: JImmutableListMap
Return the list associated with key or an empty list if no list is associated.

Specified by:
getList in interface JImmutableListMap<K,V>
Parameters:
key - identifies the value to retrieve
Returns:
list associated with key or an empty list if no value is associated

assign

@Nonnull
public JImmutableListMap<K,V> assign(@Nonnull
                                             K key,
                                             @Nonnull
                                             JImmutableList<V> value)
Description copied from interface: JImmutableListMap
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.

Specified by:
assign in interface JImmutableListMap<K,V>
Parameters:
key - non-null key
value - list of possibly null values to use for this key
Returns:
new map reflecting the change

insert

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

Specified by:
insert in interface JImmutableListMap<K,V>
Returns:

delete

@Nonnull
public JImmutableListMap<K,V> delete(@Nonnull
                                             K key)
Description copied from interface: JImmutableListMap
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.

Specified by:
delete in interface JImmutableListMap<K,V>
Parameters:
key - non-null key
Returns:
same or different map depending on whether key was removed

size

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

Specified by:
size in interface JImmutableListMap<K,V>
Returns:

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface JImmutableListMap<K,V>
Returns:
true only if list contains no values

keysCursor

@Nonnull
public Cursor<K> keysCursor()
Description copied from interface: JImmutableListMap
Creates a Cursor to access all of the Map's keys.

Specified by:
keysCursor in interface JImmutableListMap<K,V>
Returns:

valuesCursor

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

Specified by:
valuesCursor in interface JImmutableListMap<K,V>
Returns:
a (possibly empty) cursor for traversing the values associated with key

cursor

@Nonnull
public Cursor<JImmutableMap.Entry<K,JImmutableList<V>>> cursor()
Specified by:
cursor in interface Cursorable<JImmutableMap.Entry<K,JImmutableList<V>>>

insert

@Nonnull
public Insertable<JImmutableMap.Entry<K,V>> insert(@Nonnull
                                                           JImmutableMap.Entry<K,V> e)
Description copied from interface: JImmutableListMap
Add key/value entry to the map, replacing any existing entry with same key.

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

iterator

public Iterator<JImmutableMap.Entry<K,JImmutableList<V>>> iterator()
Specified by:
iterator in interface Iterable<JImmutableMap.Entry<K,JImmutableList<V>>>

get

@Nullable
public JImmutableList<V> get(K key)
Description copied from interface: Mapped
Return the value associated with key or null if no value is associated. Note that if null is an acceptable value to the container then this method will be ambiguous and find() should be used instead.

Specified by:
get in interface Mapped<K,JImmutableList<V>>
Parameters:
key - identifies the value to retrieve
Returns:
value associated with key or null if no value is associated

getValueOr

public JImmutableList<V> getValueOr(K key,
                                    JImmutableList<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.

Specified by:
getValueOr in interface Mapped<K,JImmutableList<V>>
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

find

@Nonnull
public Holder<JImmutableList<V>> find(K key)
Description copied from interface: Mapped
Return a Holder containing the value associated wth the key or an empty Holder if no value is associated with the key.

Specified by:
find in interface Mapped<K,JImmutableList<V>>
Parameters:
key - identifies the value to retrieve
Returns:
possibly empty Holder containing any value associated with the key

deleteAll

@Nonnull
public JImmutableListMap<K,V> deleteAll()
Specified by:
deleteAll in interface JImmutableListMap<K,V>
Returns:
an equivalent collection with no values

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

create

protected abstract JImmutableListMap<K,V> create(JImmutableMap<K,JImmutableList<V>> map)
Implemented by derived classes to create a new instance of the appropriate class.

Parameters:
map -
Returns:

copyList

protected JImmutableList<V> copyList(JImmutableList<V> original)
Overridable by derived classes to create a compatible copy of the specified list. Default implementation simply returns the original.

Returns:

emptyList

@Nonnull
protected JImmutableList<V> emptyList()
Overridable by derived classes to create a new empty list

Returns:

insertInList

protected JImmutableList<V> insertInList(JImmutableList<V> list,
                                         V value)
Overridable by derived classes to insert a value into a list in some way. Default implementation appends to end of the list.

Returns:


Copyright © 2014 Burton Computer Corporation. All rights reserved.