KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

72     private UnmodifiableSortedBidiMap(SortedBidiMap map) {
73         super(map);
74     }
75
76     //-----------------------------------------------------------------------
77
public void clear() {
78         throw new UnsupportedOperationException JavaDoc();
79     }
80
81     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
82         throw new UnsupportedOperationException JavaDoc();
83     }
84
85     public void putAll(Map JavaDoc mapToCopy) {
86         throw new UnsupportedOperationException JavaDoc();
87     }
88
89     public Object JavaDoc remove(Object JavaDoc key) {
90         throw new UnsupportedOperationException JavaDoc();
91     }
92
93     public Set JavaDoc entrySet() {
94         Set JavaDoc set = super.entrySet();
95         return UnmodifiableEntrySet.decorate(set);
96     }
97
98     public Set JavaDoc keySet() {
99         Set JavaDoc set = super.keySet();
100         return UnmodifiableSet.decorate(set);
101     }
102
103     public Collection JavaDoc values() {
104         Collection JavaDoc coll = super.values();
105         return UnmodifiableCollection.decorate(coll);
106     }
107
108     //-----------------------------------------------------------------------
109
public Object JavaDoc removeValue(Object JavaDoc value) {
110         throw new UnsupportedOperationException JavaDoc();
111     }
112
113     public MapIterator mapIterator() {
114         return orderedMapIterator();
115     }
116
117     public BidiMap inverseBidiMap() {
118         return inverseSortedBidiMap();
119     }
120     
121     //-----------------------------------------------------------------------
122
public OrderedMapIterator orderedMapIterator() {
123         OrderedMapIterator it = getSortedBidiMap().orderedMapIterator();
124         return UnmodifiableOrderedMapIterator.decorate(it);
125     }
126
127     public OrderedBidiMap inverseOrderedBidiMap() {
128         return inverseSortedBidiMap();
129     }
130
131     //-----------------------------------------------------------------------
132
public SortedBidiMap inverseSortedBidiMap() {
133         if (inverse == null) {
134             inverse = new UnmodifiableSortedBidiMap(getSortedBidiMap().inverseSortedBidiMap());
135             inverse.inverse = this;
136         }
137         return inverse;
138     }
139
140     public SortedMap JavaDoc subMap(Object JavaDoc fromKey, Object JavaDoc toKey) {
141         SortedMap JavaDoc sm = getSortedBidiMap().subMap(fromKey, toKey);
142         return UnmodifiableSortedMap.decorate(sm);
143     }
144
145     public SortedMap JavaDoc headMap(Object JavaDoc toKey) {
146         SortedMap JavaDoc sm = getSortedBidiMap().headMap(toKey);
147         return UnmodifiableSortedMap.decorate(sm);
148     }
149
150     public SortedMap JavaDoc tailMap(Object JavaDoc fromKey) {
151         SortedMap JavaDoc sm = getSortedBidiMap().tailMap(fromKey);
152         return UnmodifiableSortedMap.decorate(sm);
153     }
154
155 }
156
Popular Tags