1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.iterators;
18
19 import java.util.ListIterator;
20 import java.util.Objects;
21
22 import org.apache.commons.collections4.Unmodifiable;
23
24
25
26
27
28
29
30
31
32
33 public final class UnmodifiableListIterator<E> implements ListIterator<E>, Unmodifiable {
34
35
36
37
38
39
40
41
42
43
44 @Deprecated
45 public static <E> ListIterator<E> umodifiableListIterator(final ListIterator<? extends E> iterator) {
46 return unmodifiableListIterator(iterator);
47 }
48
49
50
51
52
53
54
55
56
57 public static <E> ListIterator<E> unmodifiableListIterator(final ListIterator<? extends E> iterator) {
58 Objects.requireNonNull(iterator, "iterator");
59 if (iterator instanceof Unmodifiable) {
60 @SuppressWarnings("unchecked")
61 final ListIterator<E> tmpIterator = (ListIterator<E>) iterator;
62 return tmpIterator;
63 }
64 return new UnmodifiableListIterator<>(iterator);
65 }
66
67
68 private final ListIterator<? extends E> iterator;
69
70
71
72
73
74
75 private UnmodifiableListIterator(final ListIterator<? extends E> iterator) {
76 this.iterator = iterator;
77 }
78
79 @Override
80 public void add(final E obj) {
81 throw new UnsupportedOperationException("add() is not supported");
82 }
83
84 @Override
85 public boolean hasNext() {
86 return iterator.hasNext();
87 }
88
89 @Override
90 public boolean hasPrevious() {
91 return iterator.hasPrevious();
92 }
93
94 @Override
95 public E next() {
96 return iterator.next();
97 }
98
99 @Override
100 public int nextIndex() {
101 return iterator.nextIndex();
102 }
103
104 @Override
105 public E previous() {
106 return iterator.previous();
107 }
108
109 @Override
110 public int previousIndex() {
111 return iterator.previousIndex();
112 }
113
114 @Override
115 public void remove() {
116 throw new UnsupportedOperationException("remove() is not supported");
117 }
118
119 @Override
120 public void set(final E ignored) {
121 throw new UnsupportedOperationException("set() is not supported");
122 }
123
124 }