KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

58     private UnmodifiableListIterator(ListIterator JavaDoc iterator) {
59         super();
60         this.iterator = iterator;
61     }
62
63     //-----------------------------------------------------------------------
64
public boolean hasNext() {
65         return iterator.hasNext();
66     }
67
68     public Object JavaDoc next() {
69         return iterator.next();
70     }
71
72     public int nextIndex() {
73         return iterator.nextIndex();
74     }
75
76     public boolean hasPrevious() {
77         return iterator.hasPrevious();
78     }
79
80     public Object JavaDoc previous() {
81         return iterator.previous();
82     }
83
84     public int previousIndex() {
85         return iterator.previousIndex();
86     }
87
88     public void remove() {
89         throw new UnsupportedOperationException JavaDoc("remove() is not supported");
90     }
91
92     public void set(Object JavaDoc obj) {
93         throw new UnsupportedOperationException JavaDoc("set() is not supported");
94     }
95
96     public void add(Object JavaDoc obj) {
97         throw new UnsupportedOperationException JavaDoc("add() is not supported");
98     }
99
100 }
101
Popular Tags