    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 */
    017package org.apache.commons.collections4.bag;
    018
    019import java.util.Set;
    020
    021import org.apache.commons.collections4.Bag;
    022import org.apache.commons.collections4.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 * @param <E> the type of elements in this bag
    030 * @since 3.0
    031 */
    032public abstract class AbstractBagDecorator<E>
    033        extends AbstractCollectionDecorator<E> implements Bag<E> {
    034
    035    /** Serialization version */
    036    private static final long serialVersionUID = -3768146017343785417L;
    037
    038    /**
    039     * Constructor only used in deserialization, do not use otherwise.
    040     * @since 3.1
    041     */
    042    protected AbstractBagDecorator() {
    043        super();
    044    }
    045
    046    /**
    047     * Constructor that wraps (not copies).
    048     *
    049     * @param bag  the bag to decorate, must not be null
    050     * @throws NullPointerException if bag is null
    051     */
    052    protected AbstractBagDecorator(final Bag<E> bag) {
    053        super(bag);
    054    }
    055
    056    /**
    057     * Gets the bag being decorated.
    058     *
    059     * @return the decorated bag
    060     */
    061    @Override
    062    protected Bag<E> decorated() {
    063        return (Bag<E>) super.decorated();
    064    }
    065
    066    @Override
    067    public boolean equals(final Object object) {
    068        return object == this || decorated().equals(object);
    069    }
    070
    071    @Override
    072    public int hashCode() {
    073        return decorated().hashCode();
    074    }
    075
    076    //-----------------------------------------------------------------------
    077
    078    @Override
    079    public int getCount(final Object object) {
    080        return decorated().getCount(object);
    081    }
    082
    083    @Override
    084    public boolean add(final E object, final int count) {
    085        return decorated().add(object, count);
    086    }
    087
    088    @Override
    089    public boolean remove(final Object object, final int count) {
    090        return decorated().remove(object, count);
    091    }
    092
    093    @Override
    094    public Set<E> uniqueSet() {
    095        return decorated().uniqueSet();
    096    }
    097
    098}