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