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.bidimap;
018
019import java.util.Set;
020
021import org.apache.commons.collections4.BidiMap;
022import org.apache.commons.collections4.MapIterator;
023import org.apache.commons.collections4.map.AbstractMapDecorator;
024
025/**
026 * Provides a base decorator that enables additional functionality to be added
027 * to a BidiMap via decoration.
028 * <p>
029 * Methods are forwarded directly to the decorated map.
030 * <p>
031 * This implementation does not perform any special processing with the map views.
032 * Instead it simply returns the set/collection from the wrapped map. This may be
033 * undesirable, for example if you are trying to write a validating implementation
034 * it would provide a loophole around the validation.
035 * But, you might want that loophole, so this class is kept simple.
036 *
037 * @param <K> the type of the keys in this map
038 * @param <V> the type of the values in this map
039 * @since 3.0
040 */
041public abstract class AbstractBidiMapDecorator<K, V>
042        extends AbstractMapDecorator<K, V> implements BidiMap<K, V> {
043
044    /**
045     * Constructor that wraps (not copies).
046     *
047     * @param map  the map to decorate, must not be null
048     * @throws NullPointerException if the collection is null
049     */
050    protected AbstractBidiMapDecorator(final BidiMap<K, V> map) {
051        super(map);
052    }
053
054    /**
055     * Gets the map being decorated.
056     *
057     * @return the decorated map
058     */
059    @Override
060    protected BidiMap<K, V> decorated() {
061        return (BidiMap<K, V>) super.decorated();
062    }
063
064    //-----------------------------------------------------------------------
065    @Override
066    public MapIterator<K, V> mapIterator() {
067        return decorated().mapIterator();
068    }
069
070    @Override
071    public K getKey(final Object value) {
072        return decorated().getKey(value);
073    }
074
075    @Override
076    public K removeValue(final Object value) {
077        return decorated().removeValue(value);
078    }
079
080    @Override
081    public BidiMap<V, K> inverseBidiMap() {
082        return decorated().inverseBidiMap();
083    }
084
085    @Override
086    public Set<V> values() {
087        return decorated().values();
088    }
089
090}