1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.collections;
  17. /**
  18. * Defines a map that maintains order and allows both forward and backward
  19. * iteration through that order.
  20. *
  21. * @since Commons Collections 3.0
  22. * @version $Revision: 1.6 $ $Date: 2004/02/18 01:15:42 $
  23. *
  24. * @author Stephen Colebourne
  25. */
  26. public interface OrderedMap extends IterableMap {
  27. /**
  28. * Obtains an <code>OrderedMapIterator</code> over the map.
  29. * <p>
  30. * A ordered map iterator is an efficient way of iterating over maps
  31. * in both directions.
  32. * <pre>
  33. * BidiMap map = new TreeBidiMap();
  34. * MapIterator it = map.mapIterator();
  35. * while (it.hasNext()) {
  36. * Object key = it.next();
  37. * Object value = it.getValue();
  38. * it.setValue("newValue");
  39. * Object previousKey = it.previous();
  40. * }
  41. * </pre>
  42. *
  43. * @return a map iterator
  44. */
  45. OrderedMapIterator orderedMapIterator();
  46. /**
  47. * Gets the first key currently in this map.
  48. *
  49. * @return the first key currently in this map
  50. * @throws java.util.NoSuchElementException if this map is empty
  51. */
  52. public Object firstKey();
  53. /**
  54. * Gets the last key currently in this map.
  55. *
  56. * @return the last key currently in this map
  57. * @throws java.util.NoSuchElementException if this map is empty
  58. */
  59. public Object lastKey();
  60. /**
  61. * Gets the next key after the one specified.
  62. *
  63. * @param key the key to search for next from
  64. * @return the next key, null if no match or at end
  65. */
  66. public Object nextKey(Object key);
  67. /**
  68. * Gets the previous key before the one specified.
  69. *
  70. * @param key the key to search for previous from
  71. * @return the previous key, null if no match or at start
  72. */
  73. public Object previousKey(Object key);
  74. }