1
19
20 package com.liferay.portal.kernel.util;
21
22 import java.util.Collection;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.ListIterator;
26
27
40 public class UnmodifiableList<E> implements List<E> {
41
42 public UnmodifiableList(List<? extends E> list) {
43 if (list == null) {
44 throw new NullPointerException();
45 }
46
47 _list = list;
48 }
49
50 public boolean add(E element) {
51 throw new UnsupportedOperationException(_MESSAGE);
52 }
53
54 public void add(int index, E element) {
55 throw new UnsupportedOperationException(_MESSAGE);
56 }
57
58 public boolean addAll(Collection<? extends E> collection) {
59 throw new UnsupportedOperationException(_MESSAGE);
60 }
61
62 public boolean addAll(int index, Collection<? extends E> collection) {
63 throw new UnsupportedOperationException(_MESSAGE);
64 }
65
66 public void clear() {
67 throw new UnsupportedOperationException(_MESSAGE);
68 }
69
70 public boolean contains(Object object) {
71 return _list.contains(object);
72 }
73
74 public boolean containsAll(Collection<?> collection) {
75 return _list.containsAll(collection);
76 }
77
78 public boolean equals(Object object) {
79 return _list.equals(object);
80 }
81
82 public E get(int index) {
83 return _list.get(index);
84 }
85
86 public int hashCode() {
87 return _list.hashCode();
88 }
89
90 public int indexOf(Object object) {
91 return _list.indexOf(object);
92 }
93
94 public boolean isEmpty() {
95 return _list.isEmpty();
96 }
97
98 public Iterator<E> iterator() {
99 return new Iterator<E>() {
100
101 Iterator<? extends E> itr = _list.iterator();
102
103 public boolean hasNext() {
104 return itr.hasNext();
105 }
106
107 public E next() {
108 return itr.next();
109 }
110
111 public void remove() {
112 throw new UnsupportedOperationException(_MESSAGE);
113 }
114
115 };
116 }
117
118 public int lastIndexOf(Object o) {
119 return _list.lastIndexOf(o);
120 }
121
122 public ListIterator<E> listIterator() {
123 return listIterator(0);
124 }
125
126 public ListIterator<E> listIterator(final int index) {
127 return new ListIterator<E>() {
128
129 ListIterator<? extends E> itr = _list.listIterator(index);
130
131 public void add(E element) {
132 throw new UnsupportedOperationException(_MESSAGE);
133 }
134
135 public boolean hasNext() {
136 return itr.hasNext();
137 }
138
139 public E next() {
140 return itr.next();
141 }
142
143 public boolean hasPrevious() {
144 return itr.hasPrevious();
145 }
146
147 public E previous() {
148 return itr.previous();
149 }
150
151 public int nextIndex() {
152 return itr.nextIndex();
153 }
154
155 public int previousIndex() {
156 return itr.previousIndex();
157 }
158
159 public void remove() {
160 throw new UnsupportedOperationException(_MESSAGE);
161 }
162
163 public void set(E element) {
164 throw new UnsupportedOperationException(_MESSAGE);
165 }
166
167 };
168 }
169
170 public E remove(int index) {
171 throw new UnsupportedOperationException(_MESSAGE);
172 }
173
174 public boolean remove(Object object) {
175 throw new UnsupportedOperationException(_MESSAGE);
176 }
177
178 public boolean removeAll(Collection<?> collection) {
179 throw new UnsupportedOperationException(_MESSAGE);
180 }
181
182 public boolean retainAll(Collection<?> collection) {
183 throw new UnsupportedOperationException(_MESSAGE);
184 }
185
186 public E set(int index, E element) {
187 throw new UnsupportedOperationException(_MESSAGE);
188 }
189
190 public int size() {
191 return _list.size();
192 }
193
194 public List<E> subList(int fromIndex, int toIndex) {
195 return new UnmodifiableList<E>(_list.subList(fromIndex, toIndex));
196 }
197
198 public Object[] toArray() {
199 return _list.toArray();
200 }
201
202 public <T> T[] toArray(T[] a) {
203 return _list.toArray(a);
204 }
205
206 public String toString() {
207 return _list.toString();
208 }
209
210 private static final String _MESSAGE =
211 "Please make a copy of this read-only list before modifying it.";
212
213 private List<? extends E> _list;
214
215 }