org.apache.commons.collections.bidimap

Class DualTreeBidiMap

public class DualTreeBidiMap extends AbstractDualBidiMap implements SortedBidiMap, Serializable

Implementation of BidiMap that uses two TreeMap instances.

The setValue() method on iterators will succeed only if the new value being set is not already in the bidimap.

When considering whether to use this class, the TreeBidiMap class should also be considered. It implements the interface using a dedicated design, and does not store each object twice, which can save on memory use.

NOTE: From Commons Collections 3.1, all subclasses will use TreeMap and the flawed createMap method is ignored.

Since: Commons Collections 3.0

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

Author: Matthew Hawthorne Stephen Colebourne

Nested Class Summary
protected static classDualTreeBidiMap.BidiOrderedMapIterator
Inner class MapIterator.
protected static classDualTreeBidiMap.ViewMap
Internal sorted map view.
Field Summary
protected Comparatorcomparator
The comparator to use
Constructor Summary
DualTreeBidiMap()
Creates an empty DualTreeBidiMap
DualTreeBidiMap(Map map)
Constructs a DualTreeBidiMap and copies the mappings from specified Map.
DualTreeBidiMap(Comparator comparator)
Constructs a DualTreeBidiMap using the specified Comparator.
protected DualTreeBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap)
Constructs a DualTreeBidiMap that decorates the specified maps.
Method Summary
Comparatorcomparator()
protected BidiMapcreateBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap)
Creates a new instance of this object.
ObjectfirstKey()
SortedMapheadMap(Object toKey)
OrderedBidiMapinverseOrderedBidiMap()
SortedBidiMapinverseSortedBidiMap()
ObjectlastKey()
ObjectnextKey(Object key)
OrderedMapIteratororderedMapIterator()
Obtains an ordered map iterator.
ObjectpreviousKey(Object key)
SortedMapsubMap(Object fromKey, Object toKey)
SortedMaptailMap(Object fromKey)

Field Detail

comparator

protected final Comparator comparator
The comparator to use

Constructor Detail

DualTreeBidiMap

public DualTreeBidiMap()
Creates an empty DualTreeBidiMap

DualTreeBidiMap

public DualTreeBidiMap(Map map)
Constructs a DualTreeBidiMap and copies the mappings from specified Map.

Parameters: map the map whose mappings are to be placed in this map

DualTreeBidiMap

public DualTreeBidiMap(Comparator comparator)
Constructs a DualTreeBidiMap using the specified Comparator.

Parameters: comparator the Comparator

DualTreeBidiMap

protected DualTreeBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap)
Constructs a DualTreeBidiMap that decorates the specified maps.

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

Method Detail

comparator

public Comparator comparator()

createBidiMap

protected BidiMap createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap)
Creates a new instance of this object.

Parameters: normalMap the normal direction map reverseMap the reverse direction map inverseMap the inverse BidiMap

Returns: new bidi map

firstKey

public Object firstKey()

headMap

public SortedMap headMap(Object toKey)

inverseOrderedBidiMap

public OrderedBidiMap inverseOrderedBidiMap()

inverseSortedBidiMap

public SortedBidiMap inverseSortedBidiMap()

lastKey

public Object lastKey()

nextKey

public Object nextKey(Object key)

orderedMapIterator

public OrderedMapIterator orderedMapIterator()
Obtains an ordered map iterator.

This implementation copies the elements to an ArrayList in order to provide the forward/backward behaviour.

Returns: a new ordered map iterator

previousKey

public Object previousKey(Object key)

subMap

public SortedMap subMap(Object fromKey, Object toKey)

tailMap

public SortedMap tailMap(Object fromKey)
Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.