1   package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
2   
3   public class InputRightCurlyAlone {
4   
5       private int a;
6       private static int b;
7       {  a = 2; }  //violation
8       static { b = 3; }  //violation
9   
10      void method1() {
11          Thread t = new Thread() {@Override public void run() {
12              int a; int b;} //violation
13          };
14      }
15  
16      void method2(java.util.HashSet<String> set) {
17          java.util.Map<String, String> map1 = new java.util.LinkedHashMap<String, String>() {{
18              put("Hello", "World");
19              put("first", "second");
20              put("polygene", "lubricants");
21              put("alpha", "betical");}  //violation
22          };
23  
24          java.util.Map<String, String> map2 = new java.util.LinkedHashMap<String, String>() {{
25              put("Hello", "World");
26              put("first", "second");
27              put("polygene", "lubricants");
28              put("alpha", "betical");
29          }}; //NO violation
30      }
31  
32      void method3() {
33          method2(new java.util.HashSet<String>() {{
34              add("XZ13s");
35              add("AB21/X");
36              add("YYLEX");
37              add("AR5E");
38          }});  //violation
39      }
40  
41      int method4(int a) {
42          if (a>2) a*=10; return ++a; }   //violation
43  
44      void method5(int a) {
45          while (a > 5) { a--; }  //violation
46  
47          if (a > 4) { a++; }  //violation
48  
49          do {a--;} while (a > 3);  //violation
50  
51          for (int i = 1; i < 10; i++) { byte b = 10; }  //violation
52  
53          if (a < 2) { --a; } else if (a > 3) { a++; } //2 violations
54  
55          java.util.List<String> list = new java.util.ArrayList<>();
56          list.stream()
57                  .filter(e -> {return !e.isEmpty() && !"null".equals(e);} )
58                  .collect(java.util.stream.Collectors.toList());
59      }
60  
61      class TestClass { private int field; }  //violation
62  
63      class TestClass2 { private int field; };  //violation
64  
65      class TestClass3 {
66          private int field;
67      };  //violation
68  
69      void method6(int a) {
70          java.util.Map<String, String> map3 = new java.util.LinkedHashMap<String, String>() {{
71              put("Hello", "World");
72              put("first", "second");
73              put("polygene", "lubricants");
74          }{}; // violation
75          };
76      }
77  }