AbstractMultiSetDecorator.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.collections4.multiset;

  18. import java.util.Set;

  19. import org.apache.commons.collections4.MultiSet;
  20. import org.apache.commons.collections4.collection.AbstractCollectionDecorator;

  21. /**
  22.  * Decorates another {@code MultiSet} to provide additional behavior.
  23.  * <p>
  24.  * Methods are forwarded directly to the decorated multiset.
  25.  * </p>
  26.  *
  27.  * @param <E> the type held in the multiset
  28.  * @since 4.1
  29.  */
  30. public abstract class AbstractMultiSetDecorator<E>
  31.         extends AbstractCollectionDecorator<E> implements MultiSet<E> {

  32.     /** Serialization version */
  33.     private static final long serialVersionUID = 20150610L;

  34.     /**
  35.      * Constructor only used in deserialization, do not use otherwise.
  36.      */
  37.     protected AbstractMultiSetDecorator() {
  38.     }

  39.     /**
  40.      * Constructor that wraps (not copies).
  41.      *
  42.      * @param multiset  the multiset to decorate, must not be null
  43.      * @throws NullPointerException if multiset is null
  44.      */
  45.     protected AbstractMultiSetDecorator(final MultiSet<E> multiset) {
  46.         super(multiset);
  47.     }

  48.     @Override
  49.     public int add(final E object, final int count) {
  50.         return decorated().add(object, count);
  51.     }

  52.     /**
  53.      * Gets the multiset being decorated.
  54.      *
  55.      * @return the decorated multiset
  56.      */
  57.     @Override
  58.     protected MultiSet<E> decorated() {
  59.         return (MultiSet<E>) super.decorated();
  60.     }

  61.     @Override
  62.     public Set<Entry<E>> entrySet() {
  63.         return decorated().entrySet();
  64.     }

  65.     @Override
  66.     public boolean equals(final Object object) {
  67.         return object == this || decorated().equals(object);
  68.     }

  69.     @Override
  70.     public int getCount(final Object object) {
  71.         return decorated().getCount(object);
  72.     }

  73.     @Override
  74.     public int hashCode() {
  75.         return decorated().hashCode();
  76.     }

  77.     @Override
  78.     public int remove(final Object object, final int count) {
  79.         return decorated().remove(object, count);
  80.     }

  81.     @Override
  82.     public int setCount(final E object, final int count) {
  83.         return decorated().setCount(object, count);
  84.     }

  85.     @Override
  86.     public Set<E> uniqueSet() {
  87.         return decorated().uniqueSet();
  88.     }

  89. }