org.apache.commons.collections.bidimap

Class AbstractDualBidiMap

public abstract class AbstractDualBidiMap extends 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

Version: $Id: AbstractDualBidiMap.java 155406 2005-02-26 12:55:26Z dirkv $

Author: Matthew Hawthorne Stephen Colebourne

See Also: DualHashBidiMap DualTreeBidiMap

Nested Class Summary
protected static classAbstractDualBidiMap.BidiMapIterator
Inner class MapIterator.
protected static classAbstractDualBidiMap.EntrySet
Inner class EntrySet.
protected static classAbstractDualBidiMap.EntrySetIterator
Inner class EntrySetIterator.
protected static classAbstractDualBidiMap.KeySet
Inner class KeySet.
protected static classAbstractDualBidiMap.KeySetIterator
Inner class KeySetIterator.
protected static classAbstractDualBidiMap.MapEntry
Inner class MapEntry.
protected static classAbstractDualBidiMap.Values
Inner class Values.
protected static classAbstractDualBidiMap.ValuesIterator
Inner class ValuesIterator.
protected abstract static classAbstractDualBidiMap.View
Inner class View.
Field Summary
protected SetentrySet
View of the entries.
protected BidiMapinverseBidiMap
Inverse view of this map.
protected SetkeySet
View of the keys.
protected Map[]maps
Delegate map array.
protected Collectionvalues
View of the values.
Constructor Summary
protected AbstractDualBidiMap()
Creates an empty map, initialised by createMap.
protected AbstractDualBidiMap(Map normalMap, Map reverseMap)
Creates an empty map using the two maps specified as storage.
protected AbstractDualBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap)
Constructs a map that decorates the specified maps, used by the subclass createBidiMap implementation.
Method Summary
voidclear()
booleancontainsKey(Object key)
booleancontainsValue(Object value)
protected abstract BidiMapcreateBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap)
Creates a new instance of the subclass.
protected IteratorcreateEntrySetIterator(Iterator iterator)
Creates an entry set iterator.
protected IteratorcreateKeySetIterator(Iterator iterator)
Creates a key set iterator.
protected MapcreateMap()
Creates a new instance of the map used by the subclass to store data.
protected IteratorcreateValuesIterator(Iterator iterator)
Creates a values iterator.
SetentrySet()
Gets an entrySet view of the map.
booleanequals(Object obj)
Objectget(Object key)
ObjectgetKey(Object value)
inthashCode()
BidiMapinverseBidiMap()
booleanisEmpty()
SetkeySet()
Gets a keySet view of the map.
MapIteratormapIterator()
Obtains a MapIterator over the map.
Objectput(Object key, Object value)
voidputAll(Map map)
Objectremove(Object key)
ObjectremoveValue(Object value)
intsize()
StringtoString()
Collectionvalues()
Gets a values view of the map.

Field Detail

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 Detail

AbstractDualBidiMap

protected AbstractDualBidiMap()
Creates an empty map, initialised by createMap.

This constructor remains in place for deserialization. All other usage is deprecated in favour of AbstractDualBidiMap.

AbstractDualBidiMap

protected AbstractDualBidiMap(Map normalMap, Map reverseMap)
Creates an empty map using the two maps specified as storage.

The two maps must be a matching pair, normal and reverse. They will typically both be empty.

Neither map is validated, so nulls may be passed in. If you choose to do this then the subclass constructor must populate the maps[] instance variable itself.

Parameters: normalMap the normal direction map reverseMap the reverse direction map

Since: Commons Collections 3.1

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 Detail

clear

public void clear()

containsKey

public boolean containsKey(Object key)

containsValue

public boolean containsValue(Object value)

createBidiMap

protected abstract 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()

Deprecated: For constructors, use the new two map constructor. For deserialization, populate the maps array directly in readObject.

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

This design is deeply flawed and has been deprecated. It relied on subclass data being used during a superclass constructor.

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)

get

public Object get(Object key)

getKey

public Object getKey(Object 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)

putAll

public void putAll(Map map)

remove

public Object remove(Object key)

removeValue

public Object removeValue(Object 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

Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.