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