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