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.multiset;
018
019import java.util.Comparator;
020
021import org.apache.commons.collections4.SortedMultiSet;
022
023/**
024 * Decorates another {@code SortedMultiSet} to provide additional behavior.
025 * <p>
026 * Methods are forwarded directly to the decorated multiset.
027 * </p>
028 *
029 * @param <E> The type held in the multiset
030 * @since 4.6.0
031 */
032public abstract class AbstractSortedMultiSetDecorator<E>
033        extends AbstractMultiSetDecorator<E> implements SortedMultiSet<E> {
034
035    /** Serialization version */
036    private static final long serialVersionUID = 20260705L;
037
038    /**
039     * Constructor only used in deserialization, do not use otherwise.
040     */
041    protected AbstractSortedMultiSetDecorator() {
042    }
043
044    /**
045     * Constructor that wraps (not copies).
046     *
047     * @param multiset  The multiset to decorate, must not be null
048     * @throws NullPointerException if multiset is null
049     */
050    protected AbstractSortedMultiSetDecorator(final SortedMultiSet<E> multiset) {
051        super(multiset);
052    }
053
054    @Override
055    public Comparator<? super E> comparator() {
056        return decorated().comparator();
057    }
058
059    /**
060     * Gets the multiset being decorated.
061     *
062     * @return The decorated multiset
063     */
064    @Override
065    protected SortedMultiSet<E> decorated() {
066        return (SortedMultiSet<E>) super.decorated();
067    }
068
069    @Override
070    public E first() {
071        return decorated().first();
072    }
073
074    @Override
075    public E last() {
076        return decorated().last();
077    }
078
079}