Skip to content

Commit 9f5df73

Browse files
committed
Add checkstyle to project
1 parent e3a6bab commit 9f5df73

File tree

10 files changed

+215
-62
lines changed

10 files changed

+215
-62
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ before_install:
1414
- tar xvf secrets.tar
1515

1616
script:
17-
- mvn clean install -X -Djarsigner.skip=false
17+
- mvn clean install -X -Djarsigner.skip=false checkstyle:check
1818

1919
after_success:
2020
- mvn test jacoco:report coveralls:report

checkstyle-suppressions.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Copyright 2017 Patrick Favre-Bulle
4+
~
5+
~ Licensed to the Apache Software Foundation (ASF) under one
6+
~ or more contributor license agreements. See the NOTICE file
7+
~ distributed with this work for additional information
8+
~ regarding copyright ownership. The ASF licenses this file
9+
~ to you under the Apache License, Version 2.0 (the
10+
~ "License"); you may not use this file except in compliance
11+
~ with the License. You may obtain a copy of the License at
12+
~
13+
~ http://www.apache.org/licenses/LICENSE-2.0
14+
~
15+
~ Unless required by applicable law or agreed to in writing,
16+
~ software distributed under the License is distributed on an
17+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18+
~ KIND, either express or implied. See the License for the
19+
~ specific language governing permissions and limitations
20+
~ under the License.
21+
-->
22+
23+
<!DOCTYPE suppressions PUBLIC
24+
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
25+
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
26+
27+
<suppressions>
28+
<suppress checks="FileLength"
29+
files="Bytes.java"
30+
lines="0-3000"/>
31+
</suppressions>

checkstyle.xml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
~ Copyright 2017 Patrick Favre-Bulle
4+
~
5+
~ Licensed to the Apache Software Foundation (ASF) under one
6+
~ or more contributor license agreements. See the NOTICE file
7+
~ distributed with this work for additional information
8+
~ regarding copyright ownership. The ASF licenses this file
9+
~ to you under the Apache License, Version 2.0 (the
10+
~ "License"); you may not use this file except in compliance
11+
~ with the License. You may obtain a copy of the License at
12+
~
13+
~ http://www.apache.org/licenses/LICENSE-2.0
14+
~
15+
~ Unless required by applicable law or agreed to in writing,
16+
~ software distributed under the License is distributed on an
17+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18+
~ KIND, either express or implied. See the License for the
19+
~ specific language governing permissions and limitations
20+
~ under the License.
21+
-->
22+
23+
<!DOCTYPE module PUBLIC
24+
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
25+
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
26+
27+
<module name="Checker">
28+
<module name="NewlineAtEndOfFile"/> <!-- force newline, important for git merge and POSIX compatibility: http://checkstyle.sourceforge.net/config_misc.html#NewlineAtEndOfFile -->
29+
<module name="FileTabCharacter"/> <!-- e.g. disallow tab character outside of strings -->
30+
<module name="UniqueProperties"><!-- must not have duplicate properties in .properties files: http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties -->
31+
<property name="fileExtensions" value="properties"/>
32+
</module>
33+
34+
<module name="FileLength"><!-- max line length for single file: http://checkstyle.sourceforge.net/config_sizes.html#FileLength -->
35+
<property name="max" value="1500"/>
36+
</module>
37+
38+
<module name="TreeWalker">
39+
<module name="SuppressionCommentFilter"/> <!-- use //CHECKSTYLE:OFF (...) //CHECKSTYLE:ON to disable checkstyle: http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter -->
40+
41+
<!-- Annotations -->
42+
<module name="MissingDeprecated"> <!-- if @deprecated and javadoc is there, must be explained in javadoc: http://checkstyle.sourceforge.net/config_annotation.html#MissingDeprecated -->
43+
<property name="skipNoJavadoc" value="true"/>
44+
</module>
45+
<module name="MissingOverride"/> <!-- if has @inheritDoc in javadoc must have @Override http://checkstyle.sourceforge.net/config_annotation.html#MissingOverride -->
46+
<module name="PackageAnnotation"/> <!-- must only be in package-info: http://checkstyle.sourceforge.net/config_annotation.html#PackageAnnotation -->
47+
48+
<!-- Blocks -->
49+
<module name="AvoidNestedBlocks"/> <!-- fails for useless {...} blocks: http://checkstyle.sourceforge.net/config_blocks.html#AvoidNestedBlocks -->
50+
<module name="EmptyCatchBlock"> <!-- empty catch blocks exception var name must be 'ignored' or must not be empty: http://checkstyle.sourceforge.net/config_blocks.html#EmptyCatchBlock -->
51+
<property name="exceptionVariableName" value="expected|ignore"/>
52+
</module>
53+
54+
<!-- Misc -->
55+
<module name="ArrayTypeStyle"/> <!-- e.g. int[] array is ok int array[] not: http://checkstyle.sourceforge.net/config_misc.html#ArrayTypeStyle -->
56+
<module
57+
name="MutableException"/> <!-- e.g. int[] array is ok int array[] not: http://checkstyle.sourceforge.net/config_misc.html#ArrayTypeStyle -->
58+
<module name="UpperEll"/> <!-- long values must be postfixed with 'L' not 'l': http://checkstyle.sourceforge.net/config_misc.html#UpperEll -->
59+
<module name="Indentation"> <!-- Checks correct indentation of Java code: http://checkstyle.sourceforge.net/config_misc.html#Indentation -->
60+
<property name="basicOffset" value="4"/>
61+
<property name="arrayInitIndent" value="8"/>
62+
<property name="braceAdjustment" value="0"/>
63+
<property name="caseIndent" value="4"/>
64+
<property name="throwsIndent" value="4"/>
65+
<property name="lineWrappingIndentation" value="4"/>
66+
<property name="forceStrictCondition" value="false"/>
67+
</module>
68+
69+
<!-- Modifier -->
70+
<module name="ModifierOrder"/> <!-- Checks that the order of modifiers conforms to the suggestions in the Java Language specification: http://checkstyle.sourceforge.net/config_modifier.html#ModifierOrder -->
71+
<module name="RedundantModifier"> <!-- Checks for redundant modifiers: http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier -->
72+
<property name="tokens"
73+
value="METHOD_DEF, VARIABLE_DEF, INTERFACE_DEF, ANNOTATION_FIELD_DEF, ENUM_DEF, CLASS_DEF"/>
74+
</module>
75+
76+
<!-- Classes -->
77+
<module name="FinalClass"/> <!-- class with only private constructor must be final: http://checkstyle.sourceforge.net/config_design.html#FinalClass -->
78+
<module
79+
name="OneStatementPerLine"/> <!-- you cant write int i=1;int j=2; http://checkstyle.sourceforge.net/config_design.html#OneStatementPerLine -->
80+
<module
81+
name="SimplifyBooleanReturn"/> <!-- directly return boolean doe not check and return http://checkstyle.sourceforge.net/config_design.html#SimplifyBooleanReturn -->
82+
<module
83+
name="StringLiteralEquality"/> <!-- you cant write myString == "this" http://checkstyle.sourceforge.net/config_design.html#StringLiteralEquality -->
84+
<module name="OneTopLevelClass"/> <!-- only one root class per file http://checkstyle.sourceforge.net/config_design.html#OneTopLevelClass -->
85+
<module name="ThrowsCount"> <!-- max 5 throws definitions per method: http://checkstyle.sourceforge.net/config_design.html#ThrowsCount -->
86+
<property name="max" value="5"/>
87+
</module>
88+
<module name="InterfaceIsType"/> <!-- interface must contain methods, should not be used for const only: http://checkstyle.sourceforge.net/config_design.html#InterfaceIsType -->
89+
<module name="OuterTypeFilename"/> <!-- class Foo must be in Foo.java: http://checkstyle.sourceforge.net/config_misc.html#OuterTypeFilename -->
90+
91+
<module name="HideUtilityClassConstructor"/> <!-- utility class constructor must be private: http://checkstyle.sourceforge.net/config_design.html#HideUtilityClassConstructor -->
92+
<module name="VisibilityModifier"> <!-- most members must be private http://checkstyle.sourceforge.net/config_design.html#VisibilityModifier -->
93+
<property name="protectedAllowed" value="true"/>
94+
<property name="packageAllowed" value="true"/>
95+
<property name="allowPublicImmutableFields" value="true"/>
96+
<property name="allowPublicFinalFields" value="true"/>
97+
<property name="publicMemberPattern" value="^TAG$|^CREATOR$"/>
98+
</module>
99+
100+
<!-- Coding -->
101+
<module name="CovariantEquals"/> <!-- if you override equals with different type you must provide equals with same type: http://checkstyle.sourceforge.net/config_coding.html#CovariantEquals -->
102+
<module name="DefaultComesLast"/> <!-- in switch case default must be the last elem: http://checkstyle.sourceforge.net/config_coding.html#DefaultComesLast -->
103+
<module name="EmptyStatement"/> <!-- basically an empty semicolon: http://checkstyle.sourceforge.net/config_coding.html#EmptyStatement -->
104+
<module name="EqualsHashCode"/> <!-- if you implement equals, you must implement hashcode and vice versa: http://checkstyle.sourceforge.net/config_coding.html#EqualsHashCode -->
105+
<module name="NoFinalizer"/> <!-- Verifies there are no finalize() methods defined in a class: http://checkstyle.sourceforge.net/config_coding.html#NoFinalizer -->
106+
<module name="FallThrough"/> <!-- switch fallthrough with statement not allowed http://checkstyle.sourceforge.net/config_coding.html#FallThrough -->
107+
<module name="IllegalInstantiation"/> <!-- Must not use const of certain types (Activity, Fragment): http://checkstyle.sourceforge.net/config_coding.html#IllegalInstantiation -->
108+
109+
<!-- Size Limitiations -->
110+
<module name="LineLength"><!-- max char length per line http://checkstyle.sourceforge.net/config_sizes.html#LineLength -->
111+
<property name="max" value="300"/>
112+
</module>
113+
<module name="MethodLength"><!-- max line length for single method http://checkstyle.sourceforge.net/config_sizes.html#MethodLength -->
114+
<property name="max" value="150"/>
115+
</module>
116+
<module name="AnonInnerLength"><!-- max line length for anon class http://checkstyle.sourceforge.net/config_sizes.html#AnonInnerLength -->
117+
<property name="max" value="85"/>
118+
</module>
119+
<module name="ParameterNumber"><!-- max params for method http://checkstyle.sourceforge.net/config_sizes.html#ParameterNumber -->
120+
<property name="max" value="10"/>
121+
<property name="ignoreOverriddenMethods" value="true"/>
122+
<property name="tokens" value="METHOD_DEF"/>
123+
</module>
124+
125+
<!-- Naming Conventions -->
126+
<!--<module name="ConstantName" /> for possible futer use-->
127+
128+
<!-- Whitespaces -->
129+
<module name="EmptyLineSeparator"> <!-- Checks for correct empty line placements, omit VAR token: http://checkstyle.sourceforge.net/config_whitespace.html#EmptyLineSeparator -->
130+
<property name="allowMultipleEmptyLines" value="false"/>
131+
<property name="tokens"
132+
value="PACKAGE_DEF, IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF"/>
133+
</module>
134+
<module name="SingleSpaceSeparator"/> <!-- Checks if a token is surrounded by whitespace: http://checkstyle.sourceforge.net/config_whitespace.html#SingleSpaceSeparator -->
135+
<module name="GenericWhitespace"/> <!-- Checks whitespaces with Java Generics <>: http://checkstyle.sourceforge.net/config_whitespace.html#GenericWhitespace -->
136+
<module name="WhitespaceAround"> <!-- Checks if a token is surrounded by whitespace: http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround -->
137+
<property name="allowEmptyConstructors" value="true"/>
138+
<property name="allowEmptyMethods" value="true"/>
139+
<property name="allowEmptyTypes" value="true"/>
140+
<property name="allowEmptyLambdas" value="true"/>
141+
<property name="allowEmptyCatches" value="true"/>
142+
</module>
143+
144+
<!-- Imports -->
145+
<module name="RedundantImport"/> <!-- e.g. double import statements: http://checkstyle.sourceforge.net/config_imports.html#RedundantImport -->
146+
<module name="UnusedImports"/> <!-- http://checkstyle.sourceforge.net/config_imports.html#UnusedImports -->
147+
<module name="IllegalImport"/> <!-- checks if import sun.* is used http://checkstyle.sourceforge.net/config_imports.html#IllegalImport -->
148+
</module>
149+
</module>

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@
3737

3838
<build>
3939
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-checkstyle-plugin</artifactId>
43+
<version>2.17</version>
44+
<configuration>
45+
<configLocation>checkstyle.xml</configLocation>
46+
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
47+
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
48+
</configuration>
49+
<dependencies>
50+
<dependency>
51+
<groupId>com.puppycrawl.tools</groupId>
52+
<artifactId>checkstyle</artifactId>
53+
<version>8.4</version>
54+
</dependency>
55+
</dependencies>
56+
</plugin>
4057
<plugin>
4158
<groupId>org.apache.maven.plugins</groupId>
4259
<artifactId>maven-compiler-plugin</artifactId>

src/main/java/at/favre/lib/bytes/AbstractBytes.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/main/java/at/favre/lib/bytes/Base64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,4 @@ private static String encode(byte[] in, byte[] map) {
150150
}
151151
return new String(out, StandardCharsets.US_ASCII);
152152
}
153-
}
153+
}

src/main/java/at/favre/lib/bytes/Bytes.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
* </pre>
5858
*/
5959
@SuppressWarnings("WeakerAccess")
60-
public class Bytes implements Comparable<Bytes>, AbstractBytes, Serializable, Iterable<Byte> {
60+
public class Bytes implements Comparable<Bytes>, Serializable, Iterable<Byte> {
6161

6262
/* FACTORY ***************************************************************************************************/
6363

@@ -886,7 +886,6 @@ public ByteOrder byteOrder() {
886886
*
887887
* @return true if mutable, ie. transformers will change internal array
888888
*/
889-
@Override
890889
public boolean isMutable() {
891890
return false;
892891
}
@@ -896,7 +895,6 @@ public boolean isMutable() {
896895
*
897896
* @return true if read only
898897
*/
899-
@Override
900898
public boolean isReadOnly() {
901899
return false;
902900
}

src/main/java/at/favre/lib/bytes/BytesTransformer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ public byte[] transform(byte[] currentArray, boolean inPlace) {
7676

7777
for (int i = 0; i < currentArray.length; i++) {
7878
switch (mode) {
79-
default:
80-
case OR:
81-
out[i] = (byte) (currentArray[i] | secondArray[i]);
82-
break;
8379
case AND:
8480
out[i] = (byte) (currentArray[i] & secondArray[i]);
8581
break;
8682
case XOR:
8783
out[i] = (byte) (currentArray[i] ^ secondArray[i]);
8884
break;
85+
default:
86+
case OR:
87+
out[i] = (byte) (currentArray[i] | secondArray[i]);
88+
break;
8989
}
9090
}
9191

@@ -146,11 +146,11 @@ public byte[] transform(byte[] currentArray, boolean inPlace) {
146146
byte[] out = inPlace ? currentArray : Bytes.from(currentArray).array();
147147

148148
switch (type) {
149+
case RIGHT_SHIFT:
150+
return Util.shiftRight(out, shiftCount);
149151
default:
150152
case LEFT_SHIFT:
151153
return Util.shiftLeft(out, shiftCount);
152-
case RIGHT_SHIFT:
153-
return Util.shiftRight(out, shiftCount);
154154
}
155155
}
156156

@@ -326,7 +326,7 @@ public boolean supportInPlaceTransformation() {
326326
* Converts to hash
327327
*/
328328
class MessageDigestTransformer implements BytesTransformer {
329-
final static String ALGORITHM_SHA_256 = "SHA-256";
329+
static final String ALGORITHM_SHA_256 = "SHA-256";
330330

331331
private final MessageDigest messageDigest;
332332

src/main/java/at/favre/lib/bytes/BytesTransformers.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static BytesTransformer decompressGzip() {
112112
/**
113113
* Shuffles the internal byte array
114114
*/
115-
public final static class ShuffleTransformer implements BytesTransformer {
115+
public static final class ShuffleTransformer implements BytesTransformer {
116116
private final Random random;
117117

118118
ShuffleTransformer(Random random) {
@@ -136,7 +136,7 @@ public boolean supportInPlaceTransformation() {
136136
/**
137137
* Sorts the internal byte array with given {@link java.util.Comparator}
138138
*/
139-
public final static class SortTransformer implements BytesTransformer {
139+
public static final class SortTransformer implements BytesTransformer {
140140
private final Comparator<Byte> comparator;
141141

142142
SortTransformer() {
@@ -170,7 +170,7 @@ public boolean supportInPlaceTransformation() {
170170
/**
171171
* Adds or converts to arbitrary checksum
172172
*/
173-
public final static class ChecksumTransformer implements BytesTransformer {
173+
public static final class ChecksumTransformer implements BytesTransformer {
174174
public enum Mode {
175175
/**
176176
* Appends checksum to given byte array
@@ -217,7 +217,7 @@ public boolean supportInPlaceTransformation() {
217217
/**
218218
* Byte compression with gzip
219219
*/
220-
public final static class GzipCompressor implements BytesTransformer {
220+
public static final class GzipCompressor implements BytesTransformer {
221221
private final boolean compress;
222222

223223
GzipCompressor(boolean compress) {
@@ -235,7 +235,7 @@ private byte[] decompress(byte[] compressedContent) {
235235
byte[] returnBuffer;
236236
try {
237237
int len;
238-
byte buffer[] = new byte[4 * 1024];
238+
byte[] buffer = new byte[4 * 1024];
239239
gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedContent));
240240

241241
while ((len = gzipInputStream.read(buffer)) > 0) {

src/main/java/at/favre/lib/bytes/BytesValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ public boolean validate(byte[] byteArrayToValidate) {
164164
boolean bool = operator != OR;
165165
for (BytesValidator bytesValidator : validatorList) {
166166
switch (operator) {
167+
case AND:
168+
bool &= bytesValidator.validate(byteArrayToValidate);
169+
break;
167170
default:
168171
case OR:
169172
bool |= bytesValidator.validate(byteArrayToValidate);
170173
break;
171-
case AND:
172-
bool &= bytesValidator.validate(byteArrayToValidate);
173-
break;
174174
}
175175
}
176176
return bool;

0 commit comments

Comments
 (0)