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