001: /*
002: * Copyright 2003-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.bidimap;
017:
018: import java.util.Collection;
019: import java.util.Map;
020: import java.util.Set;
021:
022: import org.apache.commons.collections.BidiMap;
023: import org.apache.commons.collections.MapIterator;
024: import org.apache.commons.collections.OrderedBidiMap;
025: import org.apache.commons.collections.OrderedMapIterator;
026: import org.apache.commons.collections.Unmodifiable;
027: import org.apache.commons.collections.collection.UnmodifiableCollection;
028: import org.apache.commons.collections.iterators.UnmodifiableOrderedMapIterator;
029: import org.apache.commons.collections.map.UnmodifiableEntrySet;
030: import org.apache.commons.collections.set.UnmodifiableSet;
031:
032: /**
033: * Decorates another <code>OrderedBidiMap</code> to ensure it can't be altered.
034: *
035: * @since Commons Collections 3.0
036: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
037: *
038: * @author Stephen Colebourne
039: */
040: public final class UnmodifiableOrderedBidiMap extends
041: AbstractOrderedBidiMapDecorator implements Unmodifiable {
042:
043: /** The inverse unmodifiable map */
044: private UnmodifiableOrderedBidiMap inverse;
045:
046: /**
047: * Factory method to create an unmodifiable map.
048: * <p>
049: * If the map passed in is already unmodifiable, it is returned.
050: *
051: * @param map the map to decorate, must not be null
052: * @return an unmodifiable OrderedBidiMap
053: * @throws IllegalArgumentException if map is null
054: */
055: public static OrderedBidiMap decorate(OrderedBidiMap map) {
056: if (map instanceof Unmodifiable) {
057: return map;
058: }
059: return new UnmodifiableOrderedBidiMap(map);
060: }
061:
062: //-----------------------------------------------------------------------
063: /**
064: * Constructor that wraps (not copies).
065: *
066: * @param map the map to decorate, must not be null
067: * @throws IllegalArgumentException if map is null
068: */
069: private UnmodifiableOrderedBidiMap(OrderedBidiMap map) {
070: super (map);
071: }
072:
073: //-----------------------------------------------------------------------
074: public void clear() {
075: throw new UnsupportedOperationException();
076: }
077:
078: public Object put(Object key, Object value) {
079: throw new UnsupportedOperationException();
080: }
081:
082: public void putAll(Map mapToCopy) {
083: throw new UnsupportedOperationException();
084: }
085:
086: public Object remove(Object key) {
087: throw new UnsupportedOperationException();
088: }
089:
090: public Set entrySet() {
091: Set set = super .entrySet();
092: return UnmodifiableEntrySet.decorate(set);
093: }
094:
095: public Set keySet() {
096: Set set = super .keySet();
097: return UnmodifiableSet.decorate(set);
098: }
099:
100: public Collection values() {
101: Collection coll = super .values();
102: return UnmodifiableCollection.decorate(coll);
103: }
104:
105: //-----------------------------------------------------------------------
106: public Object removeValue(Object value) {
107: throw new UnsupportedOperationException();
108: }
109:
110: public MapIterator mapIterator() {
111: return orderedMapIterator();
112: }
113:
114: public BidiMap inverseBidiMap() {
115: return inverseOrderedBidiMap();
116: }
117:
118: //-----------------------------------------------------------------------
119: public OrderedMapIterator orderedMapIterator() {
120: OrderedMapIterator it = getOrderedBidiMap()
121: .orderedMapIterator();
122: return UnmodifiableOrderedMapIterator.decorate(it);
123: }
124:
125: public OrderedBidiMap inverseOrderedBidiMap() {
126: if (inverse == null) {
127: inverse = new UnmodifiableOrderedBidiMap(
128: getOrderedBidiMap().inverseOrderedBidiMap());
129: inverse.inverse = this;
130: }
131: return inverse;
132: }
133:
134: }
|