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.set;
  17. import java.util.Comparator;
  18. import java.util.Set;
  19. import java.util.SortedSet;
  20. /**
  21. * Decorates another <code>SortedSet</code> to provide additional behaviour.
  22. * <p>
  23. * Methods are forwarded directly to the decorated set.
  24. *
  25. * @since Commons Collections 3.0
  26. * @version $Revision: 1.4 $ $Date: 2004/06/02 21:53:03 $
  27. *
  28. * @author Stephen Colebourne
  29. */
  30. public abstract class AbstractSortedSetDecorator extends AbstractSetDecorator implements SortedSet {
  31. /**
  32. * Constructor only used in deserialization, do not use otherwise.
  33. * @since Commons Collections 3.1
  34. */
  35. protected AbstractSortedSetDecorator() {
  36. super();
  37. }
  38. /**
  39. * Constructor that wraps (not copies).
  40. *
  41. * @param set the set to decorate, must not be null
  42. * @throws IllegalArgumentException if set is null
  43. */
  44. protected AbstractSortedSetDecorator(Set set) {
  45. super(set);
  46. }
  47. /**
  48. * Gets the sorted set being decorated.
  49. *
  50. * @return the decorated set
  51. */
  52. protected SortedSet getSortedSet() {
  53. return (SortedSet) getCollection();
  54. }
  55. //-----------------------------------------------------------------------
  56. public SortedSet subSet(Object fromElement, Object toElement) {
  57. return getSortedSet().subSet(fromElement, toElement);
  58. }
  59. public SortedSet headSet(Object toElement) {
  60. return getSortedSet().headSet(toElement);
  61. }
  62. public SortedSet tailSet(Object fromElement) {
  63. return getSortedSet().tailSet(fromElement);
  64. }
  65. public Object first() {
  66. return getSortedSet().first();
  67. }
  68. public Object last() {
  69. return getSortedSet().last();
  70. }
  71. public Comparator comparator() {
  72. return getSortedSet().comparator();
  73. }
  74. }