⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.bidimap

Class AbstractDualBidiMap

java.lang.Object
|
+--org.apache.commons.collections.bidimap.AbstractDualBidiMap

All Implemented Interfaces:
BidiMap

Known Direct Subclasses:
DualHashBidiMap, DualTreeBidiMap


public abstract class AbstractDualBidiMap
extends java.lang.Object
implements BidiMap

Abstract BidiMap implemented using two maps.

An implementation can be written simply by implementing the createMap method.

Since:
Commons Collections 3.0
Authors:
Matthew Hawthorne
Stephen Colebourne
See Also:
DualHashBidiMap
DualTreeBidiMap

Field Summary

transient Set

entrySet

View of the entries.

transient BidiMap

inverseBidiMap

Inverse view of this map.

transient Set

keySet

View of the keys.

transient Map[]

maps

Delegate map array.

transient Collection

values

View of the values.

Constructor Summary

AbstractDualBidiMap()

Creates an empty map, initialised by createMap.

AbstractDualBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap)

Constructs a map that decorates the specified maps, used by the subclass createBidiMap implementation.

Method Summary

void

clear()

boolean

containsKey(Object key)

boolean

containsValue(Object value)

BidiMap

createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap)

Creates a new instance of the subclass.

Iterator

createEntrySetIterator(Iterator iterator)

Creates an entry set iterator.

Iterator

createKeySetIterator(Iterator iterator)

Creates a key set iterator.

Map

createMap()

Creates a new instance of the map used by the subclass to store data.

Iterator

createValuesIterator(Iterator iterator)

Creates a values iterator.

Set

entrySet()

Gets an entrySet view of the map.

boolean

equals(Object obj)

Object

get(Object key)

Object

getKey(Object value)

int

hashCode()

BidiMap

inverseBidiMap()

boolean

isEmpty()

Set

keySet()

Gets a keySet view of the map.

MapIterator

mapIterator()

Obtains a MapIterator over the map.

Object

put(Object key, Object value)

void

putAll(Map map)

Object

remove(Object key)

Object

removeValue(Object value)

int

size()

String

toString()

Collection

values()

Gets a values view of the map.

Field Details

entrySet

protected transient Set entrySet

View of the entries.


inverseBidiMap

protected transient BidiMap inverseBidiMap

Inverse view of this map.


keySet

protected transient Set keySet

View of the keys.


maps

protected final transient Map[] maps

Delegate map array. The first map contains standard entries, and the second contains inverses.


values

protected transient Collection values

View of the values.

Constructor Details

AbstractDualBidiMap

protected AbstractDualBidiMap()

Creates an empty map, initialised by createMap.

The map array must be populated by the subclass.


AbstractDualBidiMap

protected AbstractDualBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap)

Constructs a map that decorates the specified maps, used by the subclass createBidiMap implementation.

Parameters:
normalMap - the normal direction map
reverseMap - the reverse direction map
inverseBidiMap - the inverse BidiMap

Method Details

clear

public void clear()


containsKey

public boolean containsKey(Object key)

Parameters:
key

containsValue

public boolean containsValue(Object value)

Parameters:
value

createBidiMap

protected BidiMap createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap)

Creates a new instance of the subclass.

Parameters:
normalMap - the normal direction map
reverseMap - the reverse direction map
inverseMap - this map, which is the inverse in the new map
Returns:
the inverse map

createEntrySetIterator

protected Iterator createEntrySetIterator(Iterator iterator)

Creates an entry set iterator. Subclasses can override this to return iterators with different properties.

Parameters:
iterator - the iterator to decorate
Returns:
the entrySet iterator

createKeySetIterator

protected Iterator createKeySetIterator(Iterator iterator)

Creates a key set iterator. Subclasses can override this to return iterators with different properties.

Parameters:
iterator - the iterator to decorate
Returns:
the keySet iterator

createMap

protected Map createMap()

Creates a new instance of the map used by the subclass to store data.

Do not change any instance variables from this method.

Returns:
the map to be used for internal storage

createValuesIterator

protected Iterator createValuesIterator(Iterator iterator)

Creates a values iterator. Subclasses can override this to return iterators with different properties.

Parameters:
iterator - the iterator to decorate
Returns:
the values iterator

entrySet

public Set entrySet()

Gets an entrySet view of the map. Changes made on the set are reflected in the map. The set supports remove and clear but not add.

The Map Entry setValue() method only allow a new value to be set. If the value being set is already in the map, an IllegalArgumentException is thrown (as setValue cannot change the size of the map).

Returns:
the entrySet view

equals

public boolean equals(Object obj)

Parameters:
obj

get

public Object get(Object key)

Parameters:
key

getKey

public Object getKey(Object value)

Parameters:
value

hashCode

public int hashCode()


inverseBidiMap

public BidiMap inverseBidiMap()


isEmpty

public boolean isEmpty()


keySet

public Set keySet()

Gets a keySet view of the map. Changes made on the view are reflected in the map. The set supports remove and clear but not add.

Returns:
the keySet view

mapIterator

public MapIterator mapIterator()

Obtains a MapIterator over the map. The iterator implements ResetableMapIterator. This implementation relies on the entrySet iterator.

The setValue() methods only allow a new value to be set. If the value being set is already in the map, an IllegalArgumentException is thrown (as setValue cannot change the size of the map).

Returns:
a map iterator

put

public Object put(Object key, Object value)

Parameters:
key
value

putAll

public void putAll(Map map)

Parameters:
map

remove

public Object remove(Object key)

Parameters:
key

removeValue

public Object removeValue(Object value)

Parameters:
value

size

public int size()


toString

public String toString()


values

public Collection values()

Gets a values view of the map. Changes made on the view are reflected in the map. The set supports remove and clear but not add.

Returns:
the values view