AbstractNavigableSetDecorator.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.set;

  18. import java.util.Iterator;
  19. import java.util.NavigableSet;

  20. /**
  21.  * Decorates another {@code NavigableSet} to provide additional behavior.
  22.  * <p>
  23.  * Methods are forwarded directly to the decorated set.
  24.  * </p>
  25.  *
  26.  * @param <E> the type of the elements in the navigable set
  27.  * @since 4.1
  28.  */
  29. public abstract class AbstractNavigableSetDecorator<E>
  30.         extends AbstractSortedSetDecorator<E>
  31.         implements NavigableSet<E> {

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

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

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

  48.     @Override
  49.     public E ceiling(final E e) {
  50.         return decorated().ceiling(e);
  51.     }

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

  61.     @Override
  62.     public Iterator<E> descendingIterator() {
  63.         return decorated().descendingIterator();
  64.     }

  65.     @Override
  66.     public NavigableSet<E> descendingSet() {
  67.         return decorated().descendingSet();
  68.     }

  69.     @Override
  70.     public E floor(final E e) {
  71.         return decorated().floor(e);
  72.     }

  73.     @Override
  74.     public NavigableSet<E> headSet(final E toElement, final boolean inclusive) {
  75.         return decorated().headSet(toElement, inclusive);
  76.     }

  77.     @Override
  78.     public E higher(final E e) {
  79.         return decorated().higher(e);
  80.     }

  81.     @Override
  82.     public E lower(final E e) {
  83.         return decorated().lower(e);
  84.     }

  85.     @Override
  86.     public E pollFirst() {
  87.         return decorated().pollFirst();
  88.     }

  89.     @Override
  90.     public E pollLast() {
  91.         return decorated().pollLast();
  92.     }

  93.     @Override
  94.     public NavigableSet<E> subSet(final E fromElement, final boolean fromInclusive, final E toElement,
  95.             final boolean toInclusive) {
  96.         return decorated().subSet(fromElement, fromInclusive, toElement, toInclusive);
  97.     }

  98.     @Override
  99.     public NavigableSet<E> tailSet(final E fromElement, final boolean inclusive) {
  100.         return decorated().tailSet(fromElement, inclusive);
  101.     }

  102. }