# HG changeset patch
# User akhil
# Date 1366647574 25200
# Node ID bb47896553314df93615b1c88a98479f916233bc
# Parent 22a27dfd0510029e3d92ad5b9fec298490daf286
[mq]: collections
diff --git a/src/share/classes/java/util/ArrayList.java b/src/share/classes/java/util/ArrayList.java
--- a/src/share/classes/java/util/ArrayList.java
+++ b/src/share/classes/java/util/ArrayList.java
@@ -25,6 +25,10 @@
package java.util;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+
/**
* Resizable-array implementation of the List interface. Implements
* all optional list operations, and permits all elements, including
@@ -1168,4 +1172,88 @@
throw new ConcurrentModificationException();
}
}
+
+ @Override
+ public void forEach(Consumer super E> action) {
+ Objects.requireNonNull(action);
+ final int expectedModCount = modCount;
+ @SuppressWarnings("unchecked")
+ final E[] elementData = (E[]) this.elementData;
+ final int size = this.size;
+ for (int i=0; modCount == expectedModCount && i < size; i++) {
+ action.accept(elementData[i]);
+ }
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ }
+
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ Objects.requireNonNull(filter);
+ // figure out which elements are to be removed
+ // any exception thrown from the filter predicate at this stage
+ // will leave the collection unmodified
+ int removeCount = 0;
+ final BitSet removeSet = new BitSet(size);
+ final int expectedModCount = modCount;
+ final int size = this.size;
+ for (int i=0; modCount == expectedModCount && i < size; i++) {
+ @SuppressWarnings("unchecked")
+ final E element = (E) elementData[i];
+ if (filter.test(element)) {
+ removeSet.set(i);
+ removeCount++;
+ }
+ }
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+
+ // shift surviving elements left over the spaces left by removed elements
+ final boolean anyToRemove = removeCount > 0;
+ if (anyToRemove) {
+ final int newSize = size - removeCount;
+ for (int i=0, j=0; (i < size) && (j < newSize); i++, j++) {
+ i = removeSet.nextClearBit(i);
+ elementData[j] = elementData[i];
+ }
+ for (int k=newSize; k < size; k++) {
+ elementData[k] = null; // Let gc do its work
+ }
+ this.size = newSize;
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ modCount++;
+ }
+
+ return anyToRemove;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void replaceAll(UnaryOperator operator) {
+ Objects.requireNonNull(operator);
+ final int expectedModCount = modCount;
+ final int size = this.size;
+ for (int i=0; modCount == expectedModCount && i < size; i++) {
+ elementData[i] = operator.apply((E) elementData[i]);
+ }
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ modCount++;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void sort(Comparator super E> c) {
+ final int expectedModCount = modCount;
+ Arrays.sort((E[]) elementData, 0, size, c);
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ modCount++;
+ }
}
diff --git a/src/share/classes/java/util/Collection.java b/src/share/classes/java/util/Collection.java
--- a/src/share/classes/java/util/Collection.java
+++ b/src/share/classes/java/util/Collection.java
@@ -25,6 +25,8 @@
package java.util;
+import java.util.function.Predicate;
+
/**
* The root interface in the collection hierarchy. A collection
* represents a group of objects, known as its elements. Some
@@ -373,6 +375,40 @@
boolean removeAll(Collection> c);
/**
+ * Removes all of the elements of this collection that satisfy the given
+ * predicate. Errors or runtime exceptions thrown by the predicate are
+ * relayed to the caller.
+ *
+ * @implSpec
+ * The default implementation traverses all elements of the collection using
+ * its {@link #iterator}. Each matching element is removed using
+ * {@link Iterator#remove()}. If the collection's iterator does not
+ * support removal then an {@code UnsupportedOperationException} will be
+ * thrown on the first matching element.
+ *
+ * @param filter a predicate which returns {@code true} for elements to be
+ * removed
+ * @return {@code true} if any elements were removed
+ * @throws NullPointerException if the specified filter is null
+ * @throws UnsupportedOperationException if the {@code remove}
+ * method is not supported by this collection's
+ * {@link #iterator}
+ * @since 1.8
+ */
+ default boolean removeIf(Predicate super E> filter) {
+ Objects.requireNonNull(filter);
+ boolean removed = false;
+ final Iterator each = iterator();
+ while (each.hasNext()) {
+ if (filter.test(each.next())) {
+ each.remove();
+ removed = true;
+ }
+ }
+ return removed;
+ }
+
+ /**
* Retains only the elements in this collection that are contained in the
* specified collection (optional operation). In other words, removes from
* this collection all of its elements that are not contained in the
diff --git a/src/share/classes/java/util/Collections.java b/src/share/classes/java/util/Collections.java
--- a/src/share/classes/java/util/Collections.java
+++ b/src/share/classes/java/util/Collections.java
@@ -30,7 +30,10 @@
import java.lang.reflect.Array;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
+import java.util.function.Consumer;
import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
/**
* This class consists exclusively of static methods that operate on or return
@@ -1110,6 +1113,15 @@
public void clear() {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public void forEach(Consumer super E> action) {
+ c.forEach(action);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ throw new UnsupportedOperationException();
+ }
}
/**
@@ -1240,6 +1252,16 @@
public boolean addAll(int index, Collection extends E> c) {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public void replaceAll(UnaryOperator operator) {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public void sort(Comparator super E> c) {
+ throw new UnsupportedOperationException();
+ }
+
public ListIterator listIterator() {return listIterator(0);}
public ListIterator listIterator(final int index) {
@@ -1742,6 +1764,15 @@
private void writeObject(ObjectOutputStream s) throws IOException {
synchronized (mutex) {s.defaultWriteObject();}
}
+
+ @Override
+ public void forEach(Consumer super E> action) {
+ synchronized (mutex) {c.forEach(action);}
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ synchronized (mutex) {return c.removeIf(filter);}
+ }
}
/**
@@ -1996,6 +2027,15 @@
}
}
+ @Override
+ public void replaceAll(UnaryOperator operator) {
+ synchronized (mutex) {list.replaceAll(operator);}
+ }
+ @Override
+ public void sort(Comparator super E> c) {
+ synchronized (mutex) {list.sort(c);}
+ }
+
/**
* SynchronizedRandomAccessList instances are serialized as
* SynchronizedList instances to allow them to be deserialized
@@ -2492,6 +2532,15 @@
// element as we added it)
return c.addAll(checkedCopyOf(coll));
}
+
+ @Override
+ public void forEach(Consumer super E> action) {
+ c.forEach(action);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ return c.removeIf(filter);
+ }
}
/**
@@ -2753,6 +2802,15 @@
public List subList(int fromIndex, int toIndex) {
return new CheckedList<>(list.subList(fromIndex, toIndex), type);
}
+
+ @Override
+ public void replaceAll(UnaryOperator operator) {
+ list.replaceAll(operator);
+ }
+ @Override
+ public void sort(Comparator super E> c) {
+ list.sort(c);
+ }
}
/**
@@ -3416,6 +3474,16 @@
return a;
}
+ @Override
+ public void forEach(Consumer super E> action) {
+ Objects.requireNonNull(action);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ Objects.requireNonNull(filter);
+ return false;
+ }
+
// Preserves singleton property
private Object readResolve() {
return EMPTY_SET;
@@ -3523,6 +3591,16 @@
public E last() {
throw new NoSuchElementException();
}
+
+ @Override
+ public void forEach(Consumer super E> action) {
+ Objects.requireNonNull(action);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ Objects.requireNonNull(filter);
+ return false;
+ }
}
/**
@@ -3592,6 +3670,24 @@
public int hashCode() { return 1; }
+ @Override
+ public void forEach(Consumer super E> action) {
+ Objects.requireNonNull(action);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ Objects.requireNonNull(filter);
+ return false;
+ }
+ @Override
+ public void replaceAll(UnaryOperator operator) {
+ Objects.requireNonNull(operator);
+ }
+ @Override
+ public void sort(Comparator super E> c) {
+ Objects.requireNonNull(c);
+ }
+
// Preserves singleton property
private Object readResolve() {
return EMPTY_LIST;
@@ -3770,6 +3866,15 @@
public int size() {return 1;}
public boolean contains(Object o) {return eq(o, element);}
+
+ @Override
+ public void forEach(Consumer super E> action) {
+ action.accept(element);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ throw new UnsupportedOperationException();
+ }
}
/**
@@ -3810,6 +3915,22 @@
throw new IndexOutOfBoundsException("Index: "+index+", Size: 1");
return element;
}
+
+ @Override
+ public void forEach(Consumer super E> action) {
+ action.accept(element);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public void replaceAll(UnaryOperator operator) {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public void sort(Comparator super E> c) {
+ }
}
/**
@@ -4408,6 +4529,15 @@
public boolean retainAll(Collection> c) {return s.retainAll(c);}
// addAll is the only inherited implementation
+ @Override
+ public void forEach(Consumer super E> action) {
+ s.forEach(action);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ return s.removeIf(filter);
+ }
+
private static final long serialVersionUID = 2454657854757543876L;
private void readObject(java.io.ObjectInputStream stream)
@@ -4466,5 +4596,14 @@
public boolean removeAll(Collection> c) {return q.removeAll(c);}
public boolean retainAll(Collection> c) {return q.retainAll(c);}
// We use inherited addAll; forwarding addAll would be wrong
+
+ @Override
+ public void forEach(Consumer super E> action) {
+ q.forEach(action);
+ }
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ return q.removeIf(filter);
+ }
}
}
diff --git a/src/share/classes/java/util/List.java b/src/share/classes/java/util/List.java
--- a/src/share/classes/java/util/List.java
+++ b/src/share/classes/java/util/List.java
@@ -25,6 +25,8 @@
package java.util;
+import java.util.function.UnaryOperator;
+
/**
* An ordered collection (also known as a sequence). The user of this
* interface has precise control over where in the list each element is
@@ -375,6 +377,64 @@
boolean retainAll(Collection> c);
/**
+ * Replaces each element of this list with the result of applying the
+ * operator to that element. Errors or runtime exceptions thrown by
+ * the operator are relayed to the caller.
+ *
+ * @implSpec
+ * The default implementation is equivalent to, for this {@code list}:
+ *
+ * final ListIterator li = list.listIterator();
+ * while (li.hasNext()) {
+ * li.set(operator.apply(li.next()));
+ * }
+ *
+ * If the list's list-iterator does not support the {@code set} operation
+ * then an {@code UnsupportedOperationException} will be thrown when
+ * replacing the first element.
+ *
+ * @param operator the operator to apply to each element
+ * @throws UnsupportedOperationException if the {@code set}
+ * operation is not supported by this list
+ * @throws NullPointerException if the specified operator is null or
+ * if the element is replaced with a null value and this list
+ * does not permit null elements
+ * (optional)
+ * @since 1.8
+ */
+ default void replaceAll(UnaryOperator operator) {
+ Objects.requireNonNull(operator);
+ final ListIterator li = this.listIterator();
+ while (li.hasNext()) {
+ li.set(operator.apply(li.next()));
+ }
+ }
+
+ /**
+ * Sorts this list using the supplied {@code Comparator} to compare elements.
+ *
+ * @implSpec
+ * The default implementation is equivalent to, for this {@code list}:
+ *
Collections.sort(list, c)
+ *
+ * @param c the {@code Comparator} used to compare list elements.
+ * A {@code null} value indicates that the elements'
+ * {@linkplain Comparable natural ordering} should be used
+ * @throws ClassCastException if the list contains elements that are not
+ * mutually comparable using the specified comparator
+ * @throws UnsupportedOperationException if the list's list-iterator does
+ * not support the {@code set} operation
+ * @throws IllegalArgumentException
+ * (optional)
+ * if the comparator is found to violate the {@link Comparator}
+ * contract
+ * @since 1.8
+ */
+ default void sort(Comparator super E> c) {
+ Collections.sort(this, c);
+ }
+
+ /**
* Removes all of the elements from this list (optional operation).
* The list will be empty after this call returns.
*
diff --git a/src/share/classes/java/util/Vector.java b/src/share/classes/java/util/Vector.java
--- a/src/share/classes/java/util/Vector.java
+++ b/src/share/classes/java/util/Vector.java
@@ -25,6 +25,10 @@
package java.util;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+
/**
* The {@code Vector} class implements a growable array of
* objects. Like an array, it contains components that can be
@@ -1209,4 +1213,89 @@
lastRet = -1;
}
}
+
+ @Override
+ public synchronized void forEach(Consumer super E> action) {
+ Objects.requireNonNull(action);
+ final int expectedModCount = modCount;
+ @SuppressWarnings("unchecked")
+ final E[] elementData = (E[]) this.elementData;
+ final int elementCount = this.elementCount;
+ for (int i=0; modCount == expectedModCount && i < elementCount; i++) {
+ action.accept(elementData[i]);
+ }
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public synchronized boolean removeIf(Predicate super E> filter) {
+ Objects.requireNonNull(filter);
+ // figure out which elements are to be removed
+ // any exception thrown from the filter predicate at this stage
+ // will leave the collection unmodified
+ int removeCount = 0;
+ final int size = elementCount;
+ final BitSet removeSet = new BitSet(size);
+ final int expectedModCount = modCount;
+ for (int i=0; modCount == expectedModCount && i < size; i++) {
+ @SuppressWarnings("unchecked")
+ final E element = (E) elementData[i];
+ if (filter.test(element)) {
+ removeSet.set(i);
+ removeCount++;
+ }
+ }
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+
+ // shift surviving elements left over the spaces left by removed elements
+ final boolean anyToRemove = removeCount > 0;
+ if (anyToRemove) {
+ final int newSize = size - removeCount;
+ for (int i=0, j=0; (i < size) && (j < newSize); i++, j++) {
+ i = removeSet.nextClearBit(i);
+ elementData[j] = elementData[i];
+ }
+ for (int k=newSize; k < size; k++) {
+ elementData[k] = null; // Let gc do its work
+ }
+ elementCount = newSize;
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ modCount++;
+ }
+
+ return anyToRemove;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public synchronized void replaceAll(UnaryOperator operator) {
+ Objects.requireNonNull(operator);
+ final int expectedModCount = modCount;
+ final int size = elementCount;
+ for (int i=0; modCount == expectedModCount && i < size; i++) {
+ elementData[i] = operator.apply((E) elementData[i]);
+ }
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ modCount++;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public synchronized void sort(Comparator super E> c) {
+ final int expectedModCount = modCount;
+ Arrays.sort((E[]) elementData, 0, elementCount, c);
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ modCount++;
+ }
}
diff --git a/src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
--- a/src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
+++ b/src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
@@ -36,6 +36,9 @@
package java.util.concurrent;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
/**
* A thread-safe variant of {@link java.util.ArrayList} in which all mutative
@@ -1260,9 +1263,58 @@
}
}
+ @Override
+ public void forEach(Consumer super E> action) {
+ @SuppressWarnings("unchecked")
+ final E[] elements = (E[]) l.getArray();
+ checkForComodification();
+ l.forEach(action, elements, offset, offset + size);
+ }
+
+ @Override
+ public void sort(Comparator super E> c) {
+ final ReentrantLock lock = l.lock;
+ lock.lock();
+ try {
+ checkForComodification();
+ l.sort(c, offset, offset + size);
+ expectedArray = l.getArray();
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ Objects.requireNonNull(filter);
+ final ReentrantLock lock = l.lock;
+ lock.lock();
+ try {
+ checkForComodification();
+ final int removeCount =
+ l.removeIf(filter, offset, offset + size);
+ expectedArray = l.getArray();
+ size -= removeCount;
+ return removeCount > 0;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ @Override
+ public void replaceAll(UnaryOperator operator) {
+ final ReentrantLock lock = l.lock;
+ lock.lock();
+ try {
+ checkForComodification();
+ l.replaceAll(operator, offset, offset + size);
+ expectedArray = l.getArray();
+ } finally {
+ lock.unlock();
+ }
+ }
}
-
private static class COWSubListIterator implements ListIterator {
private final ListIterator it;
private final int offset;
@@ -1333,4 +1385,139 @@
throw new Error(e);
}
}
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void forEach(Consumer super E> action) {
+ forEach(action, (E[]) getArray(), 0, size());
+ }
+
+ private void forEach(Consumer super E> action,
+ final E[] elements,
+ final int from, final int to) {
+ Objects.requireNonNull(action);
+ for (int i = from; i < to; i++) {
+ action.accept(elements[i]);
+ }
+ }
+
+ @Override
+ public void sort(Comparator super E> c) {
+ final ReentrantLock lock = this.lock;
+ lock.lock();
+ try {
+ sort(c, 0, size());
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ // must be called with this.lock held
+ @SuppressWarnings("unchecked")
+ private void sort(Comparator super E> c, final int from, final int to) {
+ final E[] elements = (E[]) getArray();
+ final E[] newElements = Arrays.copyOf(elements, elements.length);
+ // only elements [from, to) are sorted
+ Arrays.sort(newElements, from, to, c);
+ setArray(newElements);
+ }
+
+ @Override
+ public boolean removeIf(Predicate super E> filter) {
+ Objects.requireNonNull(filter);
+ final ReentrantLock lock = this.lock;
+ lock.lock();
+ try {
+ return removeIf(filter, 0, size()) > 0;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ // must be called with this.lock held
+ private int removeIf(Predicate super E> filter, final int from, final int to) {
+ Objects.requireNonNull(filter);
+ final ReentrantLock lock = this.lock;
+ lock.lock();
+ try {
+ @SuppressWarnings("unchecked")
+ final E[] elements = (E[]) getArray();
+
+ // figure out which elements are to be removed
+ // any exception thrown from the filter predicate at this stage
+ // will leave the collection unmodified
+ int removeCount = 0;
+ final int range = to - from;
+ final BitSet removeSet = new BitSet(range);
+ for (int i = 0; i < range; i++) {
+ final E element = elements[from + i];
+ if (filter.test(element)) {
+ // removeSet is zero-based to keep its size small
+ removeSet.set(i);
+ removeCount++;
+ }
+ }
+
+ // copy surviving elements into a new array
+ if (removeCount > 0) {
+ final int newSize = elements.length - removeCount;
+ final int newRange = newSize - from;
+ @SuppressWarnings("unchecked")
+ final E[] newElements = (E[]) new Object[newSize];
+ // copy elements before [from, to) unmodified
+ for (int i = 0; i < from; i++) {
+ newElements[i] = elements[i];
+ }
+ // elements [from, to) are subject to removal
+ int j = 0;
+ for (int i = 0; (i < range) && (j < newRange); i++) {
+ i = removeSet.nextClearBit(i);
+ if (i >= range) {
+ break;
+ }
+ newElements[from + (j++)] = elements[from + i];
+ }
+ // copy any remaining elements beyond [from, to)
+ j += from;
+ for (int i = to; (i < elements.length) && (j < newSize); i++) {
+ newElements[j++] = elements[i];
+ }
+ setArray(newElements);
+ }
+
+ return removeCount;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ @Override
+ public void replaceAll(UnaryOperator operator) {
+ Objects.requireNonNull(operator);
+ final ReentrantLock lock = this.lock;
+ lock.lock();
+ try {
+ replaceAll(operator, 0, size());
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ // must be called with this.lock held
+ @SuppressWarnings("unchecked")
+ private void replaceAll(UnaryOperator operator, final int from, final int to) {
+ final E[] elements = (E[]) getArray();
+ final E[] newElements = (E[]) new Object[elements.length];
+ for (int i = 0; i < from; i++) {
+ newElements[i] = elements[i];
+ }
+ // the operator is only applied to elements [from, to)
+ for (int i = from; i < to; i++) {
+ newElements[i] = operator.apply(elements[i]);
+ }
+ for (int i = to; i < elements.length; i++) {
+ newElements[i] = elements[i];
+ }
+ setArray(newElements);
+ }
}
diff --git a/test/java/util/Collection/CollectionDefaults.java b/test/java/util/Collection/CollectionDefaults.java
new file mode 100644
--- /dev/null
+++ b/test/java/util/Collection/CollectionDefaults.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.function.Predicate;
+
+/**
+ * @test
+ * @library testlibrary
+ * @build CollectionAsserts CollectionSupplier
+ * @run testng CollectionDefaults
+ * @summary Unit tests for extension methods on Collection
+ */
+public class CollectionDefaults {
+
+ public static final Predicate pEven = x -> 0 == x % 2;
+ public static final Predicate pOdd = x -> 1 == x % 2;
+
+ private static final String[] SET_CLASSES = {
+ "java.util.HashSet",
+ "java.util.LinkedHashSet",
+ "java.util.TreeSet"
+ };
+
+ private static final int SIZE = 100;
+
+ @DataProvider(name="setProvider", parallel=true)
+ public static Object[][] setCases() {
+ final List