KickJava   Java API By Example, From Geeks To Geeks.

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


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.OrderedBidiMap;
25 import org.apache.commons.collections.OrderedMapIterator;
26 import org.apache.commons.collections.Unmodifiable;
27 import org.apache.commons.collections.collection.UnmodifiableCollection;
28 import org.apache.commons.collections.iterators.UnmodifiableOrderedMapIterator;
29 import org.apache.commons.collections.map.UnmodifiableEntrySet;
30 import org.apache.commons.collections.set.UnmodifiableSet;
31
32 /**
33  * Decorates another <code>OrderedBidiMap</code> to ensure it can't be altered.
34  *
35  * @since Commons Collections 3.0
36  * @version $Revision: 1.5 $ $Date: 2004/05/15 12:13:03 $
37  *
38  * @author Stephen Colebourne
39  */

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

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

69     private UnmodifiableOrderedBidiMap(OrderedBidiMap map) {
70         super(map);
71     }
72
73     //-----------------------------------------------------------------------
74
public void clear() {
75         throw new UnsupportedOperationException JavaDoc();
76     }
77
78     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
79         throw new UnsupportedOperationException JavaDoc();
80     }
81
82     public void putAll(Map JavaDoc mapToCopy) {
83         throw new UnsupportedOperationException JavaDoc();
84     }
85
86     public Object JavaDoc remove(Object JavaDoc key) {
87         throw new UnsupportedOperationException JavaDoc();
88     }
89
90     public Set JavaDoc entrySet() {
91         Set JavaDoc set = super.entrySet();
92         return UnmodifiableEntrySet.decorate(set);
93     }
94
95     public Set JavaDoc keySet() {
96         Set JavaDoc set = super.keySet();
97         return UnmodifiableSet.decorate(set);
98     }
99
100     public Collection JavaDoc values() {
101         Collection JavaDoc coll = super.values();
102         return UnmodifiableCollection.decorate(coll);
103     }
104
105     //-----------------------------------------------------------------------
106
public Object JavaDoc removeValue(Object JavaDoc value) {
107         throw new UnsupportedOperationException JavaDoc();
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().orderedMapIterator();
121         return UnmodifiableOrderedMapIterator.decorate(it);
122     }
123
124     public OrderedBidiMap inverseOrderedBidiMap() {
125         if (inverse == null) {
126             inverse = new UnmodifiableOrderedBidiMap(getOrderedBidiMap().inverseOrderedBidiMap());
127             inverse.inverse = this;
128         }
129         return inverse;
130     }
131
132 }
133
Popular Tags