001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.collections.bag;
018
019 import java.util.Set;
020
021 import org.apache.commons.collections.Bag;
022 import org.apache.commons.collections.collection.AbstractCollectionDecorator;
023
024 /**
025 * Decorates another <code>Bag</code> to provide additional behaviour.
026 * <p>
027 * Methods are forwarded directly to the decorated bag.
028 *
029 * @since Commons Collections 3.0
030 * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
031 *
032 * @author Stephen Colebourne
033 */
034 public abstract class AbstractBagDecorator
035 extends AbstractCollectionDecorator implements Bag {
036
037 /**
038 * Constructor only used in deserialization, do not use otherwise.
039 * @since Commons Collections 3.1
040 */
041 protected AbstractBagDecorator() {
042 super();
043 }
044
045 /**
046 * Constructor that wraps (not copies).
047 *
048 * @param bag the bag to decorate, must not be null
049 * @throws IllegalArgumentException if list is null
050 */
051 protected AbstractBagDecorator(Bag bag) {
052 super(bag);
053 }
054
055 /**
056 * Gets the bag being decorated.
057 *
058 * @return the decorated bag
059 */
060 protected Bag getBag() {
061 return (Bag) getCollection();
062 }
063
064 //-----------------------------------------------------------------------
065 public int getCount(Object object) {
066 return getBag().getCount(object);
067 }
068
069 public boolean add(Object object, int count) {
070 return getBag().add(object, count);
071 }
072
073 public boolean remove(Object object, int count) {
074 return getBag().remove(object, count);
075 }
076
077 public Set uniqueSet() {
078 return getBag().uniqueSet();
079 }
080
081 }