KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 public final class UnmodifiableOrderedMapIterator implements OrderedMapIterator, Unmodifiable {
30
31     /** The iterator being decorated */
32     private OrderedMapIterator 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 OrderedMapIterator decorate(OrderedMapIterator iterator) {
42         if (iterator == null) {
43             throw new IllegalArgumentException JavaDoc("OrderedMapIterator must not be null");
44         }
45         if (iterator instanceof Unmodifiable) {
46             return iterator;
47         }
48         return new UnmodifiableOrderedMapIterator(iterator);
49     }
50     
51     //-----------------------------------------------------------------------
52
/**
53      * Constructor.
54      *
55      * @param iterator the iterator to decorate
56      */

57     private UnmodifiableOrderedMapIterator(OrderedMapIterator 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 boolean hasPrevious() {
72         return iterator.hasPrevious();
73     }
74
75     public Object JavaDoc previous() {
76         return iterator.previous();
77     }
78
79     public Object JavaDoc getKey() {
80         return iterator.getKey();
81     }
82
83     public Object JavaDoc getValue() {
84         return iterator.getValue();
85     }
86
87     public Object JavaDoc setValue(Object JavaDoc value) {
88         throw new UnsupportedOperationException JavaDoc("setValue() is not supported");
89     }
90
91     public void remove() {
92         throw new UnsupportedOperationException JavaDoc("remove() is not supported");
93     }
94
95 }
96
Popular Tags