Skip to content

Commit 5fc6d68

Browse files
committed
Cleans up code after running strict inspections in IDEA
1 parent 6046667 commit 5fc6d68

25 files changed

+142
-119
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ Normally, one of our developers should be able to comment on them and fix.
461461

462462
These are the release notes for the Java library for mapcodes.
463463

464+
### 2.4.6
465+
466+
* General cleanup after running stricter IntelliJ inspections profile.
467+
464468
### 2.4.5
465469

466470
* Remove hard reference to `log4j` for production. Left only for unit tests.

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@
7373

7474
<!-- Modules. -->
7575
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
76-
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
76+
<jacoco-maven-plugin.version>0.8.1</jacoco-maven-plugin.version>
7777
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
78-
<maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
78+
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
7979
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
8080
<maven-project-info-reports-plugin.version>2.9</maven-project-info-reports-plugin.version>
81-
<maven-site-plugin.version>3.6</maven-site-plugin.version>
81+
<maven-site-plugin.version>3.7.1</maven-site-plugin.version>
8282
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
83-
<maven-surefire-plugin.version>2.20.1</maven-surefire-plugin.version>
83+
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
8484
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
8585

8686
<!-- libraries. -->
87-
<gson.version>2.8.2</gson.version>
87+
<gson.version>2.8.4</gson.version>
8888
<jsr305.version>3.0.2</jsr305.version>
8989
<junit.version>4.12</junit.version>
9090
<log4j.version>1.2.17</log4j.version>

src/main/java/com/mapcode/Alphabet.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,4 @@ public static Alphabet fromString(@Nonnull final String alphaCode) throws Unknow
101101
throw new UnknownAlphabetException(trimmed);
102102
}
103103
}
104-
105-
/**
106-
* Static consistency check of internal data structures.
107-
*/
108-
static {
109-
int i = 0;
110-
for (final Alphabet alphabet : Alphabet.values()) {
111-
if (Alphabet.values()[i].number != i) {
112-
throw new ExceptionInInitializerError("Incorrect alphabet number: " + alphabet + ".number should be " + i);
113-
}
114-
++i;
115-
}
116-
}
117104
}

src/main/java/com/mapcode/Boundary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* This class handles territory rectangles for mapcodes.
2727
*/
28-
class Boundary {
28+
final class Boundary {
2929
private int latMicroDegMin; // Minimum latitude (in microdegrees). Inclusive.
3030
private int lonMicroDegMin; // Minimum longitude (in microdegrees). Inclusive.
3131
private int latMicroDegMax; // Minimum latitude (in microdegrees). Exclusive.

src/main/java/com/mapcode/CheckArgs.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
*
2929
* This class provides a number of helper methods to check (runtime) arguments.
3030
*/
31-
@SuppressWarnings("OverlyBroadThrowsClause")
32-
class CheckArgs {
31+
final class CheckArgs {
3332

3433
private CheckArgs() {
3534
// Prevent instantiation.

src/main/java/com/mapcode/Common.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
*
2727
* This class contains common data structures and methods used by the Mapcode implementation.
2828
*/
29-
class Common {
29+
@SuppressWarnings("MagicNumber")
30+
final class Common {
3031
private static final Logger LOG = LoggerFactory.getLogger(Common.class);
3132

3233
// TODO: Need better name and explanation.
@@ -76,7 +77,6 @@ private Common() {
7677
// Some of the methods (and tests) take considerably longer with assertions checking, so it's useful
7778
// to have this information in the log file.
7879

79-
//noinspection UnusedAssignment
8080
boolean debug = false;
8181
//noinspection AssertWithSideEffects
8282
assert debug = true;
@@ -90,6 +90,7 @@ private Common() {
9090

9191
// This method returns a divider for longitude (multiplied by 4), for a given latitude.
9292
// TODO: Need better names for minY and maxY.
93+
@SuppressWarnings("ConstantConditions")
9394
static int xDivider(final int latMin, final int latMax) {
9495
assert latMin < latMax;
9596
if (latMin >= 0) {

src/main/java/com/mapcode/Data.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
*
2626
* This class the data class for Mapcode codex items.
2727
*/
28-
class Data {
28+
@SuppressWarnings("MagicNumber")
29+
final class Data {
2930

3031
// TODO: Need explanation what this is and how this is used.
3132
static final char[] ENCODE_CHARS = {

src/main/java/com/mapcode/DataModel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*
3232
* This class contains the module that reads the Mapcode areas into memory and processes them.
3333
*/
34+
@SuppressWarnings("MagicNumber")
3435
class DataModel {
3536
private static final Logger LOG = LoggerFactory.getLogger(DataModel.class);
3637

@@ -81,7 +82,6 @@ private static int readLongLoHi(final int lo, final int mid1, final int mid2, fi
8182
private final int[] index;
8283
private final int[] data;
8384

84-
@SuppressWarnings("StaticNonFinalField")
8585
private static volatile DataModel instance = null;
8686
private static final Object mutex = new Object();
8787

@@ -97,6 +97,7 @@ public static DataModel getInstance() {
9797
return instance;
9898
}
9999

100+
@SuppressWarnings("NestedTryStatement")
100101
DataModel(@Nonnull final String fileName) throws IncorrectDataModelException {
101102
// Read data only once in static initializer.
102103
LOG.info("DataModel: reading regions from file: {}", fileName);

src/main/java/com/mapcode/Decoder.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
*
3131
* This class contains decoder for mapcodes.
3232
*/
33-
class Decoder {
33+
@SuppressWarnings({"MagicNumber", "StringConcatenationMissingWhitespace"})
34+
final class Decoder {
3435
private static final Logger LOG = LoggerFactory.getLogger(Decoder.class);
3536

3637
// Get direct access to the data model singleton.
@@ -225,12 +226,12 @@ static MapcodeZone decodeToMapcodeZone(@Nonnull final String argMapcode,
225226

226227
private static class Unicode2Ascii {
227228

228-
public final char min;
229-
public final char max;
229+
final char min;
230+
final char max;
230231
@Nonnull
231-
public final String convert;
232+
final String convert;
232233

233-
public Unicode2Ascii(final char min, final char max, @Nonnull final String convert) {
234+
Unicode2Ascii(final char min, final char max, @Nonnull final String convert) {
234235
this.min = min;
235236
this.max = max;
236237
this.convert = convert;
@@ -243,7 +244,8 @@ public Unicode2Ascii(final char min, final char max, @Nonnull final String conve
243244
// Special character '?' indicating missing character in alphabet.
244245
private static final char MISSCODE = '?';
245246

246-
private final static char[][] ASCII2LANGUAGE = {
247+
// @formatter:off
248+
@SuppressWarnings("LongLine") private final static char[][] ASCII2LANGUAGE = {
247249
// Character: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9
248250
/* Roman */ {'\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004a', '\u004b', '\u004c', '\u004d', '\u004e', '\u004f', '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005a', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Roman
249251
/* Greek */ {'\u0391', '\u0392', '\u039e', '\u0394', '\u0388', '\u0395', '\u0393', '\u0397', '\u0399', '\u03a0', '\u039a', '\u039b', '\u039c', '\u039d', '\u039f', '\u03a1', '\u0398', '\u03a8', '\u03a3', '\u03a4', '\u0389', '\u03a6', '\u03a9', '\u03a7', '\u03a5', '\u0396', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Greek
@@ -274,8 +276,10 @@ public Unicode2Ascii(final char min, final char max, @Nonnull final String conve
274276
/* Kannada */ {'\u0C92', '\u0C95', '\u0C96', '\u0C97', '\u0C8E', '\u0C99', '\u0C9A', '\u0C9B', '\u0C85', '\u0C9C', '\u0CA0', '\u0CA1', '\u0CA3', '\u0CA4', '\u0C89', '\u0CA6', '\u0CA7', '\u0CA8', '\u0CAA', '\u0CAB', '\u0C87', '\u0CAC', '\u0CAD', '\u0CB0', '\u0CB2', '\u0CB5', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Kannada
275277
/* Gujarati */ {'\u0AB3', '\u0A97', '\u0A9C', '\u0AA1', '\u0A87', '\u0AA6', '\u0AAC', '\u0A95', '\u0A8F', '\u0A9A', '\u0A9F', '\u0AA4', '\u0AAA', '\u0AA0', '\u0A8D', '\u0AB0', '\u0AB5', '\u0A9E', '\u0AAE', '\u0AAB', '\u0A89', '\u0AB7', '\u0AA8', '\u0A9D', '\u0AA2', '\u0AAD', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'} // Gujarati
276278
};
279+
// @formatter:on
277280

278-
private final static Unicode2Ascii[] UNICODE2ASCII = {
281+
// @formatter:off
282+
@SuppressWarnings("LongLine") private final static Unicode2Ascii[] UNICODE2ASCII = {
279283
/* Roman */ new Unicode2Ascii('\u0041', '\u005a', "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), // Roman
280284
/* Greek */ new Unicode2Ascii('\u0388', '\u03a9', "EU???????ABGDFZHQIKLMNCOJP?STYVXRW"), // Greek
281285
/* Cyrillic */ new Unicode2Ascii('\u0410', '\u042f', "AZBGDEFNI?KLMHOJPCTYQXSVW????U?R"), // Cyrillic
@@ -322,6 +326,7 @@ public Unicode2Ascii(final char min, final char max, @Nonnull final String conve
322326
/* Georgian */ new Unicode2Ascii('\u10d0', '\u10ef', "AB?CE?D?UF?GHOJ?KLMINPQRSTVW?XYZ"),
323327
/* Armenian */ new Unicode2Ascii('\u0562', '\u0586', "BCDE??FGHI?J?KLM?N?U?PQ?R??STVWXYZ?OA")
324328
};
329+
// @formatter:on
325330

326331
@Nonnull
327332
private static MapcodeZone decodeGrid(
@@ -981,19 +986,25 @@ private static String convertFromAbjad(@Nonnull final String mapcode) {
981986
} else if (form == 35) {
982987
final int c = ((DECODE_CHARS[(int) s.charAt(2)] * 8) + (DECODE_CHARS[(int) s.charAt(6)] - 18));
983988
if ((c >= 32) && (c < 63)) {
984-
newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c - 32] + s.charAt(4) + '.' + s.charAt(5) + s.charAt(7) + s.charAt(8);
989+
newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c - 32] + s.charAt(4) + '.' + s.charAt(5) + s.charAt(7) +
990+
s.charAt(8);
985991
} else if ((c >= 0) && (c < 31)) {
986-
newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c] + '.' + s.charAt(4) + s.charAt(5) + s.charAt(7) + s.charAt(8);
992+
newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c] + '.' + s.charAt(4) + s.charAt(5) + s.charAt(7) +
993+
s.charAt(8);
987994
}
988995
} else if (form == 45) {
989-
final int c = (DECODE_CHARS[(int) s.charAt(2)] * 100) + (DECODE_CHARS[(int) s.charAt(5)] * 10) + (DECODE_CHARS[(int) s.charAt(8)] - 39);
996+
final int c = (DECODE_CHARS[(int) s.charAt(2)] * 100) + (DECODE_CHARS[(int) s.charAt(5)] * 10) +
997+
(DECODE_CHARS[(int) s.charAt(8)] - 39);
990998
if ((c >= 0) && (c < 961)) {
991-
newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c / 31] + s.charAt(3) + '.' + s.charAt(6) + s.charAt(7) + s.charAt(9) + Data.ENCODE_CHARS[c % 31];
999+
newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c / 31] + s.charAt(3) + '.' + s.charAt(6) + s.charAt(7) +
1000+
s.charAt(9) + Data.ENCODE_CHARS[c % 31];
9921001
}
9931002
} else if (form == 55) {
994-
final int c = (DECODE_CHARS[(int) s.charAt(2)] * 100) + (DECODE_CHARS[(int) s.charAt(6)] * 10) + (DECODE_CHARS[(int) s.charAt(9)] - 39);
1003+
final int c = (DECODE_CHARS[(int) s.charAt(2)] * 100) + (DECODE_CHARS[(int) s.charAt(6)] * 10) +
1004+
(DECODE_CHARS[(int) s.charAt(9)] - 39);
9951005
if ((c >= 0) && (c < 961)) {
996-
newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c / 31] + s.charAt(3) + s.charAt(4) + '.' + s.charAt(7) + s.charAt(8) + s.charAt(10) + Data.ENCODE_CHARS[c % 31];
1006+
newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c / 31] + s.charAt(3) + s.charAt(4) + '.' + s.charAt(7) +
1007+
s.charAt(8) + s.charAt(10) + Data.ENCODE_CHARS[c % 31];
9971008
}
9981009
}
9991010

src/main/java/com/mapcode/Encoder.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
*
3535
* This class contains encoder for mapcodes.
3636
*/
37-
class Encoder {
37+
@SuppressWarnings({"MagicNumber", "StringConcatenationMissingWhitespace"})
38+
final class Encoder {
3839
private static final Logger LOG = LoggerFactory.getLogger(Encoder.class);
3940

4041
// Get direct access to data model singleton.
@@ -130,16 +131,16 @@ private static List<Mapcode> encode(
130131
final Mapcode newResult = new Mapcode(mapcode, encodeTerritory);
131132

132133
// The result should not be stored yet.
133-
if (!results.contains(newResult)) {
134+
if (results.contains(newResult)) {
135+
LOG.error("encode: Duplicate results found, newResult={}, results={} items",
136+
newResult.getCodeWithTerritory(), results.size());
137+
} else {
134138

135139
// Remove existing results (if there was a parent territory).
136140
if (limitToOneResult) {
137141
results.clear();
138142
}
139143
results.add(newResult);
140-
} else {
141-
LOG.error("encode: Duplicate results found, newResult={}, results={} items",
142-
newResult.getCodeWithTerritory(), results.size());
143144
}
144145

145146
lastBaseSubTerritoryNumber = lastSubTerritoryRecord;

0 commit comments

Comments
 (0)