gumbo.util
Class AbstractGroupBimap

java.lang.Object
  |
  +--gumbo.util.AbstractBimap
        |
        +--gumbo.util.AbstractGroupBimap
All Implemented Interfaces:
Bimap, GroupBimap, java.util.Map

public class AbstractGroupBimap
extends AbstractBimap
implements GroupBimap

An abstract implementation of the GroupBimap interface. Intended as a lightweight proxy for a bimap's stores, with lazy build of the stores and this object's immutable views. Because of the need to match value group type, wrapping and external target, as in a Bimap, is not supported. TODO: Group store must be a List for now until Bimap and GroupBimap can be made fully compliant with Map.

Version:
$Revision: 1.3 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
AbstractGroupBimap()
          Constructs an instance, with empty lazy build stores (see newValueStore(), newKeyStore()).
AbstractGroupBimap(java.util.Map init)
          Constructs an instance, with initialized stores.
 
Method Summary
 void addAll(java.util.Collection keys, int index, java.util.Collection values)
          Adds all the values to the groups associated with all the keys.
 void addAll(java.util.Map map)
          Adds all the entries in the map to this one.
 void addAllKeys(java.util.Collection keys, int index, java.lang.Object value)
          Adds a value to the groups associated with all the keys.
 void addAllValues(java.lang.Object key, int index, java.util.Collection values)
          Adds all the values to the group associated with a key.
 void addValue(java.lang.Object key, int index, java.lang.Object value)
          Adds a value to the group associated with a key.
 java.util.Set entrySet()
          Gets an immutable view of the key-value entries (Map.Entry) in this bimap.
 java.lang.Object get(java.lang.Object key)
          If the value group storage is a list, gets the value at the head of the list associated with the key.
 GroupBimap getGroupBimap()
          Gets a singleton immutable view of this group bimap.
 Group getValues(java.lang.Object key)
          Gets an immutable snapshot of the values (Object) associated with a key.
protected  Group newValueGroup()
          Called by this object when it needs to build a new value group (Object) in the key-to-value map.
protected  java.util.Collection newValueGroupStore()
          Called by this object when it needs to lazily build the store for a value group in the key-to-values map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          If the value group storage is a list, adds the value to the head of the list associated with the key.
 void putAll(java.util.Map map)
          If the value group storage is a list, adds a map value to the head of the list associated with a key.
 java.lang.Object remove(java.lang.Object key)
          Removes the values associated with a key.
 void removeAll(java.util.Collection keys, java.util.Collection values)
          Removes all the values from the groups associated with all the keys.
 void removeAllKeys(java.util.Collection keys)
          Removes all the keys and their associated values.
 void removeAllKeys(java.util.Collection keys, java.lang.Object value)
          Removes a value from the groups associated with all the keys.
 void removeAllValues(java.util.Collection values)
          Removes all the values and their associated keys.
 void removeAllValues(java.lang.Object key, java.util.Collection values)
          Removes all the values from the group associated with a key.
 void removeKey(java.lang.Object key)
          Removes the key and its associated value.
 void removeValue(java.lang.Object value)
          Removes the value and its associated keys.
 void removeValue(java.lang.Object key, java.lang.Object value)
          Removes a value from the group associated with a key.
 java.util.Collection values()
          If the value group storage is a list, gets the values at the head of the lists associated with the keys.
 
Methods inherited from class gumbo.util.AbstractBimap
clear, containsKey, containsValue, equals, getBimap, getKeyMapStore, getKeys, getValueMapStore, hashCode, isEmpty, keySet, newKeyGroup, newKeyGroupStore, newKeyMapStore, newValueMapStore, size, toString, valueSet
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gumbo.util.Bimap
getBimap, getKeys, keySet, valueSet
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, hashCode, isEmpty, size
 

Constructor Detail

AbstractGroupBimap

public AbstractGroupBimap()
Constructs an instance, with empty lazy build stores (see newValueStore(), newKeyStore()).


AbstractGroupBimap

public AbstractGroupBimap(java.util.Map init)
Constructs an instance, with initialized stores. Master constructor.

Parameters:
init - The initial map (Object to Object) or group bimap (Object to Group of Object). See addAll(Map). None if null.
Method Detail

newValueGroupStore

protected java.util.Collection newValueGroupStore()
Called by this object when it needs to lazily build the store for a value group in the key-to-values map. Defaults to a SetList. Override as needed with a different collection type.

Returns:
A new empty store. Never null.

newValueGroup

protected final Group newValueGroup()
Called by this object when it needs to build a new value group (Object) in the key-to-value map. Calls newValueGroupStore() to lazy build the group backing store. Master mutator.

Returns:
A new empty group. Never null.
Throws:
java.lang.IllegalStateException - New value group store is null.

addAll

public void addAll(java.util.Collection keys,
                   int index,
                   java.util.Collection values)
Description copied from interface: GroupBimap
Adds all the values to the groups associated with all the keys.

Specified by:
addAll in interface GroupBimap

addAll

public void addAll(java.util.Map map)
Description copied from interface: GroupBimap
Adds all the entries in the map to this one. If the map is a GroupBimap, its group values will be added.

Specified by:
addAll in interface GroupBimap

addAllKeys

public void addAllKeys(java.util.Collection keys,
                       int index,
                       java.lang.Object value)
Description copied from interface: GroupBimap
Adds a value to the groups associated with all the keys.

Specified by:
addAllKeys in interface GroupBimap

addAllValues

public void addAllValues(java.lang.Object key,
                         int index,
                         java.util.Collection values)
Description copied from interface: GroupBimap
Adds all the values to the group associated with a key.

Specified by:
addAllValues in interface GroupBimap

addValue

public void addValue(java.lang.Object key,
                     int index,
                     java.lang.Object value)
Description copied from interface: GroupBimap
Adds a value to the group associated with a key. Some stores (such as SetList) may throw an exception when attempting to add a duplicate member.

Specified by:
addValue in interface GroupBimap
Parameters:
key - Value group key. Never null.
index - List index. If not backed by a list, < 0. If backed by a list, <= group size, with < 0 being the end of the list.
value - Value to be added. Ignored if null.

getValues

public Group getValues(java.lang.Object key)
Description copied from interface: GroupBimap
Gets an immutable snapshot of the values (Object) associated with a key. Similar to get(Object).

Specified by:
getValues in interface GroupBimap

removeAll

public void removeAll(java.util.Collection keys,
                      java.util.Collection values)
Description copied from interface: GroupBimap
Removes all the values from the groups associated with all the keys.

Specified by:
removeAll in interface GroupBimap

removeAllKeys

public void removeAllKeys(java.util.Collection keys,
                          java.lang.Object value)
Description copied from interface: GroupBimap
Removes a value from the groups associated with all the keys.

Specified by:
removeAllKeys in interface GroupBimap

removeAllValues

public void removeAllValues(java.lang.Object key,
                            java.util.Collection values)
Description copied from interface: GroupBimap
Removes all the values from the group associated with a key.

Specified by:
removeAllValues in interface GroupBimap

removeValue

public void removeValue(java.lang.Object key,
                        java.lang.Object value)
Description copied from interface: GroupBimap
Removes a value from the group associated with a key. If the group is not backed by a set, only the first instance is removed (see List.remove()).

Specified by:
removeValue in interface GroupBimap
Parameters:
key - Value group key. Never null.
value - Value to be removed. Ignored if null or missing.

getGroupBimap

public GroupBimap getGroupBimap()
Description copied from interface: GroupBimap
Gets a singleton immutable view of this group bimap. To avoid unnecessary lazy builds, if possible, use other accessors instead of this view.

Specified by:
getGroupBimap in interface GroupBimap
Returns:
The view. Never null.

removeAllKeys

public void removeAllKeys(java.util.Collection keys)
Description copied from interface: Bimap
Removes all the keys and their associated values.

Specified by:
removeAllKeys in interface Bimap
Overrides:
removeAllKeys in class AbstractBimap

removeAllValues

public void removeAllValues(java.util.Collection values)
Description copied from interface: Bimap
Removes all the values and their associated keys.

Specified by:
removeAllValues in interface Bimap
Overrides:
removeAllValues in class AbstractBimap

removeKey

public void removeKey(java.lang.Object key)
Description copied from interface: Bimap
Removes the key and its associated value. Similar in function to remove(Object).

Specified by:
removeKey in interface Bimap
Overrides:
removeKey in class AbstractBimap

removeValue

public void removeValue(java.lang.Object value)
Description copied from interface: Bimap
Removes the value and its associated keys.

Specified by:
removeValue in interface Bimap
Overrides:
removeValue in class AbstractBimap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from interface: GroupBimap
If the value group storage is a list, adds the value to the head of the list associated with the key. A list is required so that put() and get() work as expected. TODO: Refactor to allow list or set store.

Specified by:
put in interface GroupBimap
Overrides:
put in class AbstractBimap
Returns:
The value previously returned by get(key). Null if none.

putAll

public void putAll(java.util.Map map)
Description copied from interface: GroupBimap
If the value group storage is a list, adds a map value to the head of the list associated with a key. A list is required so that put() and get() work as expected.

Specified by:
putAll in interface GroupBimap
Overrides:
putAll in class AbstractBimap

get

public java.lang.Object get(java.lang.Object key)
Description copied from interface: GroupBimap
If the value group storage is a list, gets the value at the head of the list associated with the key. A list is required so that put() and get() work as expected. TODO: Refactor to allow list or set store.

Specified by:
get in interface GroupBimap
Overrides:
get in class AbstractBimap
Returns:
The value. Null if none.

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from interface: GroupBimap
Removes the values associated with a key. If the value group storage is a list, returns the value at the head of the list associated with the key; otherwise, returns the discarded value group.

Specified by:
remove in interface GroupBimap
Overrides:
remove in class AbstractBimap
Returns:
The value. Null if none.

values

public java.util.Collection values()
Description copied from interface: GroupBimap
If the value group storage is a list, gets the values at the head of the lists associated with the keys. A list is required so that put() and get() work as expected. TODO: Refactor to allow list or set store.

Specified by:
values in interface GroupBimap
Overrides:
values in class AbstractBimap
Returns:
An immutable snapshot in key iterator order. Never null.

entrySet

public java.util.Set entrySet()
Description copied from interface: Bimap
Gets an immutable view of the key-value entries (Map.Entry) in this bimap.

Specified by:
entrySet in interface GroupBimap
Overrides:
entrySet in class AbstractBimap