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