820 |
* @throws UnsupportedOperationException if l.listIterator() does not |
* @throws UnsupportedOperationException if l.listIterator() does not |
821 |
* support the set operation. |
* support the set operation. |
822 |
*/ |
*/ |
823 |
public static <T> void fill(List<T> l, T val) |
public static <T> void fill(List<? super T> l, T val) |
824 |
{ |
{ |
825 |
ListIterator<T> itr = l.listIterator(); |
ListIterator<? super T> itr = l.listIterator(); |
826 |
for (int i = l.size() - 1; i >= 0; --i) |
for (int i = l.size() - 1; i >= 0; --i) |
827 |
{ |
{ |
828 |
itr.next(); |
itr.next(); |
1178 |
* @throws UnsupportedOperationException if l.listIterator() does not |
* @throws UnsupportedOperationException if l.listIterator() does not |
1179 |
* support the set operation |
* support the set operation |
1180 |
*/ |
*/ |
1181 |
public static <T> void reverse(List<T> l) |
public static void reverse(List<?> l) |
1182 |
{ |
{ |
1183 |
ListIterator<T> i1 = l.listIterator(); |
ListIterator i1 = l.listIterator(); |
1184 |
int pos1 = 1; |
int pos1 = 1; |
1185 |
int pos2 = l.size(); |
int pos2 = l.size(); |
1186 |
ListIterator<T> i2 = l.listIterator(pos2); |
ListIterator i2 = l.listIterator(pos2); |
1187 |
while (pos1 < pos2) |
while (pos1 < pos2) |
1188 |
{ |
{ |
1189 |
T o = i1.next(); |
Object o1 = i1.next(); |
1190 |
i1.set(i2.previous()); |
Object o2 = i2.previous(); |
1191 |
i2.set(o); |
i1.set(o2); |
1192 |
|
i2.set(o1); |
1193 |
++pos1; |
++pos1; |
1194 |
--pos2; |
--pos2; |
1195 |
} |
} |
4184 |
* @return a read-only view of the collection |
* @return a read-only view of the collection |
4185 |
* @see Serializable |
* @see Serializable |
4186 |
*/ |
*/ |
4187 |
public static <T> Collection<T> unmodifiableCollection(Collection<T> c) |
public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) |
4188 |
{ |
{ |
4189 |
return new UnmodifiableCollection<T>(c); |
return new UnmodifiableCollection<T>(c); |
4190 |
} |
} |
4207 |
* The wrapped collection. Package visible for use by subclasses. |
* The wrapped collection. Package visible for use by subclasses. |
4208 |
* @serial the real collection |
* @serial the real collection |
4209 |
*/ |
*/ |
4210 |
final Collection<T> c; |
final Collection<? extends T> c; |
4211 |
|
|
4212 |
/** |
/** |
4213 |
* Wrap a given collection. |
* Wrap a given collection. |
4214 |
* @param c the collection to wrap |
* @param c the collection to wrap |
4215 |
* @throws NullPointerException if c is null |
* @throws NullPointerException if c is null |
4216 |
*/ |
*/ |
4217 |
UnmodifiableCollection(Collection<T> c) |
UnmodifiableCollection(Collection<? extends T> c) |
4218 |
{ |
{ |
4219 |
this.c = c; |
this.c = c; |
4220 |
if (c == null) |
if (c == null) |
4431 |
/** |
/** |
4432 |
* The wrapped iterator. |
* The wrapped iterator. |
4433 |
*/ |
*/ |
4434 |
private final Iterator<T> i; |
private final Iterator<? extends T> i; |
4435 |
|
|
4436 |
/** |
/** |
4437 |
* Only trusted code creates a wrapper. |
* Only trusted code creates a wrapper. |
4438 |
* @param i the wrapped iterator |
* @param i the wrapped iterator |
4439 |
*/ |
*/ |
4440 |
UnmodifiableIterator(Iterator<T> i) |
UnmodifiableIterator(Iterator<? extends T> i) |
4441 |
{ |
{ |
4442 |
this.i = i; |
this.i = i; |
4443 |
} |
} |
5267 |
* @return a read-only view of the set |
* @return a read-only view of the set |
5268 |
* @see Serializable |
* @see Serializable |
5269 |
*/ |
*/ |
5270 |
public static <T> Set<T> unmodifiableSet(Set<T> s) |
public static <T> Set<T> unmodifiableSet(Set<? extends T> s) |
5271 |
{ |
{ |
5272 |
return new UnmodifiableSet<T>(s); |
return new UnmodifiableSet<T>(s); |
5273 |
} |
} |
5291 |
* @param s the set to wrap |
* @param s the set to wrap |
5292 |
* @throws NullPointerException if s is null |
* @throws NullPointerException if s is null |
5293 |
*/ |
*/ |
5294 |
UnmodifiableSet(Set<T> s) |
UnmodifiableSet(Set<? extends T> s) |
5295 |
{ |
{ |
5296 |
super(s); |
super(s); |
5297 |
} |
} |