@@ -339,8 +340,7 @@
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection super E> c) {
- if (c == null)
- throw new NullPointerException();
+ Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
final ReentrantLock lock = this.lock;
@@ -365,8 +365,7 @@
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection super E> c, int maxElements) {
- if (c == null)
- throw new NullPointerException();
+ Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
if (maxElements <= 0)
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java Fri Feb 03 13:24:59 2017 -0800
@@ -42,6 +42,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.Objects;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.locks.LockSupport;
@@ -75,9 +76,8 @@
* is not guaranteed. However, a queue constructed with fairness set
* to {@code true} grants threads access in FIFO order.
*
- * This class and its iterator implement all of the
- * optional methods of the {@link Collection} and {@link
- * Iterator} interfaces.
+ *
This class and its iterator implement all of the optional
+ * methods of the {@link Collection} and {@link Iterator} interfaces.
*
*
This class is a member of the
*
@@ -1112,15 +1112,12 @@
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection super E> c) {
- if (c == null)
- throw new NullPointerException();
+ Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
int n = 0;
- for (E e; (e = poll()) != null;) {
+ for (E e; (e = poll()) != null; n++)
c.add(e);
- ++n;
- }
return n;
}
@@ -1131,15 +1128,12 @@
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection super E> c, int maxElements) {
- if (c == null)
- throw new NullPointerException();
+ Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
int n = 0;
- for (E e; n < maxElements && (e = poll()) != null;) {
+ for (E e; n < maxElements && (e = poll()) != null; n++)
c.add(e);
- ++n;
- }
return n;
}
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java Fri Feb 03 13:24:59 2017 -0800
@@ -1059,17 +1059,17 @@
static {
try {
SEED = U.objectFieldOffset
- (Thread.class.getDeclaredField("threadLocalRandomSeed"));
+ (Thread.class.getDeclaredField("threadLocalRandomSeed"));
PROBE = U.objectFieldOffset
- (Thread.class.getDeclaredField("threadLocalRandomProbe"));
+ (Thread.class.getDeclaredField("threadLocalRandomProbe"));
SECONDARY = U.objectFieldOffset
- (Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
+ (Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
THREADLOCALS = U.objectFieldOffset
- (Thread.class.getDeclaredField("threadLocals"));
+ (Thread.class.getDeclaredField("threadLocals"));
INHERITABLETHREADLOCALS = U.objectFieldOffset
- (Thread.class.getDeclaredField("inheritableThreadLocals"));
+ (Thread.class.getDeclaredField("inheritableThreadLocals"));
INHERITEDACCESSCONTROLCONTEXT = U.objectFieldOffset
- (Thread.class.getDeclaredField("inheritedAccessControlContext"));
+ (Thread.class.getDeclaredField("inheritedAccessControlContext"));
} catch (ReflectiveOperationException e) {
throw new Error(e);
}
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java Fri Feb 03 13:24:59 2017 -0800
@@ -425,11 +425,11 @@
static {
try {
PARKBLOCKER = U.objectFieldOffset
- (Thread.class.getDeclaredField("parkBlocker"));
+ (Thread.class.getDeclaredField("parkBlocker"));
SECONDARY = U.objectFieldOffset
- (Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
+ (Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
TID = U.objectFieldOffset
- (Thread.class.getDeclaredField("tid"));
+ (Thread.class.getDeclaredField("tid"));
} catch (ReflectiveOperationException e) {
throw new Error(e);
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/AbstractList/CheckForComodification.java
--- a/jdk/test/java/util/AbstractList/CheckForComodification.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/AbstractList/CheckForComodification.java Fri Feb 03 13:24:59 2017 -0800
@@ -35,7 +35,7 @@
public class CheckForComodification {
private static final int LENGTH = 10;
public static void main(String[] args) throws Exception {
- List list = new ArrayList();
+ List list = new ArrayList<>();
for (int i = 0; i < LENGTH; i++)
list.add(i);
try {
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/ArrayList/Bug6533203.java
--- a/jdk/test/java/util/ArrayList/Bug6533203.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/ArrayList/Bug6533203.java Fri Feb 03 13:24:59 2017 -0800
@@ -32,7 +32,7 @@
@SuppressWarnings({"serial","unchecked"})
public class Bug6533203 {
void test(String[] args) throws Throwable {
- final List superstitious = new ArrayList() {
+ final List superstitious = new ArrayList<>() {
public void add(int index, Integer i) {
if (i == 13) throw new Error("unlucky");
else super.add(index, i); }};
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/ArrayList/IteratorMicroBenchmark.java
--- a/jdk/test/java/util/ArrayList/IteratorMicroBenchmark.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/ArrayList/IteratorMicroBenchmark.java Fri Feb 03 13:24:59 2017 -0800
@@ -209,8 +209,8 @@
// iterations, size, warmupSeconds, filter);
final ConcurrentSkipListMap m
- = new ConcurrentSkipListMap();
- final ArrayList al = new ArrayList(size);
+ = new ConcurrentSkipListMap<>();
+ final ArrayList al = new ArrayList<>(size);
// Populate collections with random data
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
@@ -218,16 +218,16 @@
m.put(rnd.nextInt(size), rnd.nextInt(size));
al.add(rnd.nextInt(size));
}
- final Vector v = new Vector(al);
- final ArrayDeque ad = new ArrayDeque(al);
+ final Vector v = new Vector<>(al);
+ final ArrayDeque ad = new ArrayDeque<>(al);
// shuffle ArrayDeque elements so they wrap
for (int i = 0, n = rnd.nextInt(size); i < n; i++)
ad.addLast(ad.removeFirst());
// Also test "short" collections
final int shortSize = 5;
- final Vector sv = new Vector(v.subList(0, shortSize));
- final ArrayList sal = new ArrayList(sv);
+ final Vector sv = new Vector<>(v.subList(0, shortSize));
+ final ArrayList sal = new ArrayList<>(sv);
// Checks for correctness *and* prevents loop optimizations
class Check {
@@ -613,8 +613,7 @@
public void work() throws Throwable {
for (int i = 0; i < iterations; i++) {
int sum = 0;
- List> its
- = new ArrayList>(2);
+ List> its = new ArrayList<>(2);
its.add(v.iterator());
its.add(al.iterator());
for (int k = 0; its.get(k).hasNext(); k = (k == 0) ? 1 : 0)
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/ArrayList/RangeCheckMicroBenchmark.java
--- a/jdk/test/java/util/ArrayList/RangeCheckMicroBenchmark.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/ArrayList/RangeCheckMicroBenchmark.java Fri Feb 03 13:24:59 2017 -0800
@@ -159,7 +159,7 @@
final int size = intArg(args, "size", 1000);
final Pattern filter = patternArg(args, "filter");
- final ArrayList list = new ArrayList();
+ final ArrayList list = new ArrayList<>();
final Random rnd = new Random();
for (int i = 0; i < size; i++)
list.add(rnd.nextInt());
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/Collection/IteratorMicroBenchmark.java
--- a/jdk/test/java/util/Collection/IteratorMicroBenchmark.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/Collection/IteratorMicroBenchmark.java Fri Feb 03 13:24:59 2017 -0800
@@ -255,7 +255,7 @@
// "iterations=%d size=%d, warmup=%1g, filter=\"%s\"%n",
// iterations, size, warmupSeconds, filter);
- final ArrayList al = new ArrayList(size);
+ final ArrayList al = new ArrayList<>(size);
// Populate collections with random data
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
@@ -307,14 +307,14 @@
for (Integer n : x)
sum += n;
check.sum(sum);}}},
- new Job(klazz + " .iterator().forEachRemaining()") {
+ new Job(klazz + " iterator().forEachRemaining()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
x.iterator().forEachRemaining(n -> sum[0] += n);
check.sum(sum[0]);}}},
- new Job(klazz + " .spliterator().tryAdvance()") {
+ new Job(klazz + " spliterator().tryAdvance()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
@@ -322,28 +322,49 @@
Spliterator spliterator = x.spliterator();
do {} while (spliterator.tryAdvance(n -> sum[0] += n));
check.sum(sum[0]);}}},
- new Job(klazz + " .spliterator().forEachRemaining()") {
+ new Job(klazz + " spliterator().forEachRemaining()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
x.spliterator().forEachRemaining(n -> sum[0] += n);
check.sum(sum[0]);}}},
- new Job(klazz + " .removeIf") {
+ new Job(klazz + " removeIf") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
- x.removeIf(n -> { sum[0] += n; return false; });
+ if (x.removeIf(n -> { sum[0] += n; return false; }))
+ throw new AssertionError();
check.sum(sum[0]);}}},
- new Job(klazz + " .forEach") {
+ new Job(klazz + " contains") {
+ public void work() throws Throwable {
+ int[] sum = new int[1];
+ Object y = new Object() {
+ public boolean equals(Object z) {
+ sum[0] += (int) z; return false; }};
+ for (int i = 0; i < iterations; i++) {
+ sum[0] = 0;
+ if (x.contains(y)) throw new AssertionError();
+ check.sum(sum[0]);}}},
+ new Job(klazz + " remove(Object)") {
+ public void work() throws Throwable {
+ int[] sum = new int[1];
+ Object y = new Object() {
+ public boolean equals(Object z) {
+ sum[0] += (int) z; return false; }};
+ for (int i = 0; i < iterations; i++) {
+ sum[0] = 0;
+ if (x.remove(y)) throw new AssertionError();
+ check.sum(sum[0]);}}},
+ new Job(klazz + " forEach") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
x.forEach(n -> sum[0] += n);
check.sum(sum[0]);}}},
- new Job(klazz + " .toArray()") {
+ new Job(klazz + " toArray()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
@@ -351,7 +372,7 @@
for (Object o : x.toArray())
sum[0] += (Integer) o;
check.sum(sum[0]);}}},
- new Job(klazz + " .toArray(a)") {
+ new Job(klazz + " toArray(a)") {
public void work() throws Throwable {
Integer[] a = new Integer[x.size()];
int[] sum = new int[1];
@@ -361,7 +382,7 @@
for (Object o : a)
sum[0] += (Integer) o;
check.sum(sum[0]);}}},
- new Job(klazz + " .toArray(empty)") {
+ new Job(klazz + " toArray(empty)") {
public void work() throws Throwable {
Integer[] empty = new Integer[0];
int[] sum = new int[1];
@@ -370,12 +391,12 @@
for (Integer o : x.toArray(empty))
sum[0] += o;
check.sum(sum[0]);}}},
- new Job(klazz + " .stream().collect") {
+ new Job(klazz + " stream().collect") {
public void work() throws Throwable {
for (int i = 0; i < iterations; i++) {
check.sum(x.stream()
.collect(summingInt(e -> e)));}}},
- new Job(klazz + " .parallelStream().collect") {
+ new Job(klazz + " parallelStream().collect") {
public void work() throws Throwable {
for (int i = 0; i < iterations; i++) {
check.sum(x.parallelStream()
@@ -385,7 +406,7 @@
List dequeJobs(Deque x) {
String klazz = x.getClass().getSimpleName();
return List.of(
- new Job(klazz + " .descendingIterator() loop") {
+ new Job(klazz + " descendingIterator() loop") {
public void work() throws Throwable {
for (int i = 0; i < iterations; i++) {
int sum = 0;
@@ -393,7 +414,7 @@
while (it.hasNext())
sum += it.next();
check.sum(sum);}}},
- new Job(klazz + " .descendingIterator().forEachRemaining()") {
+ new Job(klazz + " descendingIterator().forEachRemaining()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/Collection/MOAT.java
--- a/jdk/test/java/util/Collection/MOAT.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/Collection/MOAT.java Fri Feb 03 13:24:59 2017 -0800
@@ -678,7 +678,7 @@
private static void testQueueAddRemove(final Queue q,
final Integer e) {
- final List originalContents = new ArrayList(q);
+ final List originalContents = new ArrayList<>(q);
final boolean isEmpty = q.isEmpty();
final boolean isList = (q instanceof List);
final List asList = isList ? (List) q : null;
@@ -1207,8 +1207,7 @@
private static void throwsConsistently(Class extends Throwable> k,
Iterable fs) {
- List> threw
- = new ArrayList>();
+ List> threw = new ArrayList<>();
for (Fun f : fs)
try { f.f(); threw.add(null); }
catch (Throwable t) {
@@ -1224,7 +1223,7 @@
final ConcurrentMap cm = (m instanceof ConcurrentMap)
? (ConcurrentMap) m
: null;
- List fs = new ArrayList();
+ List fs = new ArrayList<>();
fs.add(() -> check(! m.containsKey(null)));
fs.add(() -> equal(m.remove(null), null));
fs.add(() -> equal(m.get(null), null));
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/Collections/BigBinarySearch.java
--- a/jdk/test/java/util/Collections/BigBinarySearch.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/Collections/BigBinarySearch.java Fri Feb 03 13:24:59 2017 -0800
@@ -38,7 +38,7 @@
extends AbstractList
implements RandomAccess
{
- private Map m = new HashMap();
+ private Map m = new HashMap<>();
public Integer get(int i) {
if (i < 0) throw new IndexOutOfBoundsException(""+i);
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/Collections/Disjoint.java
--- a/jdk/test/java/util/Collections/Disjoint.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/Collections/Disjoint.java Fri Feb 03 13:24:59 2017 -0800
@@ -42,7 +42,7 @@
int x = 0;
for (int i = 0; i < N; i++) {
int size = rnd.nextInt(10) + 2;
- List list = new ArrayList(size);
+ List list = new ArrayList<>(size);
for (int j = 1; j < size; j++)
list.add(x++);
list.add(x);
diff -r 60e247b8d9a4 -r f9c6f543c4db jdk/test/java/util/Collections/RacingCollections.java
--- a/jdk/test/java/util/Collections/RacingCollections.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/Collections/RacingCollections.java Fri Feb 03 13:24:59 2017 -0800
@@ -184,8 +184,7 @@
}
private static List