2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6377356
|
|
27 |
* @summary Test EnumSet.retainAll
|
|
28 |
* @author Josh Bloch, Martin Buchholz
|
|
29 |
*/
|
|
30 |
|
|
31 |
import java.util.*;
|
|
32 |
|
|
33 |
public class RetainAll {
|
|
34 |
enum RegularA { A0, A2 }
|
|
35 |
enum RegularB { B0, B1 }
|
|
36 |
enum JumboA {
|
|
37 |
A00, A01, A02, A03, A04, A05, A06, A07, A08, A09,
|
|
38 |
A10, A11, A12, A13, A14, A15, A16, A17, A18, A19,
|
|
39 |
A20, A21, A22, A23, A24, A25, A26, A27, A28, A29,
|
|
40 |
A30, A31, A32, A33, A34, A35, A36, A37, A38, A39,
|
|
41 |
A40, A41, A42, A43, A44, A45, A46, A47, A48, A49,
|
|
42 |
A50, A51, A52, A53, A54, A55, A56, A57, A58, A59,
|
|
43 |
A60, A61, A62, A63, A64, A65, A66, A67, A68, A69,
|
|
44 |
}
|
|
45 |
enum JumboB {
|
|
46 |
B00, B01, B02, B03, B04, B05, B06, B07, B08, B09,
|
|
47 |
B10, B11, B12, B13, B14, B15, B16, B17, B18, B19,
|
|
48 |
B20, B21, B22, B23, B24, B25, B26, B27, B28, B29,
|
|
49 |
B30, B31, B32, B33, B34, B35, B36, B37, B38, B39,
|
|
50 |
B40, B41, B42, B43, B44, B45, B46, B47, B48, B49,
|
|
51 |
B50, B51, B52, B53, B54, B55, B56, B57, B58, B59,
|
|
52 |
B60, B61, B62, B63, B64, B65, B66, B67, B68, B69,
|
|
53 |
}
|
|
54 |
|
|
55 |
private static void realMain(String[] args) throws Throwable {
|
|
56 |
Set<RegularA> ras = EnumSet.noneOf(RegularA.class);
|
|
57 |
Set<RegularB> rbs = EnumSet.noneOf(RegularB.class);
|
|
58 |
Set<JumboA> jas = EnumSet.noneOf(JumboA.class);
|
|
59 |
Set<JumboB> jbs = EnumSet.noneOf(JumboB.class);
|
|
60 |
check(ras.getClass().getName().matches(".*Regular.*"));
|
|
61 |
check(jas.getClass().getName().matches(".*Jumbo.*"));
|
|
62 |
check(! ras.retainAll(ras));
|
|
63 |
check(! ras.retainAll(rbs));
|
|
64 |
check(! jas.retainAll(jas));
|
|
65 |
check(! jas.retainAll(jbs));
|
|
66 |
check(! ras.retainAll(jas));
|
|
67 |
check(! jas.retainAll(ras));
|
|
68 |
}
|
|
69 |
|
|
70 |
//--------------------- Infrastructure ---------------------------
|
|
71 |
static volatile int passed = 0, failed = 0;
|
|
72 |
static void pass() {passed++;}
|
|
73 |
static void fail() {failed++; Thread.dumpStack();}
|
|
74 |
static void fail(String msg) {System.out.println(msg); fail();}
|
|
75 |
static void unexpected(Throwable t) {failed++; t.printStackTrace();}
|
|
76 |
static void check(boolean cond) {if (cond) pass(); else fail();}
|
|
77 |
static void equal(Object x, Object y) {
|
|
78 |
if (x == null ? y == null : x.equals(y)) pass();
|
|
79 |
else fail(x + " not equal to " + y);}
|
|
80 |
public static void main(String[] args) throws Throwable {
|
|
81 |
try {realMain(args);} catch (Throwable t) {unexpected(t);}
|
|
82 |
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
|
|
83 |
if (failed > 0) throw new AssertionError("Some tests failed");}
|
|
84 |
}
|