View Javadoc
1   package integrationTests.otherControlStructures;
2   
3   public final class SwitchStatements {
4       void switchStatementWithSparseCasesAndDefault(char c) {
5           switch (c) {
6               case 'A':
7                   System.gc();
8                   break;
9               case 'f': {
10                  boolean b = true;
11                  System.gc();
12                  System.runFinalization();
13                  break;
14              }
15              case '\0':
16                  return;
17              default:
18                  throw new IllegalArgumentException();
19          }
20      }
21  
22      void anotherSwitchStatementWithSparseCasesAndDefault(char c) {
23          switch (c) {
24              case 'B':
25                  System.gc();
26                  break;
27              default:
28                  System.runFinalization();
29          }
30      }
31  
32      void switchStatementWithCompactCasesAndDefault(int i) {
33          switch (i) {
34              case 1:
35                  System.gc();
36                  break;
37              case 2: {
38                  boolean b = true;
39                  System.gc();
40                  System.runFinalization();
41                  break;
42              }
43              case 4:
44                  return;
45              default:
46                  throw new IllegalArgumentException();
47          }
48      }
49  
50      void anotherSwitchStatementWithCompactCasesAndDefault(int i) {
51          // @formatter:off
52          switch (i) {
53              case 1: System.gc(); break;
54              default: System.runFinalization();
55          }
56          // @formatter:on
57      }
58  
59      void switchStatementWithSparseCasesAndNoDefault(char c) {
60          switch (c) {
61              case 'A':
62                  System.gc();
63                  break;
64              case 'f':
65                  System.runFinalization();
66                  break;
67          }
68      }
69  
70      boolean switchStatementWithCompactCasesAndNoDefault(int i) {
71          boolean b = true;
72  
73          // @formatter:off
74          switch (i) {
75              case 1: System.gc(); return b;
76              case 2: System.runFinalization(); return b;
77              case 4: b = false;
78          }
79          // @formatter:on
80  
81          return b;
82      }
83  
84      char switchStatementWithExitInAllCases(int i) {
85          switch (i) {
86              case 1:
87                  return 'a';
88              case 2:
89                  return 'b';
90              default:
91                  throw new IllegalArgumentException();
92          }
93      }
94  
95      int switchOnString(String s, boolean b) {
96          switch (s) {
97              case "A":
98                  return 1;
99              default:
100                 return b ? 2 : 3;
101         }
102     }
103 }