Skip to content

Commit 4ed7d9f

Browse files
Artem LabazinArtem Labazin
authored andcommitted
Refactoring
1 parent 185bc8c commit 4ed7d9f

File tree

8 files changed

+107
-196
lines changed

8 files changed

+107
-196
lines changed

.codestyle/checkstyle.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ limitations under the License.
5252
</module>
5353

5454

55-
<!--http://checkstyle.sourceforge.net/config_sizes.html#FileLength-->
56-
<module name="FileLength">
57-
<property name="max" value="300"/>
58-
</module>
59-
60-
6155
<!--http://checkstyle.sourceforge.net/config_whitespace.html#FileTabCharacter-->
6256
<module name="FileTabCharacter">
6357
<property name="eachLine" value="true"/>
@@ -69,8 +63,11 @@ limitations under the License.
6963
<module name="Translation"/>
7064
<module name="UniqueProperties"/>
7165

66+
<module name="SuppressWarningsFilter" />
67+
7268

7369
<module name="TreeWalker">
70+
<module name="SuppressWarningsHolder" />
7471

7572
<!-- Checks for Javadoc comments. -->
7673
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
@@ -191,7 +188,7 @@ limitations under the License.
191188
</module>
192189
<module name="MethodLength">
193190
<property name="tokens" value="METHOD_DEF"/>
194-
<property name="max" value="30"/>
191+
<property name="max" value="60"/>
195192
<property name="countEmpty" value="false"/>
196193
</module>
197194
<module name="ParameterNumber">
@@ -318,9 +315,6 @@ limitations under the License.
318315
<!-- Checks for common coding problems -->
319316
<!-- See http://checkstyle.sf.net/config_coding.html -->
320317
<module name="CovariantEquals"/>
321-
<module name="DeclarationOrder">
322-
<property name="ignoreConstructors" value="true"/>
323-
</module>
324318
<module name="DefaultComesLast"/>
325319
<module name="EmptyStatement"/>
326320
<module name="EqualsAvoidNull"/>
@@ -359,7 +353,6 @@ limitations under the License.
359353
<module name="SuperClone"/>
360354
<module name="SuperFinalize"/>
361355
<module name="UnnecessaryParentheses"/>
362-
<module name="VariableDeclarationUsageDistance"/>
363356

364357

365358
<!-- Checks for class design -->
@@ -369,7 +362,6 @@ limitations under the License.
369362
</module>
370363
<module name="FinalClass"/>
371364
<module name="HideUtilityClassConstructor"/>
372-
<module name="MutableException"/>
373365
<module name="OneTopLevelClass"/>
374366

375367
<!-- Miscellaneous other checks. -->

.codestyle/findbugs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ limitations under the License.
2323
<Match>
2424
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
2525
</Match>
26+
<Match>
27+
<Bug pattern="BC_UNCONFIRMED_CAST"/>
28+
</Match>
2629
</FindBugsFilter>

.codestyle/pmd.xml

Lines changed: 39 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -23,140 +23,55 @@ limitations under the License.
2323

2424
<description>PMD Rules</description>
2525

26-
<rule ref="rulesets/java/basic.xml" />
27-
<rule ref="rulesets/java/braces.xml" />
28-
<rule ref="rulesets/java/clone.xml" />
29-
<rule ref="rulesets/java/unusedcode.xml"/>
30-
<rule ref="rulesets/java/finalizers.xml" />
31-
32-
33-
<rule ref="rulesets/java/imports.xml">
34-
<!-- Stupid rule... -->
35-
<exclude name="TooManyStaticImports" />
36-
</rule>
37-
38-
<rule ref="rulesets/java/codesize.xml" >
39-
<!-- See the explanation for TooManyMethods.-->
40-
<exclude name="TooManyFields" />
41-
<!-- Design is very hard to measure by numbers like this.-->
42-
<!-- The number and quality of dependencies might be a better indicator, -->
43-
<!-- and that requires a different tool.-->
44-
<exclude name="TooManyMethods" />
45-
<!-- See the explanation for TooManyMethods.-->
46-
<exclude name="ExcessivePublicCount" />
47-
<!-- Needs better understanding and proper configuration-->
48-
<exclude name="StdCyclomaticComplexity" />
49-
<!-- Needs better understanding and proper configuration-->
50-
<exclude name="ModifiedCyclomaticComplexity" />
51-
<!-- See the explanation for TooManyMethods.-->
52-
<exclude name="ExcessiveParameterList" />
53-
<!-- Too abstract rule -->
54-
<exclude name="CyclomaticComplexity" />
55-
</rule>
56-
57-
<rule ref="rulesets/java/design.xml">
58-
<!-- Sometimes important to avoid "DOS attack" but not as a general rule-->
59-
<exclude name="AvoidSynchronizedAtMethodLevel" />
60-
<!-- It's just extra effort to write and read the final keyword-->
61-
<exclude name="ClassWithOnlyPrivateConstructorsShouldBeFinal" />
62-
<!-- Maybe good idea if PMD could exclude null checks from this-->
63-
<exclude name="ConfusingTernary" />
64-
<!-- Statistical analysis is prone to givin false positives. Potential god classes-->
65-
<!-- most probably violate something else, too.-->
66-
<!-- And dependency analysis tools also help here.-->
67-
<exclude name="GodClass" />
68-
<!-- Switch is sometimes very readable-->
69-
<exclude name="TooFewBranchesForASwitchStatement"/>
70-
<!-- A static utility is a static utility even if it masquerades as something-->
71-
<!-- else by using the Singleton pattern-->
72-
<exclude name="UseUtilityClass" />
73-
<!-- This is good advice, but since it's violated so much in this project-->
74-
<!-- and the problem is not big (especially with good syntax colouring),-->
75-
<!-- we'll keep this ignored for now.-->
76-
<exclude name="AvoidReassigningParameters" />
77-
<!-- Good idea almost always, but not quite.-->
78-
<!--<exclude name="ReturnEmptyArrayRatherThanNull" />-->
79-
<!-- Sometimes one step at a time makes clearer code.-->
80-
<!-- Debugging is also easier if the return value is in a variable.-->
81-
<exclude name="UnnecessaryLocalBeforeReturn" />
82-
<!-- There are valid reasons for passing arrays (making it nullable for example)-->
26+
<rule ref="category/java/bestpractices.xml">
8327
<exclude name="UseVarargs" />
84-
<!-- TODO explain what false positives this gives-->
85-
<exclude name="MissingBreakInSwitch" />
86-
<!-- TODO enable when all findings have been fixed-->
87-
<exclude name="UseLocaleWithCaseConversions" />
88-
<!-- It gives a lot of warnings on 'equals' method, fixing would decrease readability-->
89-
<exclude name="SimplifyBooleanReturns"/>
90-
<!--Gives false positive-->
91-
<exclude name="FieldDeclarationsShouldBeAtStartOfClass"/>
92-
<!-- Good rule but in practice to often suppressed -->
93-
<exclude name="PreserveStackTrace"/>
94-
95-
<exclude name="AccessorMethodGeneration"/>
9628
</rule>
97-
98-
<rule ref="rulesets/java/migrating.xml">
99-
<!-- The annotation is not as readable and there is no way to state which-->
100-
<!-- line should throw the exception and with what message-->
101-
<exclude name="JUnitUseExpected" />
102-
<!-- Main code is not junit code-->
103-
<exclude name="JUnit4TestShouldUseTestAnnotation" />
104-
</rule>
105-
106-
<rule ref="rulesets/java/naming.xml">
107-
<!-- Often good to start name with Abstract, but on the other hand this-->
108-
<!-- rule is a bit too much like Hungarian notation and I in interface names.-->
109-
<!-- Who cares if it's abstract or not when you are using it?-->
29+
<rule ref="category/java/codestyle.xml">
11030
<exclude name="AbstractNaming" />
111-
<!-- Opinion, for me a getter is not a command, it's a declarative-->
112-
<!-- data reference-->
113-
<exclude name="AvoidFieldNameMatchingMethodName" />
114-
<!-- Why should generics not be named properly, like all other things-->
115-
<!-- (well, except Windows filesystem roots)?-->
116-
<exclude name="GenericsNaming" />
117-
<!-- It can be long if it's the only way to make it good-->
31+
<exclude name="AtLeastOneConstructor" />
32+
<exclude name="AvoidPrefixingMethodParameters" />
33+
<exclude name="CommentDefaultAccessModifier" />
34+
<exclude name="DefaultPackage" />
35+
<exclude name="FieldDeclarationsShouldBeAtStartOfClass" />
36+
<exclude name="LocalVariableCouldBeFinal" />
11837
<exclude name="LongVariable" />
119-
<!-- It can be short if it's good-->
120-
<exclude name="ShortVariable" />
121-
<!-- TODO explain why.-->
122-
<exclude name="BooleanGetMethodName" />
123-
<!-- It can be short if it's good-->
38+
<exclude name="MethodArgumentCouldBeFinal" />
39+
<exclude name="OnlyOneReturn" />
12440
<exclude name="ShortClassName" />
125-
<!-- It can be short if it's good-->
12641
<exclude name="ShortMethodName" />
42+
<exclude name="ShortVariable" />
43+
<exclude name="TooManyStaticImports" />
44+
<exclude name="UselessParentheses" />
12745
</rule>
128-
129-
<rule ref="rulesets/java/optimizations.xml">
130-
<!-- Too many false hits. Optimization can't be done with static analysis.
131-
Besides, following this may encourage the antipattern of using too broad
132-
scope for stuff: -->
133-
<exclude name="AvoidInstantiatingObjectsInLoops" />
134-
<!-- Good principle but too verbose in practice: -->
135-
<exclude name="MethodArgumentCouldBeFinal" />
136-
<!-- Good principle and maybe sometimes even practical but not in this
137-
project: -->
138-
<exclude name="LocalVariableCouldBeFinal" />
139-
</rule>
140-
141-
<rule ref="rulesets/java/strictexception.xml" >
142-
<!-- NPE communicates very cleary what is happening, it is not-->
143-
<!-- interesting who reports it (jvm or user code)-->
144-
<exclude name="AvoidThrowingNullPointerException" />
145-
<!-- TODO explain why-->
46+
<rule ref="category/java/design.xml">
14647
<exclude name="AvoidCatchingGenericException" />
147-
<!-- TODO explain why-->
148-
<exclude name="AvoidThrowingRawExceptionTypes" />
149-
<!-- One valid case is to catch runtime, throw as such and after that-->
150-
<!-- catch Exception and wrap as runtime.-->
151-
<!-- Without the first all runtimes are unnecessarily wrapped.-->
15248
<exclude name="AvoidRethrowingException" />
153-
<!-- There are case which should throws generic exceptions -->
154-
<exclude name="SignatureDeclareThrowsException" />
49+
<exclude name="AvoidThrowingNullPointerException" />
50+
<exclude name="ExcessiveImports" />
51+
<exclude name="LawOfDemeter" />
52+
<exclude name="LoosePackageCoupling" />
53+
<exclude name="TooManyFields" />
54+
<exclude name="TooManyMethods" />
55+
56+
<!-- remove it -->
57+
<exclude name="NcssCount" />
15558
</rule>
59+
<rule ref="category/java/documentation.xml">
60+
<exclude name="CommentSize" />
15661

157-
<rule ref="rulesets/java/strings.xml" >
158-
<!-- Splitting to multiple lines is sometimes more readable.-->
159-
<!-- Besides, where's the proof that it affects performance?-->
160-
<exclude name="ConsecutiveAppendsShouldReuse" />
62+
<!-- remove it -->
63+
<exclude name="CommentRequired" />
64+
</rule>
65+
<rule ref="category/java/errorprone.xml">
66+
<exclude name="AvoidFieldNameMatchingTypeName" />
67+
<exclude name="AvoidFieldNameMatchingMethodName" />
68+
<exclude name="BeanMembersShouldSerialize" />
69+
<exclude name="DataflowAnomalyAnalysis" />
70+
<exclude name="MissingBreakInSwitch" />
71+
</rule>
72+
<rule ref="category/java/multithreading.xml">
73+
</rule>
74+
<rule ref="category/java/performance.xml">
75+
<exclude name="AvoidUsingShortType" />
16176
</rule>
16277
</ruleset>

pom.xml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ limitations under the License.
111111
<dependency>
112112
<groupId>com.google.code.findbugs</groupId>
113113
<artifactId>annotations</artifactId>
114-
<version>3.0.1u2</version>
114+
<version>3.0.1</version>
115115
<scope>provided</scope>
116116
</dependency>
117117
<dependency>
@@ -130,7 +130,7 @@ limitations under the License.
130130
<dependency>
131131
<groupId>org.assertj</groupId>
132132
<artifactId>assertj-core</artifactId>
133-
<version>3.9.0</version>
133+
<version>3.9.1</version>
134134
<scope>test</scope>
135135
</dependency>
136136
</dependencies>
@@ -154,9 +154,10 @@ limitations under the License.
154154
<plugin>
155155
<groupId>org.apache.maven.plugins</groupId>
156156
<artifactId>maven-javadoc-plugin</artifactId>
157-
<version>2.10.4</version>
157+
<version>3.0.0</version>
158158
<configuration>
159159
<additionalOptions>-Xdoclint:none</additionalOptions>
160+
<additionalparam>-Xdoclint:none</additionalparam>
160161
<breakiterator>true</breakiterator>
161162
<charset>UTF-8</charset>
162163
<docencoding>UTF-8</docencoding>
@@ -180,11 +181,12 @@ limitations under the License.
180181
<plugin>
181182
<groupId>org.apache.maven.plugins</groupId>
182183
<artifactId>maven-surefire-plugin</artifactId>
183-
<version>2.20.1</version>
184+
<version>2.21.0</version>
184185
<configuration>
185186
<runOrder>random</runOrder>
186187
<parallel>methods</parallel>
187-
<threadCount>10</threadCount>
188+
<threadCount>2</threadCount>
189+
<trimStackTrace>false</trimStackTrace>
188190
<includes>
189191
<include>**/*Test.java</include>
190192
</includes>
@@ -197,7 +199,7 @@ limitations under the License.
197199
<plugin>
198200
<groupId>org.apache.maven.plugins</groupId>
199201
<artifactId>maven-failsafe-plugin</artifactId>
200-
<version>2.20.1</version>
202+
<version>2.21.0</version>
201203
<configuration>
202204
<includes>
203205
<include>**/*IntegrationTest.java</include>
@@ -240,11 +242,14 @@ limitations under the License.
240242
<plugin>
241243
<groupId>org.apache.maven.plugins</groupId>
242244
<artifactId>maven-pmd-plugin</artifactId>
243-
<version>3.8</version>
245+
<version>3.9.0</version>
244246
<configuration>
245247
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
246248
<targetJdk>${maven.compiler.source}</targetJdk>
247249
<verbose>true</verbose>
250+
<failOnViolation>true</failOnViolation>
251+
<printFailingErrors>true</printFailingErrors>
252+
<analysisCache>true</analysisCache>
248253
<linkXRef>false</linkXRef>
249254
<rulesets>
250255
<ruleset>${project.basedir}/.codestyle/pmd.xml</ruleset>
@@ -268,7 +273,7 @@ limitations under the License.
268273
<dependency>
269274
<groupId>com.puppycrawl.tools</groupId>
270275
<artifactId>checkstyle</artifactId>
271-
<version>8.7</version>
276+
<version>8.8</version>
272277
</dependency>
273278
</dependencies>
274279
<executions>
@@ -284,8 +289,8 @@ limitations under the License.
284289
<failsOnError>true</failsOnError>
285290
<failOnViolation>true</failOnViolation>
286291
<linkXRef>false</linkXRef>
287-
<includeTestSourceDirectory>true</includeTestSourceDirectory>
288292
<propertyExpansion>codestyleFolder=${project.basedir}/.codestyle</propertyExpansion>
293+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
289294
</configuration>
290295
</execution>
291296
</executions>

src/main/java/io/appulse/logging/AnsiColors.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@
3636

3737
import java.awt.Color;
3838
import java.awt.color.ColorSpace;
39-
import java.util.Collections;
40-
import java.util.LinkedHashMap;
4139
import java.util.Map;
4240
import java.util.Map.Entry;
41+
import java.util.concurrent.ConcurrentHashMap;
4342

4443
import lombok.NonNull;
4544

@@ -54,25 +53,23 @@ public final class AnsiColors {
5453
private static final Map<AnsiColor, LabColor> ANSI_COLOR_MAP;
5554

5655
static {
57-
Map<AnsiColor, LabColor> colorMap = new LinkedHashMap<>();
58-
colorMap.put(BLACK, new LabColor(0x000000));
59-
colorMap.put(RED, new LabColor(0xAA0000));
60-
colorMap.put(GREEN, new LabColor(0x00AA00));
61-
colorMap.put(YELLOW, new LabColor(0xAA5500));
62-
colorMap.put(BLUE, new LabColor(0x0000AA));
63-
colorMap.put(MAGENTA, new LabColor(0xAA00AA));
64-
colorMap.put(CYAN, new LabColor(0x00AAAA));
65-
colorMap.put(WHITE, new LabColor(0xAAAAAA));
66-
colorMap.put(BRIGHT_BLACK, new LabColor(0x555555));
67-
colorMap.put(BRIGHT_RED, new LabColor(0xFF5555));
68-
colorMap.put(BRIGHT_GREEN, new LabColor(0x55FF00));
69-
colorMap.put(BRIGHT_YELLOW, new LabColor(0xFFFF55));
70-
colorMap.put(BRIGHT_BLUE, new LabColor(0x5555FF));
71-
colorMap.put(BRIGHT_MAGENTA, new LabColor(0xFF55FF));
72-
colorMap.put(BRIGHT_CYAN, new LabColor(0x55FFFF));
73-
colorMap.put(BRIGHT_WHITE, new LabColor(0xFFFFFF));
74-
75-
ANSI_COLOR_MAP = Collections.unmodifiableMap(colorMap);
56+
ANSI_COLOR_MAP = new ConcurrentHashMap<>();
57+
ANSI_COLOR_MAP.put(BLACK, new LabColor(0x000000));
58+
ANSI_COLOR_MAP.put(RED, new LabColor(0xAA0000));
59+
ANSI_COLOR_MAP.put(GREEN, new LabColor(0x00AA00));
60+
ANSI_COLOR_MAP.put(YELLOW, new LabColor(0xAA5500));
61+
ANSI_COLOR_MAP.put(BLUE, new LabColor(0x0000AA));
62+
ANSI_COLOR_MAP.put(MAGENTA, new LabColor(0xAA00AA));
63+
ANSI_COLOR_MAP.put(CYAN, new LabColor(0x00AAAA));
64+
ANSI_COLOR_MAP.put(WHITE, new LabColor(0xAAAAAA));
65+
ANSI_COLOR_MAP.put(BRIGHT_BLACK, new LabColor(0x555555));
66+
ANSI_COLOR_MAP.put(BRIGHT_RED, new LabColor(0xFF5555));
67+
ANSI_COLOR_MAP.put(BRIGHT_GREEN, new LabColor(0x55FF00));
68+
ANSI_COLOR_MAP.put(BRIGHT_YELLOW, new LabColor(0xFFFF55));
69+
ANSI_COLOR_MAP.put(BRIGHT_BLUE, new LabColor(0x5555FF));
70+
ANSI_COLOR_MAP.put(BRIGHT_MAGENTA, new LabColor(0xFF55FF));
71+
ANSI_COLOR_MAP.put(BRIGHT_CYAN, new LabColor(0x55FFFF));
72+
ANSI_COLOR_MAP.put(BRIGHT_WHITE, new LabColor(0xFFFFFF));
7673
}
7774

7875
private AnsiColors () {

0 commit comments

Comments
 (0)