Skip to content

Commit af54d33

Browse files
committed
Minor fixes
1 parent 5ab6db5 commit af54d33

File tree

6 files changed

+53
-63
lines changed

6 files changed

+53
-63
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
import static com.mapcode.CheckArgs.checkNonnull;
2222

2323
/**
24-
* This enum defines all alphabets supported for mapcodes. Mapcodes can be safely converted between
25-
* alphabets and fed to the mapcode decoder in the regular ASCII Roman alphabet or any other.
24+
* This enum defines all alphabets supported for mapcodes. Note that an alphabet is different from a
25+
* language or locale. An alternative name for an alphabet is "script".
26+
*
27+
* Mapcodes can be safely converted between alphabets and fed to the mapcode decoder in the regular
28+
* ASCII Roman alphabet or any other.
2629
*/
2730
public enum Alphabet {
28-
ROMAN(0),
29-
GREEK(1),
31+
ROMAN(0), // The numeric codes for alphabets are used by the implementation
32+
GREEK(1), // of the mapcode library. Do not change them.
3033
CYRILLIC(2),
3134
HEBREW(3),
3235
HINDI(4),
@@ -41,8 +44,7 @@ public enum Alphabet {
4144
TIBETAN(13);
4245

4346
/**
44-
* The numeric code is synonym for the alphanumeric code. It can be used in the decoder
45-
* to define a territory as well.
47+
* The numeric code is synonym for the alphanumeric code. Used in the decoder.
4648
*/
4749
private final int number;
4850

@@ -65,7 +67,7 @@ int getNumber() {
6567
}
6668

6769
/**
68-
* Return alphabet from a string, which can be a numeric or alpha code.
70+
* Return alphabet from a string, which needs to be an alphanumeric code.
6971
*
7072
* @param alphaCode Alphabet, alphanumeric code.
7173
* @return Alphabet.
@@ -83,7 +85,7 @@ public static Alphabet fromString(@Nonnull final String alphaCode) throws Unknow
8385
}
8486

8587
/**
86-
* Static checking of the static data structures.
88+
* Static consistency check of internal data structures.
8789
*/
8890
static {
8991
int i = 0;

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,16 @@
2222
import static com.mapcode.Mapcode.getPrecisionFormat;
2323

2424
/**
25-
* Package private helper methods to check arguments for validity.
25+
* ----------------------------------------------------------------------------------------------
26+
* Package private implementation class. For internal use within the Mapcode implementation only.
27+
* ----------------------------------------------------------------------------------------------
2628
*/
2729
class CheckArgs {
2830

2931
private CheckArgs() {
3032
// Prevent instantiation.
3133
}
3234

33-
static void checkRange(@Nonnull final String param, final double value,
34-
final double min, final double max) throws IllegalArgumentException {
35-
if ((value < min) || (value > max)) {
36-
throw new IllegalArgumentException("Parameter " + param +
37-
" should be in range [" + min + ", " + max + "], but is: " + value);
38-
}
39-
}
40-
4135
static void checkNonnull(@Nonnull final String param, @Nullable final Object obj)
4236
throws IllegalArgumentException {
4337
if (obj == null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public static PrecisionFormat getPrecisionFormat(@Nonnull final String mapcode)
333333
* actually a valid mapcode representing a location on Earth.
334334
* @throws IllegalArgumentException If mapcode is null.
335335
*/
336-
public static boolean isValidPrecisionFormat(@Nonnull final String mapcode) throws IllegalArgumentException {
336+
public static boolean isValidMapcodeFormat(@Nonnull final String mapcode) throws IllegalArgumentException {
337337
checkNonnull("mapcode", mapcode);
338338
try {
339339
// Throws an exception if the format is incorrect.

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
import static com.mapcode.CheckArgs.checkNonnull;
2424

2525
/**
26-
* ----------------------------------------------------------------------------------------------
27-
* Package private implementation class. For internal use within the mapcode implementation only.
28-
* ----------------------------------------------------------------------------------------------
29-
*
3026
* This class defines a class for lat/lon points.
3127
*/
3228
public class Point {
@@ -37,13 +33,6 @@ public class Point {
3733
public static final double LAT_DEG_MIN = -90.0;
3834
public static final double LAT_DEG_MAX = 90.0;
3935

40-
public static final int LON_MICRODEG_MIN = degToMicroDeg(LON_DEG_MIN);
41-
public static final int LON_MICRODEG_MAX = degToMicroDeg(LON_DEG_MAX);
42-
public static final int LAT_MICRODEG_MIN = degToMicroDeg(LAT_DEG_MIN);
43-
public static final int LAT_MICRODEG_MAX = degToMicroDeg(LAT_DEG_MAX);
44-
45-
public static final double MICRODEG_TO_DEG_FACTOR = 1000000.0;
46-
4736
// Radius of Earth.
4837
public static final double EARTH_RADIUS_X_METERS = 6378137.0;
4938
public static final double EARTH_RADIUS_Y_METERS = 6356752.3;
@@ -155,8 +144,7 @@ public static double distanceInMeters(@Nonnull final Point p1, @Nonnull final Po
155144
final double deltaYMeters = degreesLatToMeters(deltaLatDeg);
156145

157146
// Calculate length through Earth. This is an approximation, but works fine for short distances.
158-
final double lenMeters = Math.sqrt((deltaXMeters * deltaXMeters) + (deltaYMeters * deltaYMeters));
159-
return lenMeters;
147+
return Math.sqrt((deltaXMeters * deltaXMeters) + (deltaYMeters * deltaYMeters));
160148
}
161149

162150
public static double degreesLatToMeters(final double latDegrees) {
@@ -236,6 +224,11 @@ private Point(final double latDeg, final double lonDeg, final boolean wrap) {
236224
/**
237225
* Package private methods. Only used in the mapcode implementation modules.
238226
*/
227+
static final double MICRODEG_TO_DEG_FACTOR = 1000000.0;
228+
static final int LON_MICRODEG_MIN = degToMicroDeg(LON_DEG_MIN);
229+
static final int LON_MICRODEG_MAX = degToMicroDeg(LON_DEG_MAX);
230+
static final int LAT_MICRODEG_MIN = degToMicroDeg(LAT_DEG_MIN);
231+
static final int LAT_MICRODEG_MAX = degToMicroDeg(LAT_DEG_MAX);
239232

240233
@Nonnull
241234
static Point fromMicroDeg(final int latMicroDeg, final int lonMicroDeg) {
@@ -287,8 +280,7 @@ Point wrap() {
287280
* @return Limited to [-90, 90].
288281
*/
289282
static double mapToLat(final double value) {
290-
final double lat = (value < -90.0) ? -90.0 : ((value > 90.0) ? 90.0 : value);
291-
return lat;
283+
return (value < -90.0) ? -90.0 : ((value > 90.0) ? 90.0 : value);
292284
}
293285

294286
/**

src/site/apt/ReleaseNotes.apt.vm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Release Notes (Version ${project.version})
1111

1212
* 2.0.2
1313

14-
* To do.
14+
* Renamed <<<isValidPrecisionFormat>>> to <<<isValidMapcodeFormat>>>.
15+
16+
* Removed public microdegree references from <<<Point>>> class.
1517

1618
[]
1719

src/test/java/com/mapcode/MapcodeTest.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,37 +60,37 @@ public void checkInvalidPrecisionFormats() {
6060
LOG.info("checkInvalidPrecisionFormats");
6161

6262
// Territory code must be correct syntax.
63-
assertFalse(Mapcode.isValidPrecisionFormat("NL- XX.XX"));
64-
assertFalse(Mapcode.isValidPrecisionFormat("US IN XX.XX"));
63+
assertFalse(Mapcode.isValidMapcodeFormat("NL- XX.XX"));
64+
assertFalse(Mapcode.isValidMapcodeFormat("US IN XX.XX"));
6565

6666
// Incorrect (nunber of) characters.
67-
assertFalse(Mapcode.isValidPrecisionFormat("A"));
68-
assertFalse(Mapcode.isValidPrecisionFormat("AB"));
69-
assertFalse(Mapcode.isValidPrecisionFormat("AB."));
70-
assertFalse(Mapcode.isValidPrecisionFormat(".A"));
71-
assertFalse(Mapcode.isValidPrecisionFormat(".AB"));
72-
assertFalse(Mapcode.isValidPrecisionFormat("A.B"));
73-
assertFalse(Mapcode.isValidPrecisionFormat("a.B"));
74-
assertFalse(Mapcode.isValidPrecisionFormat("0.1"));
75-
assertFalse(Mapcode.isValidPrecisionFormat("0.1"));
76-
assertFalse(Mapcode.isValidPrecisionFormat("00.1"));
77-
assertFalse(Mapcode.isValidPrecisionFormat("0.01"));
78-
assertFalse(Mapcode.isValidPrecisionFormat("00.01."));
79-
assertFalse(Mapcode.isValidPrecisionFormat("00.01.0"));
80-
assertFalse(Mapcode.isValidPrecisionFormat("00.01.00"));
81-
assertFalse(Mapcode.isValidPrecisionFormat("00.01-"));
82-
assertFalse(Mapcode.isValidPrecisionFormat("00.01-"));
83-
assertFalse(Mapcode.isValidPrecisionFormat("AAAAAA.BBBBB"));
84-
assertFalse(Mapcode.isValidPrecisionFormat("AAAAA.BBBBBB"));
85-
assertFalse(Mapcode.isValidPrecisionFormat("AA.AA-012"));
86-
assertFalse(Mapcode.isValidPrecisionFormat("AA.AA-Z"));
87-
assertFalse(Mapcode.isValidPrecisionFormat("AA.AA-1Z"));
88-
assertFalse(Mapcode.isValidPrecisionFormat("A.AAA"));
89-
assertFalse(Mapcode.isValidPrecisionFormat("AAA.A"));
90-
assertFalse(Mapcode.isValidPrecisionFormat("A.AAA-1"));
91-
assertFalse(Mapcode.isValidPrecisionFormat("AAA.A-1"));
92-
assertFalse(Mapcode.isValidPrecisionFormat("A.AAA-12"));
93-
assertFalse(Mapcode.isValidPrecisionFormat("AAA.A-12"));
67+
assertFalse(Mapcode.isValidMapcodeFormat("A"));
68+
assertFalse(Mapcode.isValidMapcodeFormat("AB"));
69+
assertFalse(Mapcode.isValidMapcodeFormat("AB."));
70+
assertFalse(Mapcode.isValidMapcodeFormat(".A"));
71+
assertFalse(Mapcode.isValidMapcodeFormat(".AB"));
72+
assertFalse(Mapcode.isValidMapcodeFormat("A.B"));
73+
assertFalse(Mapcode.isValidMapcodeFormat("a.B"));
74+
assertFalse(Mapcode.isValidMapcodeFormat("0.1"));
75+
assertFalse(Mapcode.isValidMapcodeFormat("0.1"));
76+
assertFalse(Mapcode.isValidMapcodeFormat("00.1"));
77+
assertFalse(Mapcode.isValidMapcodeFormat("0.01"));
78+
assertFalse(Mapcode.isValidMapcodeFormat("00.01."));
79+
assertFalse(Mapcode.isValidMapcodeFormat("00.01.0"));
80+
assertFalse(Mapcode.isValidMapcodeFormat("00.01.00"));
81+
assertFalse(Mapcode.isValidMapcodeFormat("00.01-"));
82+
assertFalse(Mapcode.isValidMapcodeFormat("00.01-"));
83+
assertFalse(Mapcode.isValidMapcodeFormat("AAAAAA.BBBBB"));
84+
assertFalse(Mapcode.isValidMapcodeFormat("AAAAA.BBBBBB"));
85+
assertFalse(Mapcode.isValidMapcodeFormat("AA.AA-012"));
86+
assertFalse(Mapcode.isValidMapcodeFormat("AA.AA-Z"));
87+
assertFalse(Mapcode.isValidMapcodeFormat("AA.AA-1Z"));
88+
assertFalse(Mapcode.isValidMapcodeFormat("A.AAA"));
89+
assertFalse(Mapcode.isValidMapcodeFormat("AAA.A"));
90+
assertFalse(Mapcode.isValidMapcodeFormat("A.AAA-1"));
91+
assertFalse(Mapcode.isValidMapcodeFormat("AAA.A-1"));
92+
assertFalse(Mapcode.isValidMapcodeFormat("A.AAA-12"));
93+
assertFalse(Mapcode.isValidMapcodeFormat("AAA.A-12"));
9494
}
9595

9696
@Test

0 commit comments

Comments
 (0)