Skip to content

Commit b17e248

Browse files
committed
Fixed IDEA warnings
1 parent 487719b commit b17e248

File tree

14 files changed

+308
-307
lines changed

14 files changed

+308
-307
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
import javax.annotation.Nonnull;
2020
import javax.annotation.Nullable;
2121

22+
/**
23+
* Package private helper methods.
24+
*/
2225
class CheckArgs {
2326

24-
/**
25-
* Package private helper methods.
26-
*/
27+
private CheckArgs() {
28+
// Prevent instantiation.
29+
}
2730

2831
static void checkRange(@Nonnull final String param, final double value,
2932
final double min, final double max) throws IllegalArgumentException {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class Common {
3737
1260, 1300, 1343, 1389, 1438, 1490, 1547, 1609, 1676, 1749, 1828, 1916, 2012, 2118, 2237, 2370, 2521, 2691,
3838
2887, 3114, 3380, 3696, 4077, 4547, 5139, 5910, 6952, 8443, 10747, 14784, 23681, 59485};
3939

40+
private Common() {
41+
// Prevent instantiation.
42+
}
43+
4044
/**
4145
* This method returns a divider for longitude (multiplied by 4), for a given latitude.
4246
*

src/main/java/com/mapcode/DataAccess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private static int asUnsignedByte(final int i) {
7878
}
7979

8080
static int dataFlags(final int i) {
81-
return asUnsignedByte((i * 20) + 16) + asUnsignedByte((i * 20) + 17) * 256;
81+
return asUnsignedByte((i * 20) + 16) + (asUnsignedByte((i * 20) + 17) * 256);
8282
}
8383

8484
static int asLong(final int i) {

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

Lines changed: 154 additions & 190 deletions
Large diffs are not rendered by default.

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

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
class Encoder {
3535
private static final Logger LOG = LoggerFactory.getLogger(Encoder.class);
3636

37+
private Encoder() {
38+
// Prevent instantiation.
39+
}
40+
3741
// ----------------------------------------------------------------------
3842
// Method called from public Java API.
3943
// ----------------------------------------------------------------------
@@ -84,7 +88,7 @@ else if (lonDeg < -180) {
8488

8589
final Point pointToEncode = Point.fromDeg(latDeg, lonDeg);
8690
final List<SubArea> areas = SubArea.getAreasForPoint(pointToEncode);
87-
final List<Mapcode> results = new ArrayList<Mapcode>();
91+
final List<Mapcode> results = new ArrayList<>();
8892

8993
int lastbasesubareaID = -1;
9094

@@ -95,8 +99,8 @@ else if (lonDeg < -180) {
9599

96100
final Territory currentEncodeTerritory = subArea.getParentTerritory();
97101

98-
if (currentEncodeTerritory == Territory.AAA && !allowWorld &&
99-
territory != Territory.AAA) {
102+
if ((currentEncodeTerritory == Territory.AAA) && !allowWorld &&
103+
(territory != Territory.AAA)) {
100104
continue;
101105
}
102106

@@ -110,10 +114,10 @@ else if (lonDeg < -180) {
110114

111115
final int i = subArea.getSubAreaID();
112116
mapcoderData.dataSetup(i);
113-
if (mapcoderData.getCodex() < 54 && mapcoderData.getMapcoderRect().containsPoint(pointToEncode)) {
117+
if ((mapcoderData.getCodex() < 54) && mapcoderData.getMapcoderRect().containsPoint(pointToEncode)) {
114118
String mapcode = "";
115119
final Territory territoryParent = currentEncodeTerritory.getParentTerritory();
116-
if (mapcoderData.isUseless() && i == upto && territoryParent != null) {
120+
if (mapcoderData.isUseless() && (i == upto) && (territoryParent != null)) {
117121

118122
if (!isRecursive) {
119123
stateOverride = currentEncodeTerritory;
@@ -124,8 +128,8 @@ else if (lonDeg < -180) {
124128

125129
continue;
126130
}
127-
if (mapcoderData.getPipeType() == 0 && !mapcoderData.isNameless()) {
128-
if (!mapcoderData.isUseless() || lastbasesubareaID == from) {
131+
if ((mapcoderData.getPipeType() == 0) && !mapcoderData.isNameless()) {
132+
if (!mapcoderData.isUseless() || (lastbasesubareaID == from)) {
129133
mapcode = encodeGrid(i, pointToEncode, mapcoderData);
130134
}
131135
}
@@ -179,10 +183,10 @@ private static String addPostfix(final int extrax4, final int extray, final int
179183
final int gy = ((30 * extray) / dividery);
180184
final int x1 = (gx / 6);
181185
final int y1 = (gy / 5);
182-
String s = "-" + encode_chars[y1 * 5 + x1];
186+
String s = "-" + encode_chars[((y1 * 5) + x1)];
183187
final int x2 = (gx % 6);
184188
final int y2 = (gy % 5);
185-
s += encode_chars[y2 * 6 + x2];
189+
s += encode_chars[((y2 * 6) + x2)];
186190
return s;
187191
}
188192

@@ -206,12 +210,12 @@ private static String encodeGrid(final int m, final Point point, final Data mapc
206210
}
207211

208212
final int ygridsize =
209-
(mapcoderData.getMapcoderRect().getMaxY() - mapcoderData.getMapcoderRect().getMinY() + divy - 1)
213+
(((mapcoderData.getMapcoderRect().getMaxY() - mapcoderData.getMapcoderRect().getMinY()) + divy) - 1)
210214
/ divy;
211215
int rely = pointToEncode.getLatMicroDeg() - mapcoderData.getMapcoderRect().getMinY();
212216
rely = rely / ygridsize;
213217
final int xgridsize =
214-
(mapcoderData.getMapcoderRect().getMaxX() - mapcoderData.getMapcoderRect().getMinX() + divx - 1)
218+
(((mapcoderData.getMapcoderRect().getMaxX() - mapcoderData.getMapcoderRect().getMinX()) + divx) - 1)
215219
/ divx;
216220

217221
int relx = pointToEncode.getLonMicroDeg() - mapcoderData.getMapcoderRect().getMinX();
@@ -234,25 +238,25 @@ else if (relx >= 360000000) {
234238
}
235239

236240
final int v;
237-
if (divx != divy && codex > 24) // D==6
241+
if ((divx != divy) && (codex > 24)) // D==6
238242
{
239243
v = encode6(relx, rely, divx, divy);
240244
}
241245
else {
242-
v = relx * divy + divy - 1 - rely;
246+
v = ((relx * divy) + divy) - 1 - rely;
243247
}
244248

245249
String result = fastEncode(v, dc);
246250

247-
if (dc == 4 && divx == xSide[4] && divy == ySide[4]) {
251+
if ((dc == 4) && (divx == xSide[4]) && (divy == ySide[4])) {
248252
result = String.valueOf(result.charAt(0)) + result.charAt(2) + result.charAt(1) + result.charAt(3);
249253
}
250254

251-
rely = mapcoderData.getMapcoderRect().getMinY() + rely * ygridsize;
252-
relx = mapcoderData.getMapcoderRect().getMinX() + relx * xgridsize;
255+
rely = mapcoderData.getMapcoderRect().getMinY() + (rely * ygridsize);
256+
relx = mapcoderData.getMapcoderRect().getMinX() + (relx * xgridsize);
253257

254-
final int dividery = (ygridsize + ySide[codexlow] - 1) / ySide[codexlow];
255-
final int dividerx = (xgridsize + xSide[codexlow] - 1) / xSide[codexlow];
258+
final int dividery = ((ygridsize + ySide[codexlow]) - 1) / ySide[codexlow];
259+
final int dividerx = ((xgridsize + xSide[codexlow]) - 1) / xSide[codexlow];
256260

257261
result += '.';
258262

@@ -275,7 +279,7 @@ else if (relx >= 360000000) {
275279
}
276280
else {
277281

278-
String postfix = fastEncode((difx) * ySide[nrchars] + dify, nrchars);
282+
String postfix = fastEncode(((difx) * ySide[nrchars]) + dify, nrchars);
279283
if (nrchars == 4) {
280284
postfix = String.valueOf(postfix.charAt(0)) + postfix.charAt(2) + postfix.charAt(1) + postfix.charAt(3);
281285
}
@@ -300,11 +304,12 @@ private static String encodeStarpipe(final Point pointToEncode, final Data mapco
300304

301305
// search back to first pipe star
302306
int firstindex = thisindex;
303-
while (Data.calcStarPipe(firstindex - 1) && Data.calcCodexLen(firstindex - 1) == thiscodexlen) {
307+
while (Data.calcStarPipe(firstindex - 1) && (Data.calcCodexLen(firstindex - 1) == thiscodexlen)) {
304308
firstindex--;
305309
}
306310

307-
for (int i = firstindex; ; i++) {
311+
int i = firstindex;
312+
while (true) {
308313
if (Data.calcCodexLen(i) != thiscodexlen) {
309314
return starpipe_result.toString();
310315
}
@@ -316,26 +321,27 @@ private static String encodeStarpipe(final Point pointToEncode, final Data mapco
316321
final int minx = mapcoderData.getMapcoderRect().getMinX();
317322
final int miny = mapcoderData.getMapcoderRect().getMinY();
318323

319-
int h = (maxy - miny + 89) / 90;
324+
int h = ((maxy - miny) + 89) / 90;
320325
final int xdiv = xDivider(miny, maxy);
321-
int w = ((maxx - minx) * 4 + xdiv - 1) / xdiv;
326+
int w = ((((maxx - minx) * 4) + xdiv) - 1) / xdiv;
322327

323-
h = 176 * ((h + 176 - 1) / 176);
324-
w = 168 * ((w + 168 - 1) / 168);
328+
h = 176 * (((h + 176) - 1) / 176);
329+
w = 168 * (((w + 168) - 1) / 168);
325330

326331
int product = (w / 168) * (h / 176) * 961 * 31;
327332

328-
final int goodRounder = mapcoderData.getCodex() >= 23 ? 961 * 961 * 31 : 961 * 961;
333+
final int goodRounder = (mapcoderData.getCodex() >= 23) ? (961 * 961 * 31) : (961 * 961);
329334
if (mapcoderData.getPipeType() == 8) // *+
330335
{
331-
product = ((storageStart + product + goodRounder - 1) / goodRounder) * goodRounder - storageStart;
336+
product =
337+
((((storageStart + product + goodRounder) - 1) / goodRounder) * goodRounder) - storageStart;
332338
}
333339

334-
if (i == thisindex && mapcoderData.getMapcoderRect().containsPoint(pointToEncode)) {
335-
final int dividerx = (maxx - minx + w - 1) / w;
340+
if ((i == thisindex) && mapcoderData.getMapcoderRect().containsPoint(pointToEncode)) {
341+
final int dividerx = (((maxx - minx) + w) - 1) / w;
336342
int vx = (pointToEncode.getLonMicroDeg() - minx) / dividerx;
337343
final int extrax = (pointToEncode.getLonMicroDeg() - minx) % dividerx;
338-
final int dividery = (maxy - miny + h - 1) / h;
344+
final int dividery = (((maxy - miny) + h) - 1) / h;
339345
int vy = (maxy - pointToEncode.getLatMicroDeg()) / dividery;
340346
final int extray = (maxy - pointToEncode.getLatMicroDeg()) % dividery;
341347
final int spx = vx % 168;
@@ -345,9 +351,9 @@ private static String encodeStarpipe(final Point pointToEncode, final Data mapco
345351
vy = vy / 176;
346352

347353
// PIPELETTER ENCODE
348-
final int value = vx * (h / 176) + vy;
354+
final int value = (vx * (h / 176)) + vy;
349355

350-
starpipe_result.append(fastEncode(storageStart / (961 * 31) + value,
356+
starpipe_result.append(fastEncode((storageStart / (961 * 31)) + value,
351357
mapcoderData.getCodexLen() - 2));
352358
starpipe_result.append('.');
353359
starpipe_result.append(encodeTriple(spx, spy));
@@ -359,6 +365,7 @@ private static String encodeStarpipe(final Point pointToEncode, final Data mapco
359365
}
360366
storageStart += product;
361367
}
368+
i++;
362369
}
363370
}
364371

@@ -383,22 +390,22 @@ private static String encodeNameless(final Point pointToEncode, final Data mapco
383390
if (a > 1) {
384391
int storage_offset;
385392

386-
if (mapcoderData.getCodex() != 21 && a <= 31) {
387-
storage_offset = (nrX * p + (nrX < r ? nrX : r)) * (961 * 961);
393+
if ((mapcoderData.getCodex() != 21) && (a <= 31)) {
394+
storage_offset = ((nrX * p) + ((nrX < r) ? nrX : r)) * (961 * 961);
388395
}
389-
else if (mapcoderData.getCodex() != 21 && a < 62) {
390-
if (nrX < 62 - a) {
396+
else if ((mapcoderData.getCodex() != 21) && (a < 62)) {
397+
if (nrX < (62 - a)) {
391398
storage_offset = nrX * 961 * 961;
392399
}
393400
else {
394-
storage_offset = (62 - a + (nrX - 62 + a) / 2) * 961 * 961;
401+
storage_offset = ((62 - a) + (((nrX - 62) + a) / 2)) * 961 * 961;
395402
if (((nrX + a) & 1) != 0) {
396403
storage_offset += 16 * 961 * 31;
397404
}
398405
}
399406
}
400407
else {
401-
final int basePower = (mapcoderData.getCodex() == 21) ? 961 * 961 : 961 * 961 * 31;
408+
final int basePower = (mapcoderData.getCodex() == 21) ? (961 * 961) : (961 * 961 * 31);
402409
int basePowerA = basePower / a;
403410
if (a == 62) {
404411
basePowerA++;
@@ -415,7 +422,7 @@ else if (mapcoderData.getCodex() != 21 && a < 62) {
415422
int xSide = side;
416423
if (mapcoderData.isSpecialShape()) {
417424
xSide *= side;
418-
side = 1 + (maxy - miny) / 90;
425+
side = 1 + ((maxy - miny) / 90);
419426
xSide = xSide / side;
420427
}
421428

@@ -425,7 +432,7 @@ else if (mapcoderData.getCodex() != 21 && a < 62) {
425432
final int dx = (4 * (x - minx)) / dividerx4;
426433
// div with floating point value
427434

428-
final int extrax4 = (x - minx) * 4 - (dx * dividerx4); // like modulus, but with floating point value
435+
final int extrax4 = ((x - minx) * 4) - (dx * dividerx4); // like modulus, but with floating point value
429436

430437
final int dividery = 90;
431438
final int dy = (maxy - y) / dividery;
@@ -435,7 +442,7 @@ else if (mapcoderData.getCodex() != 21 && a < 62) {
435442
v += encode6(dx, side - 1 - dy, xSide, side);
436443
}
437444
else {
438-
v += dx * side + dy;
445+
v += (dx * side) + dy;
439446
}
440447

441448
String result = fastEncode(v, mapcoderData.getCodexLen() + 1);
@@ -444,7 +451,7 @@ else if (mapcoderData.getCodex() != 21 && a < 62) {
444451
result = result.substring(0, 2) + '.' + result.substring(2);
445452
}
446453
else if (mapcoderData.getCodexLen() == 4) {
447-
if (mapcoderData.getCodex() == 22 && a < 62 && orgSide == 961 && !mapcoderData.isSpecialShape()) {
454+
if ((mapcoderData.getCodex() == 22) && (a < 62) && (orgSide == 961) && !mapcoderData.isSpecialShape()) {
448455
result = result.substring(0, 2) + result.charAt(3) + result.charAt(2) + result.charAt(4);
449456
}
450457
if (mapcoderData.getCodex() == 13) {
@@ -468,9 +475,9 @@ private static String aeuPack(final String argStr) {
468475
int d;
469476
String rest = "";
470477
for (d = 0; d < rlen; d++) {
471-
if (str.charAt(d) < '0' || str.charAt(d) > '9') // not digit?
478+
if ((str.charAt(d) < '0') || (str.charAt(d) > '9')) // not digit?
472479
{
473-
if (str.charAt(d) == '.' && dotpos < 0) // first dot?
480+
if ((str.charAt(d) == '.') && (dotpos < 0)) // first dot?
474481
{
475482
dotpos = d;
476483
}
@@ -485,10 +492,10 @@ else if (str.charAt(d) == '-') {
485492
}
486493
}
487494

488-
if (rlen - 2 > dotpos) {
495+
if ((rlen - 2) > dotpos) {
489496
// does r have a dot, AND at least 2 chars
490497
// after the dot?
491-
final int v = (((int) str.charAt(rlen - 2)) - 48) * 10 + ((int) str.charAt(rlen - 1)) - 48;
498+
final int v = (((((int) str.charAt(rlen - 2)) - 48) * 10) + ((int) str.charAt(rlen - 1))) - 48;
492499
final int last = v % 34;
493500
final char[] vowels = {'A', 'E', 'U'};
494501
str =
@@ -515,17 +522,17 @@ private static int encode6(final int x, final int y, final int width, final int
515522
final int maxcol = (width - 4) / 6;
516523
if (col >= maxcol) {
517524
col = maxcol;
518-
d = width - maxcol * 6;
525+
d = width - (maxcol * 6);
519526
}
520-
return height * 6 * col + (height - 1 - y) * d + x - col * 6;
527+
return ((height * 6 * col) + ((height - 1 - y) * d) + x) - (col * 6);
521528
}
522529

523530
private static String encodeTriple(final int difx, final int dify) {
524-
if (dify < 4 * 34) {
525-
return encode_chars[difx / 28 + 6 * (dify / 34)] + fastEncode((difx % 28) * 34 + dify % 34, 2);
531+
if (dify < (4 * 34)) {
532+
return encode_chars[((difx / 28) + (6 * (dify / 34)))] + fastEncode(((difx % 28) * 34) + (dify % 34), 2);
526533
}
527534
else {
528-
return encode_chars[difx / 24 + 24] + fastEncode((difx % 24) * 40 + dify - 136, 2);
535+
return encode_chars[((difx / 24) + 24)] + fastEncode((((difx % 24) * 40) + dify) - 136, 2);
529536
}
530537
}
531538
}

src/main/java/com/mapcode/Mapcode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* territory definition.
2727
*
2828
* Note that the constructor will throw an {@link IllegalArgumentException} if the syntax of the mapcode
29-
* is not correct. It does not throw an {@link com.mapcode.UnknownMapcodeException}, because the mapcode
29+
* is not correct. It does not throw an {@link UnknownMapcodeException}, because the mapcode
3030
* is not checked for validity, other than its syntax.
3131
*/
3232
public final class Mapcode {

src/main/java/com/mapcode/MapcodeCodec.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
*/
3232
public final class MapcodeCodec {
3333

34+
private MapcodeCodec() {
35+
// Prevent instantiation.
36+
}
37+
3438
/**
3539
* ------------------------------------------------------------------------------------------
3640
* Encoding latitude, longitude to mapcodes.
@@ -79,7 +83,7 @@ public static List<Mapcode> encode(
7983
*
8084
* @param latDeg Latitude, accepted range: -90..90.
8185
* @param lonDeg Longitude, accepted range: -180..180.
82-
* @param restrictToTerritory Try to encode only within this territory, see {@link com.mapcode.Territory}. Cannot
86+
* @param restrictToTerritory Try to encode only within this territory, see {@link Territory}. Cannot
8387
* be null.
8488
* @return List of mapcode information records, see {@link Mapcode}. This list is empty if no
8589
* Mapcode can be generated for this territory matching the lat/lon.
@@ -129,7 +133,7 @@ public static Mapcode encodeToShortest(
129133
*
130134
* @param latDeg Latitude, accepted range: -90..90.
131135
* @param lonDeg Longitude, accepted range: -180..180.
132-
* @param restrictToTerritory Try to encode only within this territory, see {@link com.mapcode.Territory}. Cannot
136+
* @param restrictToTerritory Try to encode only within this territory, see {@link Territory}. Cannot
133137
* be null.
134138
* @return Shortest mapcode, see {@link Mapcode}.
135139
* @throws IllegalArgumentException Thrown if latitude or longitude are out of range.

0 commit comments

Comments
 (0)