001    /*
002     * Copyright (C) 2007 Google Inc.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package com.google.common.collect;
018    
019    import com.google.common.annotations.GwtCompatible;
020    
021    import java.util.Set;
022    
023    import javax.annotation.Nullable;
024    
025    /**
026     * A multiset which forwards all its method calls to another multiset.
027     * Subclasses should override one or more methods to modify the behavior of the
028     * backing multiset as desired per the <a
029     * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
030     *
031     * @author Kevin Bourrillion
032     * @since 2 (imported from Google Collections Library)
033     */
034    @GwtCompatible
035    public abstract class ForwardingMultiset<E> extends ForwardingCollection<E>
036        implements Multiset<E> {
037    
038      /** Constructor for use by subclasses. */
039      protected ForwardingMultiset() {}
040    
041      @Override protected abstract Multiset<E> delegate();
042    
043      public int count(Object element) {
044        return delegate().count(element);
045      }
046    
047      public int add(E element, int occurrences) {
048        return delegate().add(element, occurrences);
049      }
050    
051      public int remove(Object element, int occurrences) {
052        return delegate().remove(element, occurrences);
053      }
054    
055      public Set<E> elementSet() {
056        return delegate().elementSet();
057      }
058    
059      public Set<Entry<E>> entrySet() {
060        return delegate().entrySet();
061      }
062    
063      @Override public boolean equals(@Nullable Object object) {
064        return object == this || delegate().equals(object);
065      }
066    
067      @Override public int hashCode() {
068        return delegate().hashCode();
069      }
070    
071      public int setCount(E element, int count) {
072        return delegate().setCount(element, count);
073      }
074    
075      public boolean setCount(E element, int oldCount, int newCount) {
076        return delegate().setCount(element, oldCount, newCount);
077      }
078    }