01: /*
02: * Copyright 2003-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
18: import java.util.Set;
19:
20: import org.apache.commons.collections.Bag;
21: import org.apache.commons.collections.collection.AbstractCollectionDecorator;
22:
23: /**
24: * Decorates another <code>Bag</code> to provide additional behaviour.
25: * <p>
26: * Methods are forwarded directly to the decorated bag.
27: *
28: * @since Commons Collections 3.0
29: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
30: *
31: * @author Stephen Colebourne
32: */
33: public abstract class AbstractBagDecorator extends
34: AbstractCollectionDecorator implements Bag {
35:
36: /**
37: * Constructor only used in deserialization, do not use otherwise.
38: * @since Commons Collections 3.1
39: */
40: protected AbstractBagDecorator() {
41: super ();
42: }
43:
44: /**
45: * Constructor that wraps (not copies).
46: *
47: * @param bag the bag to decorate, must not be null
48: * @throws IllegalArgumentException if list is null
49: */
50: protected AbstractBagDecorator(Bag bag) {
51: super (bag);
52: }
53:
54: /**
55: * Gets the bag being decorated.
56: *
57: * @return the decorated bag
58: */
59: protected Bag getBag() {
60: return (Bag) getCollection();
61: }
62:
63: //-----------------------------------------------------------------------
64: public int getCount(Object object) {
65: return getBag().getCount(object);
66: }
67:
68: public boolean add(Object object, int count) {
69: return getBag().add(object, count);
70: }
71:
72: public boolean remove(Object object, int count) {
73: return getBag().remove(object, count);
74: }
75:
76: public Set uniqueSet() {
77: return getBag().uniqueSet();
78: }
79:
80: }
|