KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > map > UnmodifiableOrderedMap


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.map;
17
18 import java.io.IOException JavaDoc;
19 import java.io.ObjectInputStream JavaDoc;
20 import java.io.ObjectOutputStream JavaDoc;
21 import java.io.Serializable JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import org.apache.commons.collections.MapIterator;
27 import org.apache.commons.collections.OrderedMap;
28 import org.apache.commons.collections.OrderedMapIterator;
29 import org.apache.commons.collections.Unmodifiable;
30 import org.apache.commons.collections.collection.UnmodifiableCollection;
31 import org.apache.commons.collections.iterators.UnmodifiableMapIterator;
32 import org.apache.commons.collections.iterators.UnmodifiableOrderedMapIterator;
33 import org.apache.commons.collections.set.UnmodifiableSet;
34
35 /**
36  * Decorates another <code>OrderedMap</code> to ensure it can't be altered.
37  * <p>
38  * This class is Serializable from Commons Collections 3.1.
39  *
40  * @since Commons Collections 3.0
41  * @version $Revision: 1.8 $ $Date: 2004/04/09 10:46:32 $
42  *
43  * @author Stephen Colebourne
44  */

45 public final class UnmodifiableOrderedMap
46         extends AbstractOrderedMapDecorator
47         implements Unmodifiable, Serializable JavaDoc {
48
49     /** Serialization version */
50     private static final long serialVersionUID = 8136428161720526266L;
51
52     /**
53      * Factory method to create an unmodifiable sorted map.
54      *
55      * @param map the map to decorate, must not be null
56      * @throws IllegalArgumentException if map is null
57      */

58     public static OrderedMap decorate(OrderedMap map) {
59         if (map instanceof Unmodifiable) {
60             return map;
61         }
62         return new UnmodifiableOrderedMap(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 UnmodifiableOrderedMap(OrderedMap map) {
73         super(map);
74     }
75
76     //-----------------------------------------------------------------------
77
/**
78      * Write the map out using a custom routine.
79      *
80      * @param out the output stream
81      * @throws IOException
82      * @since Commons Collections 3.1
83      */

84     private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
85         out.defaultWriteObject();
86         out.writeObject(map);
87     }
88
89     /**
90      * Read the map in using a custom routine.
91      *
92      * @param in the input stream
93      * @throws IOException
94      * @throws ClassNotFoundException
95      * @since Commons Collections 3.1
96      */

97     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
98         in.defaultReadObject();
99         map = (Map JavaDoc) in.readObject();
100     }
101
102     //-----------------------------------------------------------------------
103
public MapIterator mapIterator() {
104         MapIterator it = getOrderedMap().mapIterator();
105         return UnmodifiableMapIterator.decorate(it);
106     }
107
108     public OrderedMapIterator orderedMapIterator() {
109         OrderedMapIterator it = getOrderedMap().orderedMapIterator();
110         return UnmodifiableOrderedMapIterator.decorate(it);
111     }
112
113     public void clear() {
114         throw new UnsupportedOperationException JavaDoc();
115     }
116
117     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
118         throw new UnsupportedOperationException JavaDoc();
119     }
120
121     public void putAll(Map JavaDoc mapToCopy) {
122         throw new UnsupportedOperationException JavaDoc();
123     }
124
125     public Object JavaDoc remove(Object JavaDoc key) {
126         throw new UnsupportedOperationException JavaDoc();
127     }
128
129     public Set JavaDoc entrySet() {
130         Set JavaDoc set = super.entrySet();
131         return UnmodifiableEntrySet.decorate(set);
132     }
133
134     public Set JavaDoc keySet() {
135         Set JavaDoc set = super.keySet();
136         return UnmodifiableSet.decorate(set);
137     }
138
139     public Collection JavaDoc values() {
140         Collection JavaDoc coll = super.values();
141         return UnmodifiableCollection.decorate(coll);
142     }
143
144 }
145
Popular Tags