net.admin4j.deps.commons.collections.bidimap.UnmodifiableOrderedBidiMap Maven / Gradle / Ivy
Show all versions of admin4j Show documentation
/*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.admin4j.deps.commons.collections.bidimap;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import net.admin4j.deps.commons.collections.BidiMap;
import net.admin4j.deps.commons.collections.MapIterator;
import net.admin4j.deps.commons.collections.OrderedBidiMap;
import net.admin4j.deps.commons.collections.OrderedMapIterator;
import net.admin4j.deps.commons.collections.Unmodifiable;
import net.admin4j.deps.commons.collections.collection.UnmodifiableCollection;
import net.admin4j.deps.commons.collections.iterators.UnmodifiableOrderedMapIterator;
import net.admin4j.deps.commons.collections.map.UnmodifiableEntrySet;
import net.admin4j.deps.commons.collections.set.UnmodifiableSet;
/**
* Decorates another OrderedBidiMap
to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
*
* @author Stephen Colebourne
*/
public final class UnmodifiableOrderedBidiMap
extends AbstractOrderedBidiMapDecorator implements Unmodifiable {
/** The inverse unmodifiable map */
private UnmodifiableOrderedBidiMap inverse;
/**
* Factory method to create an unmodifiable map.
*
* If the map passed in is already unmodifiable, it is returned.
*
* @param map the map to decorate, must not be null
* @return an unmodifiable OrderedBidiMap
* @throws IllegalArgumentException if map is null
*/
public static OrderedBidiMap decorate(OrderedBidiMap map) {
if (map instanceof Unmodifiable) {
return map;
}
return new UnmodifiableOrderedBidiMap(map);
}
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies).
*
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
private UnmodifiableOrderedBidiMap(OrderedBidiMap map) {
super(map);
}
//-----------------------------------------------------------------------
public void clear() {
throw new UnsupportedOperationException();
}
public Object put(Object key, Object value) {
throw new UnsupportedOperationException();
}
public void putAll(Map mapToCopy) {
throw new UnsupportedOperationException();
}
public Object remove(Object key) {
throw new UnsupportedOperationException();
}
public Set entrySet() {
Set set = super.entrySet();
return UnmodifiableEntrySet.decorate(set);
}
public Set keySet() {
Set set = super.keySet();
return UnmodifiableSet.decorate(set);
}
public Collection values() {
Collection coll = super.values();
return UnmodifiableCollection.decorate(coll);
}
//-----------------------------------------------------------------------
public Object removeValue(Object value) {
throw new UnsupportedOperationException();
}
public MapIterator mapIterator() {
return orderedMapIterator();
}
public BidiMap inverseBidiMap() {
return inverseOrderedBidiMap();
}
//-----------------------------------------------------------------------
public OrderedMapIterator orderedMapIterator() {
OrderedMapIterator it = getOrderedBidiMap().orderedMapIterator();
return UnmodifiableOrderedMapIterator.decorate(it);
}
public OrderedBidiMap inverseOrderedBidiMap() {
if (inverse == null) {
inverse = new UnmodifiableOrderedBidiMap(getOrderedBidiMap().inverseOrderedBidiMap());
inverse.inverse = this;
}
return inverse;
}
}