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>MultSet</code> to provide additional behaviour.
026 * <p>
027 * Methods are forwarded directly to the decorated multiset.
028 *
029 * @param <E> the type held in the multiset
030 * @since 4.1
031 */
032public abstract class AbstractMultiSetDecorator<E>
033        extends AbstractCollectionDecorator<E> implements MultiSet<E> {
034
035    /** Serialization version */
036    private static final long serialVersionUID = 20150610L;
037
038    /**
039     * Constructor only used in deserialization, do not use otherwise.
040     */
041    protected AbstractMultiSetDecorator() {
042        super();
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    /**
056     * Gets the multiset being decorated.
057     *
058     * @return the decorated multiset
059     */
060    @Override
061    protected MultiSet<E> decorated() {
062        return (MultiSet<E>) super.decorated();
063    }
064
065    @Override
066    public boolean equals(final Object object) {
067        return object == this || decorated().equals(object);
068    }
069
070    @Override
071    public int hashCode() {
072        return decorated().hashCode();
073    }
074
075    //-----------------------------------------------------------------------
076
077    @Override
078    public int getCount(final Object object) {
079        return decorated().getCount(object);
080    }
081
082    @Override
083    public int setCount(final E object, final int count) {
084        return decorated().setCount(object, count);
085    }
086
087    @Override
088    public int add(final E object, final int count) {
089        return decorated().add(object, count);
090    }
091
092    @Override
093    public int remove(final Object object, final int count) {
094        return decorated().remove(object, count);
095    }
096
097    @Override
098    public Set<E> uniqueSet() {
099        return decorated().uniqueSet();
100    }
101
102    @Override
103    public Set<Entry<E>> entrySet() {
104        return decorated().entrySet();
105    }
106
107}