1 |
jsr166 |
1.1 |
/* |
2 |
|
|
* Copyright 2005 Sun Microsystems, Inc. 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 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. |
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.*; |
32 |
|
|
import java.util.concurrent.*; |
33 |
|
|
|
34 |
|
|
public class RemoveContains { |
35 |
|
|
static volatile int passed = 0, failed = 0; |
36 |
|
|
|
37 |
|
|
static void fail(String msg) { |
38 |
|
|
failed++; |
39 |
|
|
new AssertionError(msg).printStackTrace(); |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
static void pass() { |
43 |
|
|
passed++; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
static void unexpected(Throwable t) { |
47 |
|
|
failed++; |
48 |
|
|
t.printStackTrace(); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
static void check(boolean condition, String msg) { |
52 |
|
|
if (condition) |
53 |
|
|
passed++; |
54 |
|
|
else |
55 |
|
|
fail(msg); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
static void check(boolean condition) { |
59 |
|
|
check(condition, "Assertion failure"); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
public static void main(String[] args) { |
63 |
|
|
final Comparator<String> firstChar = new Comparator<String>() { |
64 |
|
|
public int compare(String x, String y) { |
65 |
|
|
return x.charAt(0) - y.charAt(0); }}; |
66 |
|
|
|
67 |
|
|
test(new PriorityQueue<String>(10, firstChar)); |
68 |
|
|
test(new PriorityBlockingQueue<String>(10, firstChar)); |
69 |
|
|
test(new ArrayBlockingQueue<String>(10)); |
70 |
|
|
test(new LinkedBlockingQueue<String>(10)); |
71 |
|
|
test(new LinkedBlockingDeque<String>(10)); |
72 |
|
|
test(new LinkedTransferQueue<String>()); |
73 |
|
|
test(new ArrayDeque<String>(10)); |
74 |
|
|
|
75 |
|
|
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
76 |
|
|
if (failed > 0) throw new Error("Some tests failed"); |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
private static void test(Queue<String> q) { |
80 |
|
|
try { |
81 |
|
|
List<String> words = |
82 |
|
|
Arrays.asList("foo", "fee", "fi", "fo", "fum", |
83 |
|
|
"Englishman"); |
84 |
|
|
q.addAll(words); |
85 |
|
|
for (String word : words) |
86 |
|
|
check(q.contains(word)); |
87 |
|
|
check(! q.contains("flurble")); |
88 |
|
|
|
89 |
|
|
check(q.remove("fi")); |
90 |
|
|
for (String word : words) |
91 |
|
|
check(q.contains(word) ^ word.equals("fi")); |
92 |
|
|
|
93 |
|
|
check(! q.remove("fi")); |
94 |
|
|
check(! q.remove("flurble")); |
95 |
|
|
|
96 |
|
|
} catch (Throwable t) { unexpected(t); } |
97 |
|
|
} |
98 |
|
|
} |