AbstractSortedBidiMapDecorator.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.bidimap;

  18. import java.util.Comparator;
  19. import java.util.SortedMap;

  20. import org.apache.commons.collections4.SortedBidiMap;

  21. /**
  22.  * Provides a base decorator that enables additional functionality to be added
  23.  * to a SortedBidiMap via decoration.
  24.  * <p>
  25.  * Methods are forwarded directly to the decorated map.
  26.  * </p>
  27.  * <p>
  28.  * This implementation does not perform any special processing with the map views.
  29.  * Instead it simply returns the inverse from the wrapped map. This may be
  30.  * undesirable, for example if you are trying to write a validating implementation
  31.  * it would provide a loophole around the validation.
  32.  * But, you might want that loophole, so this class is kept simple.
  33.  * </p>
  34.  *
  35.  * @param <K> the type of the keys in this map
  36.  * @param <V> the type of the values in this map
  37.  * @since 3.0
  38.  */
  39. public abstract class AbstractSortedBidiMapDecorator<K, V>
  40.         extends AbstractOrderedBidiMapDecorator<K, V> implements SortedBidiMap<K, V> {

  41.     /**
  42.      * Constructor that wraps (not copies).
  43.      *
  44.      * @param map  the map to decorate, must not be null
  45.      * @throws NullPointerException if the collection is null
  46.      */
  47.     public AbstractSortedBidiMapDecorator(final SortedBidiMap<K, V> map) {
  48.         super(map);
  49.     }

  50.     @Override
  51.     public Comparator<? super K> comparator() {
  52.         return decorated().comparator();
  53.     }

  54.     /**
  55.      * Gets the map being decorated.
  56.      *
  57.      * @return the decorated map
  58.      */
  59.     @Override
  60.     protected SortedBidiMap<K, V> decorated() {
  61.         return (SortedBidiMap<K, V>) super.decorated();
  62.     }

  63.     @Override
  64.     public SortedMap<K, V> headMap(final K toKey) {
  65.         return decorated().headMap(toKey);
  66.     }

  67.     @Override
  68.     public SortedBidiMap<V, K> inverseBidiMap() {
  69.         return decorated().inverseBidiMap();
  70.     }

  71.     @Override
  72.     public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
  73.         return decorated().subMap(fromKey, toKey);
  74.     }

  75.     @Override
  76.     public SortedMap<K, V> tailMap(final K fromKey) {
  77.         return decorated().tailMap(fromKey);
  78.     }

  79.     @Override
  80.     public Comparator<? super V> valueComparator() {
  81.         return decorated().valueComparator();
  82.     }

  83. }