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.multiset;
018
019import java.util.Set;
020
021import org.apache.commons.collections4.MultiSet;
022import org.apache.commons.collections4.collection.AbstractCollectionDecorator;
023
024/**
025 * Decorates another {@code MultiSet} to provide additional behavior.
026 * <p>
027 * Methods are forwarded directly to the decorated multiset.
028 * </p>
029 *
030 * @param <E> the type held in the multiset
031 * @since 4.1
032 */
033public abstract class AbstractMultiSetDecorator<E>
034        extends AbstractCollectionDecorator<E> implements MultiSet<E> {
035
036    /** Serialization version */
037    private static final long serialVersionUID = 20150610L;
038
039    /**
040     * Constructor only used in deserialization, do not use otherwise.
041     */
042    protected AbstractMultiSetDecorator() {
043    }
044
045    /**
046     * Constructor that wraps (not copies).
047     *
048     * @param multiset  the multiset to decorate, must not be null
049     * @throws NullPointerException if multiset is null
050     */
051    protected AbstractMultiSetDecorator(final MultiSet<E> multiset) {
052        super(multiset);
053    }
054
055    @Override
056    public int add(final E object, final int count) {
057        return decorated().add(object, count);
058    }
059
060    /**
061     * Gets the multiset being decorated.
062     *
063     * @return the decorated multiset
064     */
065    @Override
066    protected MultiSet<E> decorated() {
067        return (MultiSet<E>) super.decorated();
068    }
069
070    @Override
071    public Set<Entry<E>> entrySet() {
072        return decorated().entrySet();
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 int remove(final Object object, final int count) {
092        return decorated().remove(object, count);
093    }
094
095    @Override
096    public int setCount(final E object, final int count) {
097        return decorated().setCount(object, count);
098    }
099
100    @Override
101    public Set<E> uniqueSet() {
102        return decorated().uniqueSet();
103    }
104
105}