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