1 |
|
/* |
2 |
< |
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. |
2 |
> |
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. |
3 |
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
|
* This code is free software; you can redistribute it and/or modify it |
16 |
|
* 2 along with this work; if not, write to the Free Software Foundation, |
17 |
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 |
|
* |
19 |
< |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
20 |
< |
* CA 95054 USA or visit www.sun.com if you need additional information or |
21 |
< |
* have any questions. |
19 |
> |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
> |
* or visit www.oracle.com if you need additional information or have any |
21 |
> |
* questions. |
22 |
|
*/ |
23 |
|
|
24 |
|
/* |
28 |
|
* @author Martin Buchholz |
29 |
|
*/ |
30 |
|
|
31 |
< |
import java.util.*; |
31 |
> |
import java.util.Arrays; |
32 |
> |
import java.util.Iterator; |
33 |
> |
import java.util.NoSuchElementException; |
34 |
> |
import java.util.PriorityQueue; |
35 |
> |
import java.util.Queue; |
36 |
|
|
37 |
|
public class ForgetMeNot { |
38 |
|
private static void checkQ(PriorityQueue<Integer> q, Integer...elts) { |
41 |
|
|
42 |
|
private static void noMoreElements(final Iterator<Integer> it) { |
43 |
|
for (int j = 0; j < 2; j++) { |
44 |
< |
THROWS(NoSuchElementException.class, |
41 |
< |
new Fun() { void f() { it.next(); }}); |
44 |
> |
THROWS(NoSuchElementException.class, () -> it.next()); |
45 |
|
check(! it.hasNext()); |
46 |
|
} |
47 |
|
} |
48 |
|
|
49 |
|
private static void removeIsCurrentlyIllegal(final Iterator<Integer> it) { |
50 |
|
for (int j = 0; j < 2; j++) { |
51 |
< |
THROWS(IllegalStateException.class, |
49 |
< |
new Fun() { void f() { it.remove(); }}); |
51 |
> |
THROWS(IllegalStateException.class, () -> it.remove()); |
52 |
|
} |
53 |
|
} |
54 |
|
|
61 |
|
} |
62 |
|
|
63 |
|
private static void realMain(String[] args) throws Throwable { |
64 |
< |
final PriorityQueue<Integer> q = new PriorityQueue<Integer>(); |
64 |
> |
final PriorityQueue<Integer> q = new PriorityQueue<>(); |
65 |
|
Iterator<Integer> it; |
66 |
|
|
67 |
|
//---------------------------------------------------------------- |
148 |
|
try {realMain(args);} catch (Throwable t) {unexpected(t);} |
149 |
|
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
150 |
|
if (failed > 0) throw new AssertionError("Some tests failed");} |
151 |
< |
private static abstract class Fun {abstract void f() throws Throwable;} |
151 |
> |
interface Fun {void f() throws Throwable;} |
152 |
|
static void THROWS(Class<? extends Throwable> k, Fun... fs) { |
153 |
|
for (Fun f : fs) |
154 |
|
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } |