    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.set;
    018
    019import java.util.Comparator;
    020import java.util.Set;
    021import java.util.SortedSet;
    022
    023/**
    024 * Decorates another {@code SortedSet} to provide additional behavior.
    025 * <p>
    026 * Methods are forwarded directly to the decorated set.
    027 * </p>
    028 *
    029 * @param <E> the type of the elements in the sorted set
    030 * @since 3.0
    031 */
    032public abstract class AbstractSortedSetDecorator<E>
    033        extends AbstractSetDecorator<E>
    034        implements SortedSet<E> {
    035
    036    /** Serialization version */
    037    private static final long serialVersionUID = -3462240946294214398L;
    038
    039    /**
    040     * Constructor only used in deserialization, do not use otherwise.
    041     * @since 3.1
    042     */
    043    protected AbstractSortedSetDecorator() {
    044    }
    045
    046    /**
    047     * Constructor that wraps (not copies).
    048     *
    049     * @param set  the set to decorate, must not be null
    050     * @throws NullPointerException if set is null
    051     */
    052    protected AbstractSortedSetDecorator(final Set<E> set) {
    053        super(set);
    054    }
    055
    056    @Override
    057    public Comparator<? super E> comparator() {
    058        return decorated().comparator();
    059    }
    060
    061    /**
    062     * Gets the set being decorated.
    063     *
    064     * @return the decorated set
    065     */
    066    @Override
    067    protected SortedSet<E> decorated() {
    068        return (SortedSet<E>) super.decorated();
    069    }
    070
    071    @Override
    072    public E first() {
    073        return decorated().first();
    074    }
    075
    076    @Override
    077    public SortedSet<E> headSet(final E toElement) {
    078        return decorated().headSet(toElement);
    079    }
    080
    081    @Override
    082    public E last() {
    083        return decorated().last();
    084    }
    085
    086    @Override
    087    public SortedSet<E> subSet(final E fromElement, final E toElement) {
    088        return decorated().subSet(fromElement, toElement);
    089    }
    090
    091    @Override
    092    public SortedSet<E> tailSet(final E fromElement) {
    093        return decorated().tailSet(fromElement);
    094    }
    095
    096}