org.apache.commons.collections
Interface OrderedMap<K,V>

All Superinterfaces:
IterableMap<K,V>, Map<K,V>
All Known Subinterfaces:
OrderedBidiMap<K,V>, SortedBidiMap<K,V>
All Known Implementing Classes:
AbstractLinkedMap, AbstractOrderedBidiMapDecorator, AbstractOrderedMapDecorator, AbstractSortedBidiMapDecorator, DualTreeBidiMap, LinkedMap, ListOrderedMap, LRUMap, SingletonMap, TreeBidiMap, UnmodifiableOrderedBidiMap, UnmodifiableOrderedMap, UnmodifiableSortedBidiMap

public interface OrderedMap<K,V>
extends IterableMap<K,V>

Defines a map that maintains order and allows both forward and backward iteration through that order.

Since:
Commons Collections 3.0
Version:
$Revision: 1.1.1.1 $ $Date: 2005/05/23 04:33:16 $
Author:
Matt Hall, John Watkinson, Stephen Colebourne

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 K firstKey()
          Gets the first key currently in this map.
 K lastKey()
          Gets the last key currently in this map.
 K nextKey(K key)
          Gets the next key after the one specified.
 OrderedMapIterator<K,V> orderedMapIterator()
          Obtains an OrderedMapIterator over the map.
 K previousKey(K key)
          Gets the previous key before the one specified.
 
Methods inherited from interface org.apache.commons.collections.IterableMap
mapIterator
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Method Detail

orderedMapIterator

OrderedMapIterator<K,V> orderedMapIterator()
Obtains an OrderedMapIterator over the map.

A ordered map iterator is an efficient way of iterating over maps in both directions.

 BidiMap map = new TreeBidiMap();
 MapIterator it = map.mapIterator();
 while (it.hasNext()) {
   Object key = it.next();
   Object value = it.getValue();
   it.setValue("newValue");
   Object previousKey = it.previous();
 }
 

Returns:
a map iterator

firstKey

K firstKey()
Gets the first key currently in this map.

Returns:
the first key currently in this map
Throws:
NoSuchElementException - if this map is empty

lastKey

K lastKey()
Gets the last key currently in this map.

Returns:
the last key currently in this map
Throws:
NoSuchElementException - if this map is empty

nextKey

K nextKey(K key)
Gets the next key after the one specified.

Parameters:
key - the key to search for next from
Returns:
the next key, null if no match or at end

previousKey

K previousKey(K key)
Gets the previous key before the one specified.

Parameters:
key - the key to search for previous from
Returns:
the previous key, null if no match or at start


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.