View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.collections4.bag;
18  
19  import java.util.Set;
20  
21  import org.apache.commons.collections4.Bag;
22  import org.apache.commons.collections4.collection.AbstractCollectionDecorator;
23  import org.apache.commons.collections4.multiset.AbstractMultiSetDecorator;
24  
25  /**
26   * Decorates another {@code Bag} to provide additional behavior.
27   * <p>
28   * Methods are forwarded directly to the decorated bag.
29   * </p>
30   *
31   * @param <E> The type of elements in this bag
32   * @since 3.0
33   * @deprecated Since 4.6.0, use {@link AbstractMultiSetDecorator} instead.
34   */
35  @Deprecated
36  public abstract class AbstractBagDecorator<E>
37          extends AbstractCollectionDecorator<E> implements Bag<E> {
38  
39      /** Serialization version */
40      private static final long serialVersionUID = -3768146017343785417L;
41  
42      /**
43       * Constructor only used in deserialization, do not use otherwise.
44       *
45       * @since 3.1
46       */
47      protected AbstractBagDecorator() {
48      }
49  
50      /**
51       * Constructor that wraps (not copies).
52       *
53       * @param bag  The bag to decorate, must not be null
54       * @throws NullPointerException if bag is null
55       */
56      protected AbstractBagDecorator(final Bag<E> bag) {
57          super(bag);
58      }
59  
60      @Override
61      public boolean add(final E object, final int count) {
62          return decorated().add(object, count);
63      }
64  
65      /**
66       * Gets the bag being decorated.
67       *
68       * @return The decorated bag
69       */
70      @Override
71      protected Bag<E> decorated() {
72          return (Bag<E>) super.decorated();
73      }
74  
75      @Override
76      public boolean equals(final Object object) {
77          return object == this || decorated().equals(object);
78      }
79  
80      @Override
81      public int getCount(final Object object) {
82          return decorated().getCount(object);
83      }
84  
85      @Override
86      public int hashCode() {
87          return decorated().hashCode();
88      }
89  
90      @Override
91      public boolean remove(final Object object, final int count) {
92          return decorated().remove(object, count);
93      }
94  
95      @Override
96      public Set<E> uniqueSet() {
97          return decorated().uniqueSet();
98      }
99  
100 }