Skip to content

Commit 71bf51e

Browse files
committed
Ran analyze code and fixed some warnings
1 parent a7e5563 commit 71bf51e

File tree

9 files changed

+34
-31
lines changed

9 files changed

+34
-31
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.mapcode;
1818

19-
import javax.annotation.CheckForNull;
2019
import javax.annotation.Nonnull;
2120
import javax.annotation.Nullable;
2221

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ private Decoder() {
3636
// Method called from public Java API.
3737
// ----------------------------------------------------------------------
3838

39-
@SuppressWarnings("ConstantConditions")
4039
@Nonnull
4140
static Point decode(@Nonnull final String argMapcode,
4241
@Nonnull final Territory argTerritory)
@@ -806,16 +805,16 @@ private static MapcodeZone decodeExtension(final int y, final int x, final int d
806805
} // not odd
807806

808807
// FORCE_RECODE - restrict the coordinate range to the extremes that were provided
809-
if (mapcodeZone.getFractionMaxX() > (maxLonMicroDeg * Point.MICROLON_TO_FRACTIONS_FACTOR)) {
810-
mapcodeZone.setFractionMaxX(maxLonMicroDeg * Point.MICROLON_TO_FRACTIONS_FACTOR);
808+
if (mapcodeZone.getFractionMaxX() > (maxLonMicroDeg * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR)) {
809+
mapcodeZone.setFractionMaxX(maxLonMicroDeg * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR);
811810
}
812811
if (dividery >= 0) {
813-
if (mapcodeZone.getFractionMaxY() > (extremeLatMicroDeg * Point.MICROLAT_TO_FRACTIONS_FACTOR)) {
814-
mapcodeZone.setFractionMaxY(extremeLatMicroDeg * Point.MICROLAT_TO_FRACTIONS_FACTOR);
812+
if (mapcodeZone.getFractionMaxY() > (extremeLatMicroDeg * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR)) {
813+
mapcodeZone.setFractionMaxY(extremeLatMicroDeg * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR);
815814
}
816815
} else {
817-
if (mapcodeZone.getFractionMinY() < (extremeLatMicroDeg * Point.MICROLAT_TO_FRACTIONS_FACTOR)) {
818-
mapcodeZone.setFractionMinY(extremeLatMicroDeg * Point.MICROLAT_TO_FRACTIONS_FACTOR);
816+
if (mapcodeZone.getFractionMinY() < (extremeLatMicroDeg * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR)) {
817+
mapcodeZone.setFractionMinY(extremeLatMicroDeg * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR);
819818
}
820819
}
821820
return mapcodeZone;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ private static String encodeExtension(final Point pointToEncode, final int extra
142142

143143
while (true) {
144144
factorx /= 30;
145+
//noinspection NumericCastThatLosesPrecision
145146
final int gx = (int) (valx / factorx);
146147

147148
factory /= 30;
149+
//noinspection NumericCastThatLosesPrecision
148150
final int gy = (int) (valy / factory);
149151

150152
sb.append(ENCODE_CHARS[((gy / 5) * 5) + (gx / 6)]);

src/main/java/com/mapcode/MapcodeZone.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,23 @@ public Point getMidPoint() {
129129
@Nonnull
130130
public MapcodeZone restrictZoneTo(@Nonnull final Boundary area) {
131131
MapcodeZone z = new MapcodeZone(this);
132-
final double miny = area.getMinY() * Point.MICROLAT_TO_FRACTIONS_FACTOR;
132+
final double miny = area.getMinY() * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR;
133133
if (z.fractionMinY < miny) {
134134
z.fractionMinY = miny;
135135
}
136-
final double maxy = area.getMaxY() * Point.MICROLAT_TO_FRACTIONS_FACTOR;
136+
final double maxy = area.getMaxY() * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR;
137137
if (z.fractionMaxY > maxy) {
138138
z.fractionMaxY = maxy;
139139
}
140140
if (z.fractionMinY < z.fractionMaxY) {
141-
double minx = area.getMinX() * Point.MICROLON_TO_FRACTIONS_FACTOR;
142-
double maxx = area.getMaxX() * Point.MICROLON_TO_FRACTIONS_FACTOR;
141+
double minx = area.getMinX() * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR;
142+
double maxx = area.getMaxX() * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR;
143143
if ((maxx < 0) && (z.fractionMinX > 0)) {
144-
minx += (360000000 * Point.MICROLON_TO_FRACTIONS_FACTOR);
145-
maxx += (360000000 * Point.MICROLON_TO_FRACTIONS_FACTOR);
144+
minx += (360000000 * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR);
145+
maxx += (360000000 * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR);
146146
} else if ((minx > 1) && (z.fractionMaxX < 0)) {
147-
minx -= (360000000 * Point.MICROLON_TO_FRACTIONS_FACTOR);
148-
maxx -= (360000000 * Point.MICROLON_TO_FRACTIONS_FACTOR);
147+
minx -= (360000000 * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR);
148+
maxx -= (360000000 * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR);
149149
}
150150
if (z.fractionMinX < minx) {
151151
z.fractionMinX = minx;

src/main/java/com/mapcode/Point.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ public boolean equals(final Object o) {
238238
// Constants to convert between Degrees, MicroDegrees and Fractions
239239
static final double MICRODEG_TO_DEG_FACTOR = 1000000.0;
240240
static final double MAX_PRECISION_FACTOR = 810000.0;
241-
static final double MICROLAT_TO_FRACTIONS_FACTOR = (MAX_PRECISION_FACTOR);
242-
static final double MICROLON_TO_FRACTIONS_FACTOR = (MAX_PRECISION_FACTOR * 4);
243-
static final double LAT_TO_FRACTIONS_FACTOR = (MICRODEG_TO_DEG_FACTOR * MICROLAT_TO_FRACTIONS_FACTOR);
244-
static final double LON_TO_FRACTIONS_FACTOR = (MICRODEG_TO_DEG_FACTOR * MICROLON_TO_FRACTIONS_FACTOR);
241+
static final double LAT_MICRODEG_TO_FRACTIONS_FACTOR = MAX_PRECISION_FACTOR;
242+
static final double LON_MICRODEG_TO_FRACTIONS_FACTOR = MAX_PRECISION_FACTOR * 4;
243+
static final double LAT_TO_FRACTIONS_FACTOR = MICRODEG_TO_DEG_FACTOR * LAT_MICRODEG_TO_FRACTIONS_FACTOR;
244+
static final double LON_TO_FRACTIONS_FACTOR = MICRODEG_TO_DEG_FACTOR * LON_MICRODEG_TO_FRACTIONS_FACTOR;
245245

246246
static final int LON_MICRODEG_MIN = degToMicroDeg(LON_DEG_MIN);
247247
static final int LON_MICRODEG_MAX = degToMicroDeg(LON_DEG_MAX);
@@ -270,6 +270,7 @@ private Point() {
270270
/**
271271
* Public construction, from floating point degrees (potentially lossy).
272272
*/
273+
@SuppressWarnings("NumericCastThatLosesPrecision")
273274
private Point(final double latDeg, final double lonDeg) {
274275

275276
double lat = latDeg + 90;
@@ -282,8 +283,8 @@ private Point(final double latDeg, final double lonDeg) {
282283
// Lat now [0..180].
283284
lat = lat * LAT_TO_FRACTIONS_FACTOR;
284285
double latFrac = Math.floor(lat + 0.1); // TODO: Check the + 0.1! Why?
285-
latDeg32 = (int) (latFrac / MICROLAT_TO_FRACTIONS_FACTOR);
286-
latFrac = latFrac - ((double) latDeg32 * MICROLAT_TO_FRACTIONS_FACTOR);
286+
latDeg32 = (int) (latFrac / LAT_MICRODEG_TO_FRACTIONS_FACTOR);
287+
latFrac = latFrac - ((double) latDeg32 * LAT_MICRODEG_TO_FRACTIONS_FACTOR);
287288
latDegFrac = (int) latFrac;
288289
latDeg32 = latDeg32 - 90000000;
289290

@@ -292,8 +293,8 @@ private Point(final double latDeg, final double lonDeg) {
292293
// Lon now in [0..360>.
293294
lon = lon * LON_TO_FRACTIONS_FACTOR;
294295
double lonFrac = Math.floor(lon + 0.1); // TODO: Check the + 0.1! Why?
295-
lonDeg32 = (int) (lonFrac / MICROLON_TO_FRACTIONS_FACTOR);
296-
lonFrac = lonFrac - ((double) lonDeg32 * MICROLON_TO_FRACTIONS_FACTOR);
296+
lonDeg32 = (int) (lonFrac / LON_MICRODEG_TO_FRACTIONS_FACTOR);
297+
lonFrac = lonFrac - ((double) lonDeg32 * LON_MICRODEG_TO_FRACTIONS_FACTOR);
297298
lonDegFrac = (int) lonFrac;
298299

299300
// Wrap lonDeg32 from [0..360> to [-180..180).
@@ -325,15 +326,16 @@ int getLatFraction() {
325326
/**
326327
* Package private construction, from integer fractions (no loss of precision).
327328
*/
329+
@SuppressWarnings("NumericCastThatLosesPrecision")
328330
@Nonnull
329331
static Point fromFractionDeg(final double latFractionDeg, final double lonFractionDeg) {
330332
assert (Double.compare(latFractionDeg, Math.floor(latFractionDeg)) == 0);
331333
assert (Double.compare(lonFractionDeg, Math.floor(lonFractionDeg)) == 0);
332334
Point p = new Point();
333-
p.latDeg32 = (int) Math.floor(latFractionDeg / MICROLAT_TO_FRACTIONS_FACTOR);
334-
p.latDegFrac = (int) (latFractionDeg - (MICROLAT_TO_FRACTIONS_FACTOR * p.latDeg32));
335-
p.lonDeg32 = (int) Math.floor(lonFractionDeg / MICROLON_TO_FRACTIONS_FACTOR);
336-
p.lonDegFrac = (int) (lonFractionDeg - (MICROLON_TO_FRACTIONS_FACTOR * p.lonDeg32));
335+
p.latDeg32 = (int) Math.floor(latFractionDeg / LAT_MICRODEG_TO_FRACTIONS_FACTOR);
336+
p.latDegFrac = (int) (latFractionDeg - (LAT_MICRODEG_TO_FRACTIONS_FACTOR * p.latDeg32));
337+
p.lonDeg32 = (int) Math.floor(lonFractionDeg / LON_MICRODEG_TO_FRACTIONS_FACTOR);
338+
p.lonDegFrac = (int) (lonFractionDeg - (LON_MICRODEG_TO_FRACTIONS_FACTOR * p.lonDeg32));
337339
p.defined = true;
338340
return p.wrap();
339341
}

src/main/java/com/mapcode/Territory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ private static Territory createFromString(
926926
// Check for a case such as USA-NLD (=NLD)
927927
final int dividerLocation = Math.max(trimmed.indexOf('-'), trimmed.indexOf(' '));
928928
if (dividerLocation >= 0) {
929+
//noinspection TailRecursion
929930
return createFromString(trimmed.substring(dividerLocation + 1), parentTerritory);
930931
}
931932
throw new UnknownTerritoryException(trimmed);

src/main/java/com/mapcode/UnknownAlphabetException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public final class UnknownAlphabetException extends IllegalArgumentException {
2626
private static final long serialVersionUID = 1L;
2727

28-
final Integer code;
28+
private final Integer code;
2929

3030
public UnknownAlphabetException(@Nonnull final String message) {
3131
super(message);

src/main/java/com/mapcode/UnknownPrecisionFormatException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public final class UnknownPrecisionFormatException extends IllegalArgumentException {
2626
private static final long serialVersionUID = 1L;
2727

28-
final Integer precision;
28+
private final Integer precision;
2929

3030
public UnknownPrecisionFormatException(@Nonnull final String message) {
3131
super(message);

src/main/java/com/mapcode/UnknownTerritoryException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public final class UnknownTerritoryException extends IllegalArgumentException {
2626
private static final long serialVersionUID = 1L;
2727

28-
final Integer code;
28+
private final Integer code;
2929

3030
public UnknownTerritoryException(@Nonnull final String message) {
3131
super(message);

0 commit comments

Comments
 (0)