org.apache.commons.collections.bidimap

Class DualTreeBidiMap

Implemented Interfaces:
BidiMap, IterableMap, Map, OrderedBidiMap, OrderedMap, Serializable, SortedBidiMap, SortedMap

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.

Version:
$Id: DualTreeBidiMap.java,v 1.14 2004/06/11 23:27:37 scolebourne Exp $

Authors:
Matthew Hawthorne
Stephen Colebourne

Since:
Commons Collections 3.0

Nested Class Summary

protected static class
DualTreeBidiMap.BidiOrderedMapIterator
Inner class MapIterator.
protected static class
DualTreeBidiMap.ViewMap
Internal sorted map view.

Nested classes/interfaces inherited from class org.apache.commons.collections.bidimap.AbstractDualBidiMap

AbstractDualBidiMap.BidiMapIterator, AbstractDualBidiMap.EntrySet, AbstractDualBidiMap.EntrySetIterator, AbstractDualBidiMap.KeySet, AbstractDualBidiMap.KeySetIterator, AbstractDualBidiMap.MapEntry, AbstractDualBidiMap.Values, AbstractDualBidiMap.ValuesIterator, AbstractDualBidiMap.View

Field Summary

protected Comparator
comparator
The comparator to use

Fields inherited from class org.apache.commons.collections.bidimap.AbstractDualBidiMap

entrySet, inverseBidiMap, keySet, maps, values

Constructor Summary

DualTreeBidiMap()
Creates an empty DualTreeBidiMap
DualTreeBidiMap(Comparator comparator)
Constructs a DualTreeBidiMap using the specified Comparator.
DualTreeBidiMap(Map map)
Constructs a DualTreeBidiMap and copies the mappings from specified Map.
DualTreeBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap)
Constructs a DualTreeBidiMap that decorates the specified maps.

Method Summary

Comparator
comparator()
protected BidiMap
createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap)
Creates a new instance of this object.
Object
firstKey()
SortedMap
headMap(Object toKey)
OrderedBidiMap
inverseOrderedBidiMap()
SortedBidiMap
inverseSortedBidiMap()
Object
lastKey()
Object
nextKey(Object key)
OrderedMapIterator
orderedMapIterator()
Obtains an ordered map iterator.
Object
previousKey(Object key)
SortedMap
subMap(Object fromKey, Object toKey)
SortedMap
tailMap(Object fromKey)

Methods inherited from class org.apache.commons.collections.bidimap.AbstractDualBidiMap

clear, containsKey, containsValue, createBidiMap, createEntrySetIterator, createKeySetIterator, createMap, createValuesIterator, entrySet, equals, get, getKey, hashCode, inverseBidiMap, isEmpty, keySet, mapIterator, put, putAll, remove, removeValue, size, toString, values

Field Details

comparator

protected final Comparator comparator
The comparator to use

Constructor Details

DualTreeBidiMap

public DualTreeBidiMap()
Creates an empty DualTreeBidiMap


DualTreeBidiMap

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

Parameters:
comparator - the Comparator


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

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 Details

comparator

public Comparator comparator()


createBidiMap

protected BidiMap createBidiMap(Map normalMap,
                                Map reverseMap,
                                BidiMap inverseMap)
Creates a new instance of this object.
Overrides:
createBidiMap in interface AbstractDualBidiMap

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

Returns:
new bidi map


firstKey

public Object firstKey()
Specified by:
firstKey in interface OrderedMap


headMap

public SortedMap headMap(Object toKey)


inverseOrderedBidiMap

public OrderedBidiMap inverseOrderedBidiMap()
Specified by:
inverseOrderedBidiMap in interface OrderedBidiMap


inverseSortedBidiMap

public SortedBidiMap inverseSortedBidiMap()
Specified by:
inverseSortedBidiMap in interface SortedBidiMap


lastKey

public Object lastKey()
Specified by:
lastKey in interface OrderedMap


nextKey

public Object nextKey(Object key)
Specified by:
nextKey in interface OrderedMap


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.

Specified by:
orderedMapIterator in interface OrderedMap

Returns:
a new ordered map iterator


previousKey

public Object previousKey(Object key)
Specified by:
previousKey in interface OrderedMap


subMap

public SortedMap subMap(Object fromKey,
                        Object toKey)


tailMap

public SortedMap tailMap(Object fromKey)


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