1 |
|
/* |
2 |
|
* %W% %E% |
3 |
|
* |
4 |
< |
* Copyright 2004 Sun Microsystems, Inc. All rights reserved. |
4 |
> |
* Copyright 2005 Sun Microsystems, Inc. All rights reserved. |
5 |
|
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
6 |
|
*/ |
7 |
|
|
37 |
|
* example, invoking the <tt>sort</tt> method on an unmodifiable list that is |
38 |
|
* already sorted may or may not throw <tt>UnsupportedOperationException</tt>. |
39 |
|
* |
40 |
< |
* <p>This class is a member of the |
40 |
> |
* <p>This class is a member of the |
41 |
|
* <a href="{@docRoot}/../guide/collections/index.html"> |
42 |
|
* Java Collections Framework</a>. |
43 |
|
* |
63 |
|
* two implementations, one of which is appropriate for RandomAccess |
64 |
|
* lists, the other for "sequential." Often, the random access variant |
65 |
|
* yields better performance on small sequential access lists. The |
66 |
< |
* tuning parameters below determine the cutoff point for what constitutes |
66 |
> |
* tuning parameters below determine the cutoff point for what constitutes |
67 |
|
* a "small" sequential access list for each algorithm. The values below |
68 |
|
* were empirically determined to work well for LinkedList. Hopefully |
69 |
|
* they should be reasonable for other sequential access List |
97 |
|
* The sorting algorithm is a modified mergesort (in which the merge is |
98 |
|
* omitted if the highest element in the low sublist is less than the |
99 |
|
* lowest element in the high sublist). This algorithm offers guaranteed |
100 |
< |
* n log(n) performance. |
100 |
> |
* n log(n) performance. |
101 |
|
* |
102 |
|
* This implementation dumps the specified list into an array, sorts |
103 |
|
* the array, and iterates over the list resetting each element |
135 |
|
* The sorting algorithm is a modified mergesort (in which the merge is |
136 |
|
* omitted if the highest element in the low sublist is less than the |
137 |
|
* lowest element in the high sublist). This algorithm offers guaranteed |
138 |
< |
* n log(n) performance. |
138 |
> |
* n log(n) performance. |
139 |
|
* |
140 |
|
* The specified list must be modifiable, but need not be resizable. |
141 |
|
* This implementation dumps the specified list into an array, sorts |
182 |
|
* |
183 |
|
* @param list the list to be searched. |
184 |
|
* @param key the key to be searched for. |
185 |
< |
* @return index of the search key, if it is contained in the list; |
185 |
> |
* @return the index of the search key, if it is contained in the list; |
186 |
|
* otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. The |
187 |
|
* <i>insertion point</i> is defined as the point at which the |
188 |
|
* key would be inserted into the list: the index of the first |
287 |
|
* @param c the comparator by which the list is ordered. A |
288 |
|
* <tt>null</tt> value indicates that the elements' <i>natural |
289 |
|
* ordering</i> should be used. |
290 |
< |
* @return index of the search key, if it is contained in the list; |
290 |
> |
* @return the index of the search key, if it is contained in the list; |
291 |
|
* otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. The |
292 |
|
* <i>insertion point</i> is defined as the point at which the |
293 |
|
* key would be inserted into the list: the index of the first |
361 |
|
* |
362 |
|
* @param list the list whose elements are to be reversed. |
363 |
|
* @throws UnsupportedOperationException if the specified list or |
364 |
< |
* its list-iterator does not support the <tt>set</tt> method. |
364 |
> |
* its list-iterator does not support the <tt>set</tt> operation. |
365 |
|
*/ |
366 |
|
public static void reverse(List<?> list) { |
367 |
|
int size = list.size(); |
405 |
|
* |
406 |
|
* @param list the list to be shuffled. |
407 |
|
* @throws UnsupportedOperationException if the specified list or |
408 |
< |
* its list-iterator does not support the <tt>set</tt> method. |
408 |
> |
* its list-iterator does not support the <tt>set</tt> operation. |
409 |
|
*/ |
410 |
|
public static void shuffle(List<?> list) { |
411 |
|
shuffle(list, r); |
569 |
|
Iterator<? extends T> i = coll.iterator(); |
570 |
|
T candidate = i.next(); |
571 |
|
|
572 |
< |
while(i.hasNext()) { |
572 |
> |
while (i.hasNext()) { |
573 |
|
T next = i.next(); |
574 |
|
if (next.compareTo(candidate) < 0) |
575 |
|
candidate = next; |
606 |
|
Iterator<? extends T> i = coll.iterator(); |
607 |
|
T candidate = i.next(); |
608 |
|
|
609 |
< |
while(i.hasNext()) { |
609 |
> |
while (i.hasNext()) { |
610 |
|
T next = i.next(); |
611 |
|
if (comp.compare(next, candidate) < 0) |
612 |
|
candidate = next; |
639 |
|
Iterator<? extends T> i = coll.iterator(); |
640 |
|
T candidate = i.next(); |
641 |
|
|
642 |
< |
while(i.hasNext()) { |
642 |
> |
while (i.hasNext()) { |
643 |
|
T next = i.next(); |
644 |
|
if (next.compareTo(candidate) > 0) |
645 |
|
candidate = next; |
676 |
|
Iterator<? extends T> i = coll.iterator(); |
677 |
|
T candidate = i.next(); |
678 |
|
|
679 |
< |
while(i.hasNext()) { |
679 |
> |
while (i.hasNext()) { |
680 |
|
T next = i.next(); |
681 |
|
if (comp.compare(next, candidate) > 0) |
682 |
|
candidate = next; |
712 |
|
* Collections.rotate(l.subList(1, 4), -1); |
713 |
|
* </pre> |
714 |
|
* The resulting list is <tt>[a, c, d, b, e]</tt>. |
715 |
< |
* |
715 |
> |
* |
716 |
|
* <p>To move more than one element forward, increase the absolute value |
717 |
|
* of the rotation distance. To move elements backward, use a positive |
718 |
|
* shift distance. |
736 |
|
* constraints on this value; it may be zero, negative, or |
737 |
|
* greater than <tt>list.size()</tt>. |
738 |
|
* @throws UnsupportedOperationException if the specified list or |
739 |
< |
* its list-iterator does not support the <tt>set</tt> method. |
739 |
> |
* its list-iterator does not support the <tt>set</tt> operation. |
740 |
|
* @since 1.4 |
741 |
|
*/ |
742 |
|
public static void rotate(List<?> list, int distance) { |
772 |
|
private static void rotate2(List<?> list, int distance) { |
773 |
|
int size = list.size(); |
774 |
|
if (size == 0) |
775 |
< |
return; |
775 |
> |
return; |
776 |
|
int mid = -distance % size; |
777 |
|
if (mid < 0) |
778 |
|
mid += size; |
799 |
|
* <tt>e</tt> such that |
800 |
|
* <tt>(oldVal==null ? e==null : oldVal.equals(e))</tt>. |
801 |
|
* @throws UnsupportedOperationException if the specified list or |
802 |
< |
* its list-iterator does not support the <tt>set</tt> method. |
802 |
> |
* its list-iterator does not support the <tt>set</tt> operation. |
803 |
|
* @since 1.4 |
804 |
|
*/ |
805 |
|
public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal) { |
970 |
|
* that the backing collection is a set or a list.<p> |
971 |
|
* |
972 |
|
* The returned collection will be serializable if the specified collection |
973 |
< |
* is serializable. |
973 |
> |
* is serializable. |
974 |
|
* |
975 |
|
* @param c the collection for which an unmodifiable view is to be |
976 |
|
* returned. |
1014 |
|
}; |
1015 |
|
} |
1016 |
|
|
1017 |
< |
public boolean add(E o){ |
1017 |
> |
public boolean add(E e){ |
1018 |
|
throw new UnsupportedOperationException(); |
1019 |
|
} |
1020 |
|
public boolean remove(Object o) { |
1046 |
|
* iterator, result in an <tt>UnsupportedOperationException</tt>.<p> |
1047 |
|
* |
1048 |
|
* The returned set will be serializable if the specified set |
1049 |
< |
* is serializable. |
1049 |
> |
* is serializable. |
1050 |
|
* |
1051 |
|
* @param s the set for which an unmodifiable view is to be returned. |
1052 |
|
* @return an unmodifiable view of the specified set. |
1053 |
|
*/ |
1054 |
– |
|
1054 |
|
public static <T> Set<T> unmodifiableSet(Set<? extends T> s) { |
1055 |
|
return new UnmodifiableSet<T>(s); |
1056 |
|
} |
1077 |
|
* an <tt>UnsupportedOperationException</tt>.<p> |
1078 |
|
* |
1079 |
|
* The returned sorted set will be serializable if the specified sorted set |
1080 |
< |
* is serializable. |
1080 |
> |
* is serializable. |
1081 |
|
* |
1082 |
|
* @param s the sorted set for which an unmodifiable view is to be |
1083 |
< |
* returned. |
1083 |
> |
* returned. |
1084 |
|
* @return an unmodifiable view of the specified sorted set. |
1085 |
|
*/ |
1086 |
|
public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) { |
1182 |
|
public void remove() { |
1183 |
|
throw new UnsupportedOperationException(); |
1184 |
|
} |
1185 |
< |
public void set(E o) { |
1185 |
> |
public void set(E e) { |
1186 |
|
throw new UnsupportedOperationException(); |
1187 |
|
} |
1188 |
< |
public void add(E o) { |
1188 |
> |
public void add(E e) { |
1189 |
|
throw new UnsupportedOperationException(); |
1190 |
|
} |
1191 |
|
}; |
1251 |
|
* <tt>UnsupportedOperationException</tt>.<p> |
1252 |
|
* |
1253 |
|
* The returned map will be serializable if the specified map |
1254 |
< |
* is serializable. |
1254 |
> |
* is serializable. |
1255 |
|
* |
1256 |
|
* @param m the map for which an unmodifiable view is to be returned. |
1257 |
|
* @return an unmodifiable view of the specified map. |
1333 |
|
private static final long serialVersionUID = 7854390611657943733L; |
1334 |
|
|
1335 |
|
UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) { |
1336 |
< |
super((Set<Map.Entry<K,V>>)(Set)s); |
1336 |
> |
super((Set)s); |
1337 |
|
} |
1338 |
|
public Iterator<Map.Entry<K,V>> iterator() { |
1339 |
|
return new Iterator<Map.Entry<K,V>>() { |
1455 |
|
* an <tt>UnsupportedOperationException</tt>.<p> |
1456 |
|
* |
1457 |
|
* The returned sorted map will be serializable if the specified sorted map |
1458 |
< |
* is serializable. |
1458 |
> |
* is serializable. |
1459 |
|
* |
1460 |
|
* @param m the sorted map for which an unmodifiable view is to be |
1461 |
< |
* returned. |
1461 |
> |
* returned. |
1462 |
|
* @return an unmodifiable view of the specified sorted map. |
1463 |
|
*/ |
1464 |
|
public static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K, ? extends V> m) { |
1522 |
|
* that the backing collection is a set or a list.<p> |
1523 |
|
* |
1524 |
|
* The returned collection will be serializable if the specified collection |
1525 |
< |
* is serializable. |
1525 |
> |
* is serializable. |
1526 |
|
* |
1527 |
|
* @param c the collection to be "wrapped" in a synchronized collection. |
1528 |
|
* @return a synchronized view of the specified collection. |
1576 |
|
return c.iterator(); // Must be manually synched by user! |
1577 |
|
} |
1578 |
|
|
1579 |
< |
public boolean add(E o) { |
1580 |
< |
synchronized(mutex) {return c.add(o);} |
1579 |
> |
public boolean add(E e) { |
1580 |
> |
synchronized(mutex) {return c.add(e);} |
1581 |
|
} |
1582 |
|
public boolean remove(Object o) { |
1583 |
|
synchronized(mutex) {return c.remove(o);} |
1672 |
|
* sorted set when iterating over it or any of its <tt>subSet</tt>, |
1673 |
|
* <tt>headSet</tt>, or <tt>tailSet</tt> views. |
1674 |
|
* <pre> |
1675 |
< |
* SortedSet s = Collections.synchronizedSortedSet(new HashSortedSet()); |
1675 |
> |
* SortedSet s = Collections.synchronizedSortedSet(new TreeSet()); |
1676 |
|
* ... |
1677 |
|
* synchronized(s) { |
1678 |
|
* Iterator i = s.iterator(); // Must be in the synchronized block |
1682 |
|
* </pre> |
1683 |
|
* or: |
1684 |
|
* <pre> |
1685 |
< |
* SortedSet s = Collections.synchronizedSortedSet(new HashSortedSet()); |
1685 |
> |
* SortedSet s = Collections.synchronizedSortedSet(new TreeSet()); |
1686 |
|
* SortedSet s2 = s.headSet(foo); |
1687 |
|
* ... |
1688 |
|
* synchronized(s) { // Note: s, not s2!!! |
2006 |
|
public Set<Map.Entry<K,V>> entrySet() { |
2007 |
|
synchronized(mutex) { |
2008 |
|
if (entrySet==null) |
2009 |
< |
entrySet = new SynchronizedSet<Map.Entry<K,V>>((Set<Map.Entry<K,V>>)m.entrySet(), mutex); |
2009 |
> |
entrySet = new SynchronizedSet<Map.Entry<K,V>>(m.entrySet(), mutex); |
2010 |
|
return entrySet; |
2011 |
|
} |
2012 |
|
} |
2044 |
|
* collections views of any of its <tt>subMap</tt>, <tt>headMap</tt> or |
2045 |
|
* <tt>tailMap</tt> views. |
2046 |
|
* <pre> |
2047 |
< |
* SortedMap m = Collections.synchronizedSortedMap(new HashSortedMap()); |
2047 |
> |
* SortedMap m = Collections.synchronizedSortedMap(new TreeMap()); |
2048 |
|
* ... |
2049 |
|
* Set s = m.keySet(); // Needn't be in synchronized block |
2050 |
|
* ... |
2056 |
|
* </pre> |
2057 |
|
* or: |
2058 |
|
* <pre> |
2059 |
< |
* SortedMap m = Collections.synchronizedSortedMap(new HashSortedMap()); |
2059 |
> |
* SortedMap m = Collections.synchronizedSortedMap(new TreeMap()); |
2060 |
|
* SortedMap m2 = m.subMap(foo, bar); |
2061 |
|
* ... |
2062 |
|
* Set s2 = m2.keySet(); // Needn't be in synchronized block |
2190 |
|
Class<E> type) { |
2191 |
|
return new CheckedCollection<E>(c, type); |
2192 |
|
} |
2193 |
< |
|
2193 |
> |
|
2194 |
|
/** |
2195 |
|
* @serial include |
2196 |
|
*/ |
2235 |
|
c.clear(); |
2236 |
|
} |
2237 |
|
|
2238 |
< |
public boolean add(E o){ |
2239 |
< |
typeCheck(o); |
2240 |
< |
return c.add(o); |
2238 |
> |
public boolean add(E e){ |
2239 |
> |
typeCheck(e); |
2240 |
> |
return c.add(e); |
2241 |
|
} |
2242 |
|
|
2243 |
|
public boolean addAll(Collection<? extends E> coll) { |
2245 |
|
* Dump coll into an array of the required type. This serves |
2246 |
|
* three purposes: it insulates us from concurrent changes in |
2247 |
|
* the contents of coll, it type-checks all of the elements in |
2248 |
< |
* coll, and it provides all-or-nothing semantics(which we |
2248 |
> |
* coll, and it provides all-or-nothing semantics (which we |
2249 |
|
* wouldn't get if we type-checked each element as we added it). |
2250 |
|
*/ |
2251 |
|
E[] a = null; |
2252 |
|
try { |
2253 |
|
a = coll.toArray(zeroLengthElementArray()); |
2254 |
< |
} catch(ArrayStoreException e) { |
2254 |
> |
} catch (ArrayStoreException e) { |
2255 |
|
throw new ClassCastException(); |
2256 |
|
} |
2257 |
|
|
2264 |
|
private E[] zeroLengthElementArray = null; // Lazily initialized |
2265 |
|
|
2266 |
|
/* |
2267 |
< |
* We don't need locking or volatile, because it's OK if we create |
2267 |
> |
* We don't need locking or volatile, because it's OK if we create |
2268 |
|
* several zeroLengthElementArrays, and they're immutable. |
2269 |
|
*/ |
2270 |
|
E[] zeroLengthElementArray() { |
2299 |
|
public static <E> Set<E> checkedSet(Set<E> s, Class<E> type) { |
2300 |
|
return new CheckedSet<E>(s, type); |
2301 |
|
} |
2302 |
< |
|
2302 |
> |
|
2303 |
|
/** |
2304 |
|
* @serial include |
2305 |
|
*/ |
2435 |
|
E[] a = null; |
2436 |
|
try { |
2437 |
|
a = c.toArray(zeroLengthElementArray()); |
2438 |
< |
} catch(ArrayStoreException e) { |
2438 |
> |
} catch (ArrayStoreException e) { |
2439 |
|
throw new ClassCastException(); |
2440 |
|
} |
2441 |
|
|
2455 |
|
public int previousIndex() { return i.previousIndex(); } |
2456 |
|
public void remove() { i.remove(); } |
2457 |
|
|
2458 |
< |
public void set(E o) { |
2459 |
< |
typeCheck(o); |
2460 |
< |
i.set(o); |
2458 |
> |
public void set(E e) { |
2459 |
> |
typeCheck(e); |
2460 |
> |
i.set(e); |
2461 |
|
} |
2462 |
|
|
2463 |
< |
public void add(E o) { |
2464 |
< |
typeCheck(o); |
2465 |
< |
i.add(o); |
2463 |
> |
public void add(E e) { |
2464 |
> |
typeCheck(e); |
2465 |
> |
i.add(e); |
2466 |
|
} |
2467 |
|
}; |
2468 |
|
} |
2581 |
|
K[] keys = null; |
2582 |
|
try { |
2583 |
|
keys = t.keySet().toArray(zeroLengthKeyArray()); |
2584 |
< |
} catch(ArrayStoreException e) { |
2584 |
> |
} catch (ArrayStoreException e) { |
2585 |
|
throw new ClassCastException(); |
2586 |
|
} |
2587 |
|
V[] values = null; |
2588 |
|
try { |
2589 |
|
values = t.values().toArray(zeroLengthValueArray()); |
2590 |
< |
} catch(ArrayStoreException e) { |
2590 |
> |
} catch (ArrayStoreException e) { |
2591 |
|
throw new ClassCastException(); |
2592 |
|
} |
2593 |
|
|
2603 |
|
private V[] zeroLengthValueArray = null; |
2604 |
|
|
2605 |
|
/* |
2606 |
< |
* We don't need locking or volatile, because it's OK if we create |
2606 |
> |
* We don't need locking or volatile, because it's OK if we create |
2607 |
|
* several zeroLengthValueArrays, and they're immutable. |
2608 |
|
*/ |
2609 |
|
private K[] zeroLengthKeyArray() { |
2657 |
|
s.clear(); |
2658 |
|
} |
2659 |
|
|
2660 |
< |
public boolean add(Map.Entry<K, V> o){ |
2660 |
> |
public boolean add(Map.Entry<K, V> e){ |
2661 |
|
throw new UnsupportedOperationException(); |
2662 |
|
} |
2663 |
|
public boolean addAll(Collection<? extends Map.Entry<K, V>> coll) { |
3059 |
|
|
3060 |
|
final private E element; |
3061 |
|
|
3062 |
< |
SingletonSet(E o) {element = o;} |
3062 |
> |
SingletonSet(E e) {element = e;} |
3063 |
|
|
3064 |
|
public Iterator<E> iterator() { |
3065 |
|
return new Iterator<E>() { |
3167 |
|
|
3168 |
|
public Set<Map.Entry<K,V>> entrySet() { |
3169 |
|
if (entrySet==null) |
3170 |
< |
entrySet = singleton((Map.Entry<K,V>)new ImmutableEntry<K,V>(k, v)); |
3170 |
> |
entrySet = Collections.<Map.Entry<K,V>>singleton( |
3171 |
> |
new SimpleImmutableEntry<K,V>(k, v)); |
3172 |
|
return entrySet; |
3173 |
|
} |
3174 |
|
|
3178 |
|
return values; |
3179 |
|
} |
3180 |
|
|
3181 |
– |
private static class ImmutableEntry<K,V> |
3182 |
– |
implements Map.Entry<K,V> { |
3183 |
– |
final K k; |
3184 |
– |
final V v; |
3185 |
– |
|
3186 |
– |
ImmutableEntry(K key, V value) { |
3187 |
– |
k = key; |
3188 |
– |
v = value; |
3189 |
– |
} |
3190 |
– |
|
3191 |
– |
public K getKey() {return k;} |
3192 |
– |
|
3193 |
– |
public V getValue() {return v;} |
3194 |
– |
|
3195 |
– |
public V setValue(V value) { |
3196 |
– |
throw new UnsupportedOperationException(); |
3197 |
– |
} |
3198 |
– |
|
3199 |
– |
public boolean equals(Object o) { |
3200 |
– |
if (!(o instanceof Map.Entry)) |
3201 |
– |
return false; |
3202 |
– |
Map.Entry e = (Map.Entry)o; |
3203 |
– |
return eq(e.getKey(), k) && eq(e.getValue(), v); |
3204 |
– |
} |
3205 |
– |
|
3206 |
– |
public int hashCode() { |
3207 |
– |
return ((k==null ? 0 : k.hashCode()) ^ |
3208 |
– |
(v==null ? 0 : v.hashCode())); |
3209 |
– |
} |
3210 |
– |
|
3211 |
– |
public String toString() { |
3212 |
– |
return k+"="+v; |
3213 |
– |
} |
3214 |
– |
} |
3181 |
|
} |
3182 |
|
|
3183 |
|
/** |
3211 |
|
int n; |
3212 |
|
E element; |
3213 |
|
|
3214 |
< |
CopiesList(int n, E o) { |
3214 |
> |
CopiesList(int n, E e) { |
3215 |
|
if (n < 0) |
3216 |
|
throw new IllegalArgumentException("List length = " + n); |
3217 |
|
this.n = n; |
3218 |
< |
element = o; |
3218 |
> |
element = e; |
3219 |
|
} |
3220 |
|
|
3221 |
|
public int size() { |
3290 |
|
public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) { |
3291 |
|
if (cmp == null) |
3292 |
|
return new ReverseComparator(); // Unchecked warning!! |
3293 |
< |
|
3293 |
> |
|
3294 |
|
return new ReverseComparator2<T>(cmp); |
3295 |
|
} |
3296 |
< |
|
3296 |
> |
|
3297 |
|
/** |
3298 |
|
* @serial include |
3299 |
|
*/ |
3301 |
|
Serializable |
3302 |
|
{ |
3303 |
|
private static final long serialVersionUID = 4374092139857L; |
3304 |
< |
|
3304 |
> |
|
3305 |
|
/** |
3306 |
|
* The comparator specified in the static factory. This will never |
3307 |
|
* be null, as the static factory returns a ReverseComparator |
3310 |
|
* @serial |
3311 |
|
*/ |
3312 |
|
private Comparator<T> cmp; |
3313 |
< |
|
3313 |
> |
|
3314 |
|
ReverseComparator2(Comparator<T> cmp) { |
3315 |
|
assert cmp != null; |
3316 |
|
this.cmp = cmp; |
3317 |
|
} |
3318 |
< |
|
3318 |
> |
|
3319 |
|
public int compare(T t1, T t2) { |
3320 |
|
return cmp.compare(t2, t1); |
3321 |
|
} |
3435 |
|
c1 = c2; |
3436 |
|
c2 = tmp; |
3437 |
|
} |
3438 |
< |
|
3438 |
> |
|
3439 |
|
for (Object e : c1) |
3440 |
|
if (c2.contains(e)) |
3441 |
|
return false; |
3459 |
|
* @param a the elements to insert into <tt>c</tt> |
3460 |
|
* @return <tt>true</tt> if the collection changed as a result of the call |
3461 |
|
* @throws UnsupportedOperationException if <tt>c</tt> does not support |
3462 |
< |
* the <tt>add</tt> method |
3462 |
> |
* the <tt>add</tt> operation. |
3463 |
|
* @throws NullPointerException if <tt>elements</tt> contains one or more |
3464 |
< |
* null values and <tt>c</tt> does not support null elements, or |
3464 |
> |
* null values and <tt>c</tt> does not permit null elements, or |
3465 |
|
* if <tt>c</tt> or <tt>elements</tt> are <tt>null</tt> |
3466 |
< |
* @throws IllegalArgumentException if some aspect of a value in |
3466 |
> |
* @throws IllegalArgumentException if some property of a value in |
3467 |
|
* <tt>elements</tt> prevents it from being added to <tt>c</tt> |
3468 |
|
* @see Collection#addAll(Collection) |
3469 |
|
* @since 1.5 |
3565 |
|
return new AsLIFOQueue<T>(deque); |
3566 |
|
} |
3567 |
|
|
3568 |
< |
static class AsLIFOQueue<E> extends AbstractQueue<E> |
3568 |
> |
static class AsLIFOQueue<E> extends AbstractQueue<E> |
3569 |
|
implements Queue<E>, Serializable { |
3570 |
|
private final Deque<E> q; |
3571 |
|
AsLIFOQueue(Deque<E> q) { this.q = q; } |
3572 |
< |
public boolean offer(E o) { return q.offerFirst(o); } |
3572 |
> |
public boolean offer(E e) { return q.offerFirst(e); } |
3573 |
|
public E poll() { return q.pollFirst(); } |
3574 |
|
public E remove() { return q.removeFirst(); } |
3575 |
|
public E peek() { return q.peekFirst(); } |
3580 |
|
public Iterator<E> iterator() { return q.iterator(); } |
3581 |
|
public Object[] toArray() { return q.toArray(); } |
3582 |
|
public <T> T[] toArray(T[] a) { return q.toArray(a); } |
3583 |
< |
public boolean add(E o) { return q.offerFirst(o); } |
3583 |
> |
public boolean add(E e) { return q.offerFirst(e); } |
3584 |
|
public boolean remove(Object o) { return q.remove(o); } |
3585 |
|
public void clear() { q.clear(); } |
3586 |
|
} |