KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > iterators > UnmodifiableMapIterator


1 /*
2  * Copyright 1999-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.iterators;
17
18 import org.apache.commons.collections.MapIterator;
19 import org.apache.commons.collections.Unmodifiable;
20
21 /**
22  * Decorates a map iterator such that it cannot be modified.
23  *
24  * @since Commons Collections 3.0
25  * @version $Revision: 1.7 $ $Date: 2004/02/18 00:59:50 $
26  *
27  * @author Stephen Colebourne
28  */

29 public final class UnmodifiableMapIterator implements MapIterator, Unmodifiable {
30
31     /** The iterator being decorated */
32     private MapIterator iterator;
33
34     //-----------------------------------------------------------------------
35
/**
36      * Decorates the specified iterator such that it cannot be modified.
37      *
38      * @param iterator the iterator to decorate
39      * @throws IllegalArgumentException if the iterator is null
40      */

41     public static MapIterator decorate(MapIterator iterator) {
42         if (iterator == null) {
43             throw new IllegalArgumentException JavaDoc("MapIterator must not be null");
44         }
45         if (iterator instanceof Unmodifiable) {
46             return iterator;
47         }
48         return new UnmodifiableMapIterator(iterator);
49     }
50     
51     //-----------------------------------------------------------------------
52
/**
53      * Constructor.
54      *
55      * @param iterator the iterator to decorate
56      */

57     private UnmodifiableMapIterator(MapIterator iterator) {
58         super();
59         this.iterator = iterator;
60     }
61
62     //-----------------------------------------------------------------------
63
public boolean hasNext() {
64         return iterator.hasNext();
65     }
66
67     public Object JavaDoc next() {
68         return iterator.next();
69     }
70
71     public Object JavaDoc getKey() {
72         return iterator.getKey();
73     }
74
75     public Object JavaDoc getValue() {
76         return iterator.getValue();
77     }
78
79     public Object JavaDoc setValue(Object JavaDoc value) {
80         throw new UnsupportedOperationException JavaDoc("setValue() is not supported");
81     }
82
83     public void remove() {
84         throw new UnsupportedOperationException JavaDoc("remove() is not supported");
85     }
86
87 }
88
Popular Tags