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.bidimap;
  17. import java.util.Comparator;
  18. import java.util.SortedMap;
  19. import org.apache.commons.collections.SortedBidiMap;
  20. /**
  21. * Provides a base decorator that enables additional functionality to be added
  22. * to a SortedBidiMap 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 inverse 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.4 $ $Date: 2004/02/18 00:57:39 $
  34. *
  35. * @author Stephen Colebourne
  36. */
  37. public abstract class AbstractSortedBidiMapDecorator
  38. extends AbstractOrderedBidiMapDecorator implements SortedBidiMap {
  39. /**
  40. * Constructor that wraps (not copies).
  41. *
  42. * @param map the map to decorate, must not be null
  43. * @throws IllegalArgumentException if the collection is null
  44. */
  45. public AbstractSortedBidiMapDecorator(SortedBidiMap map) {
  46. super(map);
  47. }
  48. /**
  49. * Gets the map being decorated.
  50. *
  51. * @return the decorated map
  52. */
  53. protected SortedBidiMap getSortedBidiMap() {
  54. return (SortedBidiMap) map;
  55. }
  56. //-----------------------------------------------------------------------
  57. public SortedBidiMap inverseSortedBidiMap() {
  58. return getSortedBidiMap().inverseSortedBidiMap();
  59. }
  60. public Comparator comparator() {
  61. return getSortedBidiMap().comparator();
  62. }
  63. public SortedMap subMap(Object fromKey, Object toKey) {
  64. return getSortedBidiMap().subMap(fromKey, toKey);
  65. }
  66. public SortedMap headMap(Object toKey) {
  67. return getSortedBidiMap().headMap(toKey);
  68. }
  69. public SortedMap tailMap(Object fromKey) {
  70. return getSortedBidiMap().tailMap(fromKey);
  71. }
  72. }