KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > bidimap > UnmodifiableBidiMap


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.bidimap;
17
18 import java.util.Collection JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import org.apache.commons.collections.BidiMap;
23 import org.apache.commons.collections.MapIterator;
24 import org.apache.commons.collections.Unmodifiable;
25 import org.apache.commons.collections.collection.UnmodifiableCollection;
26 import org.apache.commons.collections.iterators.UnmodifiableMapIterator;
27 import org.apache.commons.collections.map.UnmodifiableEntrySet;
28 import org.apache.commons.collections.set.UnmodifiableSet;
29
30 /**
31  * Decorates another <code>BidiMap</code> to ensure it can't be altered.
32  *
33  * @since Commons Collections 3.0
34  * @version $Revision: 1.5 $ $Date: 2004/05/15 12:13:03 $
35  *
36  * @author Stephen Colebourne
37  */

38 public final class UnmodifiableBidiMap
39         extends AbstractBidiMapDecorator implements Unmodifiable {
40     
41     /** The inverse unmodifiable map */
42     private UnmodifiableBidiMap inverse;
43
44     /**
45      * Factory method to create an unmodifiable map.
46      * <p>
47      * If the map passed in is already unmodifiable, it is returned.
48      *
49      * @param map the map to decorate, must not be null
50      * @return an unmodifiable BidiMap
51      * @throws IllegalArgumentException if map is null
52      */

53     public static BidiMap decorate(BidiMap map) {
54         if (map instanceof Unmodifiable) {
55             return map;
56         }
57         return new UnmodifiableBidiMap(map);
58     }
59
60     //-----------------------------------------------------------------------
61
/**
62      * Constructor that wraps (not copies).
63      *
64      * @param map the map to decorate, must not be null
65      * @throws IllegalArgumentException if map is null
66      */

67     private UnmodifiableBidiMap(BidiMap map) {
68         super(map);
69     }
70
71     //-----------------------------------------------------------------------
72
public void clear() {
73         throw new UnsupportedOperationException JavaDoc();
74     }
75
76     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
77         throw new UnsupportedOperationException JavaDoc();
78     }
79
80     public void putAll(Map JavaDoc mapToCopy) {
81         throw new UnsupportedOperationException JavaDoc();
82     }
83
84     public Object JavaDoc remove(Object JavaDoc key) {
85         throw new UnsupportedOperationException JavaDoc();
86     }
87
88     public Set JavaDoc entrySet() {
89         Set JavaDoc set = super.entrySet();
90         return UnmodifiableEntrySet.decorate(set);
91     }
92
93     public Set JavaDoc keySet() {
94         Set JavaDoc set = super.keySet();
95         return UnmodifiableSet.decorate(set);
96     }
97
98     public Collection JavaDoc values() {
99         Collection JavaDoc coll = super.values();
100         return UnmodifiableCollection.decorate(coll);
101     }
102
103     //-----------------------------------------------------------------------
104
public Object JavaDoc removeValue(Object JavaDoc value) {
105         throw new UnsupportedOperationException JavaDoc();
106     }
107
108     public MapIterator mapIterator() {
109         MapIterator it = getBidiMap().mapIterator();
110         return UnmodifiableMapIterator.decorate(it);
111     }
112
113     public BidiMap inverseBidiMap() {
114         if (inverse == null) {
115             inverse = new UnmodifiableBidiMap(getBidiMap().inverseBidiMap());
116             inverse.inverse = this;
117         }
118         return inverse;
119     }
120     
121 }
122
Popular Tags