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