ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/PriorityQueue/RemoveContains.java
Revision: 1.6
Committed: Mon Jan 8 03:12:03 2018 UTC (6 years, 3 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +1 -1 lines
Log Message:
organize imports

File Contents

# Content
1 /*
2 * Copyright (c) 2005, 2013, 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
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
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 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 /*
25 * @test
26 * @bug 6207984 6268068
27 * @summary Test contains/remove equator compatibility
28 * @author Martin Buchholz
29 */
30
31 import java.util.ArrayDeque;
32 import java.util.Arrays;
33 import java.util.Comparator;
34 import java.util.List;
35 import java.util.PriorityQueue;
36 import java.util.Queue;
37 import java.util.concurrent.ArrayBlockingQueue;
38 import java.util.concurrent.LinkedBlockingDeque;
39 import java.util.concurrent.LinkedBlockingQueue;
40 import java.util.concurrent.LinkedTransferQueue;
41 import java.util.concurrent.PriorityBlockingQueue;
42
43 public class RemoveContains {
44 static volatile int passed = 0, failed = 0;
45
46 static void fail(String msg) {
47 failed++;
48 new AssertionError(msg).printStackTrace();
49 }
50
51 static void pass() {
52 passed++;
53 }
54
55 static void unexpected(Throwable t) {
56 failed++;
57 t.printStackTrace();
58 }
59
60 static void check(boolean condition, String msg) {
61 if (condition)
62 passed++;
63 else
64 fail(msg);
65 }
66
67 static void check(boolean condition) {
68 check(condition, "Assertion failure");
69 }
70
71 public static void main(String[] args) {
72 final Comparator<String> firstChar = new Comparator<>() {
73 public int compare(String x, String y) {
74 return x.charAt(0) - y.charAt(0); }};
75
76 test(new PriorityQueue<String>(firstChar));
77 test(new PriorityQueue<String>(10, firstChar));
78 test(new PriorityBlockingQueue<String>(10, firstChar));
79 test(new ArrayBlockingQueue<String>(10));
80 test(new LinkedBlockingQueue<String>(10));
81 test(new LinkedBlockingDeque<String>(10));
82 test(new LinkedTransferQueue<String>());
83 test(new ArrayDeque<String>(10));
84
85 System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
86 if (failed > 0) throw new Error("Some tests failed");
87 }
88
89 private static void test(Queue<String> q) {
90 try {
91 List<String> words =
92 Arrays.asList("foo", "fee", "fi", "fo", "fum",
93 "Englishman");
94 q.addAll(words);
95 for (String word : words)
96 check(q.contains(word));
97 check(! q.contains("flurble"));
98
99 check(q.remove("fi"));
100 for (String word : words)
101 check(q.contains(word) ^ word.equals("fi"));
102
103 check(! q.remove("fi"));
104 check(! q.remove("flurble"));
105
106 } catch (Throwable t) { unexpected(t); }
107 }
108 }