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