View Javadoc
1   /*
2   UnnecessaryParentheses
3   tokens = (default)EXPR, IDENT, NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG, \
4            STRING_LITERAL, LITERAL_NULL, LITERAL_FALSE, LITERAL_TRUE, ASSIGN, \
5            BAND_ASSIGN, BOR_ASSIGN, BSR_ASSIGN, BXOR_ASSIGN, DIV_ASSIGN, \
6            MINUS_ASSIGN, MOD_ASSIGN, PLUS_ASSIGN, SL_ASSIGN, SR_ASSIGN, STAR_ASSIGN, \
7            LAMBDA, TEXT_BLOCK_LITERAL_BEGIN, LAND, LITERAL_INSTANCEOF, GT, LT, GE, \
8            LE, EQUAL, NOT_EQUAL, UNARY_MINUS, UNARY_PLUS, INC, DEC, LNOT, BNOT, \
9            POST_INC, POST_DEC
10  
11  
12  */
13  
14  package com.puppycrawl.tools.checkstyle.checks.coding.unnecessaryparentheses;
15  
16  import java.util.ArrayList;
17  import java.util.HashMap;
18  import java.util.List;
19  import java.util.Map;
20  
21  public class InputUnnecessaryParenthesesCasts3 {
22      private static final double MDP_MULT = 2.2;
23  
24      public void fooUnnecessaryParentheses(String hexa) {
25          Object b = new Object();
26          int unm = 30;
27          boolean Eval = false;
28          List<Object> siZ = new ArrayList<>();
29          Map<Object, Object> record = new HashMap<>();
30          if (hexa.contains("Z")) {
31              throw new IllegalArgumentException(((char) b) + " is not a hexadecimal digit");
32              // violation above 'Unnecessary parentheses around expression.'
33          }
34          if (hexa.contains("Y")) {
35              throw new IllegalArgumentException((char) b + " is not a hexadecimal digit");
36          }
37  
38          Attrs le = new Attrs();
39          String fileName = "log.txt";
40          setFileLastModified(fileName,
41                  //no violation below until https://github.com/checkstyle/checkstyle/issues/14872
42                  ((long) le.getMTime()) * 1000);
43          setFileLastModified(fileName,
44                  (long) le.getMTime() * 1000);
45  
46          //no violation below until https://github.com/checkstyle/checkstyle/issues/14872
47          if (!Eval && unm > 0 && ((int) (12f * unm - 1)) > unm+20) {}
48          if (!Eval && unm > 0 && (int) (12f * unm - 1) > unm+20) {}
49  
50          //no violation below until https://github.com/checkstyle/checkstyle/issues/14872
51          final long l8 = ((long) record.get(unm)) & 0xffL;
52          final long l9 = (long) record.get(unm) & 0xffL;
53  
54          int maxSize = 21;
55          //no violation below until https://github.com/checkstyle/checkstyle/issues/14872
56          double used = maxSize == 0 ? 0 : 100 * (((double) unm) / maxSize);
57          double used1 = maxSize == 0 ? 0 : 100 * ((double) unm / maxSize);
58  
59          int dX = 90;
60          int dY = 2;
61          //no violation below until https://github.com/checkstyle/checkstyle/issues/14872
62          int stepx = (int) (((double)dX) * MDP_MULT) / dY;
63          int stepy = (int) ((double)dX * MDP_MULT) / dY;
64  
65          Object layerOffset;
66          //no violation below until https://github.com/checkstyle/checkstyle/issues/14872
67          unm += ((int) (Math.sqrt(unm) * 1.5));
68          unm += (int) (Math.sqrt(unm) * 1.5);
69      }
70  
71      public static void setFileLastModified(String fileName, long lastModified) {}
72      public static class Attrs {
73          int getMTime() {
74              return 123;
75          }
76      }
77  }