boolean addAll(Collection super T> c, T... elements) {
boolean result = false;
- for (T e : a)
- result |= c.add(e);
+ for (T element : elements)
+ result |= c.add(element);
return result;
}
@@ -3496,25 +3544,26 @@ public class Collections {
* to this method, and no reference to the map is retained, as illustrated
* in the following code fragment:
*
- * Set<Object> weakHashSet = Collections.asSet(
+ * Set<Object> weakHashSet = Collections.newSetFromMap(
* new WeakHashMap<Object, Boolean>());
*
*
* @param map the backing map
* @return the set backed by the map
* @throws IllegalArgumentException if map is not empty
+ * @since 1.6
*/
- public static Set asSet(Map map) {
- return new MapAsSet(map);
+ public static Set newSetFromMap(Map map) {
+ return new SetFromMap(map);
}
- private static class MapAsSet extends AbstractSet
+ private static class SetFromMap extends AbstractSet
implements Set, Serializable
{
private final Map m; // The backing map
private transient Set keySet; // Its keySet
- MapAsSet(Map map) {
+ SetFromMap(Map map) {
if (!map.isEmpty())
throw new IllegalArgumentException("Map is non-empty");
m = map;
@@ -3558,7 +3607,8 @@ public class Collections {
* remove is mapped to pop and so on. This
* view can be useful when you would like to use a method
* requiring a Queue but you need Lifo ordering.
- * @param deque the Deque
+ *
+ * @param deque the deque
* @return the queue
* @since 1.6
*/
@@ -3568,9 +3618,11 @@ public class Collections {
static class AsLIFOQueue extends AbstractQueue
implements Queue, Serializable {
+ private static final long serialVersionUID = 1802017725587941708L;
private final Deque q;
AsLIFOQueue(Deque q) { this.q = q; }
- public boolean offer(E o) { return q.offerFirst(o); }
+ public boolean add(E e) { q.addFirst(e); return true; }
+ public boolean offer(E e) { return q.offerFirst(e); }
public E poll() { return q.pollFirst(); }
public E remove() { return q.removeFirst(); }
public E peek() { return q.peekFirst(); }
@@ -3581,7 +3633,6 @@ public class Collections {
public Iterator iterator() { return q.iterator(); }
public Object[] toArray() { return q.toArray(); }
public T[] toArray(T[] a) { return q.toArray(a); }
- public boolean add(E o) { return q.offerFirst(o); }
public boolean remove(Object o) { return q.remove(o); }
public void clear() { q.clear(); }
}