1. /*
  2. * Copyright 2003-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.map;
  17. import org.apache.commons.collections.MapIterator;
  18. import org.apache.commons.collections.OrderedMap;
  19. import org.apache.commons.collections.OrderedMapIterator;
  20. /**
  21. * Provides a base decorator that enables additional functionality to be added
  22. * to an OrderedMap via decoration.
  23. * <p>
  24. * Methods are forwarded directly to the decorated map.
  25. * <p>
  26. * This implementation does not perform any special processing with the map views.
  27. * Instead it simply returns the set/collection from the wrapped map. This may be
  28. * undesirable, for example if you are trying to write a validating implementation
  29. * it would provide a loophole around the validation.
  30. * But, you might want that loophole, so this class is kept simple.
  31. *
  32. * @since Commons Collections 3.0
  33. * @version $Revision: 1.7 $ $Date: 2004/04/02 21:17:48 $
  34. *
  35. * @author Stephen Colebourne
  36. */
  37. public abstract class AbstractOrderedMapDecorator
  38. extends AbstractMapDecorator implements OrderedMap {
  39. /**
  40. * Constructor only used in deserialization, do not use otherwise.
  41. * @since Commons Collections 3.1
  42. */
  43. protected AbstractOrderedMapDecorator() {
  44. super();
  45. }
  46. /**
  47. * Constructor that wraps (not copies).
  48. *
  49. * @param map the map to decorate, must not be null
  50. * @throws IllegalArgumentException if the collection is null
  51. */
  52. public AbstractOrderedMapDecorator(OrderedMap map) {
  53. super(map);
  54. }
  55. /**
  56. * Gets the map being decorated.
  57. *
  58. * @return the decorated map
  59. */
  60. protected OrderedMap getOrderedMap() {
  61. return (OrderedMap) map;
  62. }
  63. //-----------------------------------------------------------------------
  64. public Object firstKey() {
  65. return getOrderedMap().firstKey();
  66. }
  67. public Object lastKey() {
  68. return getOrderedMap().lastKey();
  69. }
  70. public Object nextKey(Object key) {
  71. return getOrderedMap().nextKey(key);
  72. }
  73. public Object previousKey(Object key) {
  74. return getOrderedMap().previousKey(key);
  75. }
  76. public MapIterator mapIterator() {
  77. return getOrderedMap().mapIterator();
  78. }
  79. public OrderedMapIterator orderedMapIterator() {
  80. return getOrderedMap().orderedMapIterator();
  81. }
  82. }