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 * http://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.multiset;
18
19 import java.util.Set;
20
21 import org.apache.commons.collections4.MultiSet;
22 import org.apache.commons.collections4.collection.AbstractCollectionDecorator;
23
24 /**
25 * Decorates another {@code MultiSet} to provide additional behavior.
26 * <p>
27 * Methods are forwarded directly to the decorated multiset.
28 * </p>
29 *
30 * @param <E> the type held in the multiset
31 * @since 4.1
32 */
33 public abstract class AbstractMultiSetDecorator<E>
34 extends AbstractCollectionDecorator<E> implements MultiSet<E> {
35
36 /** Serialization version */
37 private static final long serialVersionUID = 20150610L;
38
39 /**
40 * Constructor only used in deserialization, do not use otherwise.
41 */
42 protected AbstractMultiSetDecorator() {
43 }
44
45 /**
46 * Constructor that wraps (not copies).
47 *
48 * @param multiset the multiset to decorate, must not be null
49 * @throws NullPointerException if multiset is null
50 */
51 protected AbstractMultiSetDecorator(final MultiSet<E> multiset) {
52 super(multiset);
53 }
54
55 @Override
56 public int add(final E object, final int count) {
57 return decorated().add(object, count);
58 }
59
60 /**
61 * Gets the multiset being decorated.
62 *
63 * @return the decorated multiset
64 */
65 @Override
66 protected MultiSet<E> decorated() {
67 return (MultiSet<E>) super.decorated();
68 }
69
70 @Override
71 public Set<Entry<E>> entrySet() {
72 return decorated().entrySet();
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 int remove(final Object object, final int count) {
92 return decorated().remove(object, count);
93 }
94
95 @Override
96 public int setCount(final E object, final int count) {
97 return decorated().setCount(object, count);
98 }
99
100 @Override
101 public Set<E> uniqueSet() {
102 return decorated().uniqueSet();
103 }
104
105 }