Skip to content

Commit da5226f

Browse files
committed
Added utility method to Mapcode.
1 parent 5412dea commit da5226f

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<jsr305.version>3.0.0</jsr305.version>
7575
<junit.version>4.12</junit.version>
7676
<log4j.version>1.2.17</log4j.version>
77-
<slf4j.version>1.7.10</slf4j.version>
77+
<slf4j.version>1.7.12</slf4j.version>
7878
<nexus-staging-maven-plugin.version>1.6.5</nexus-staging-maven-plugin.version>
7979
<maven-source-plugin.version>2.4</maven-source-plugin.version>
8080
<maven-javadoc-plugin.version>2.10.1</maven-javadoc-plugin.version>

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ public String getMapcode() {
7272
return mapcodePrecision0;
7373
}
7474

75+
/**
76+
* Alias for {@link #getMapcode}.
77+
*
78+
* @param precision Precision. Range: 0..2.
79+
* @return Mapcode string.
80+
*/
81+
@Nonnull
82+
public String getMapcodePrecision(final int precision) {
83+
switch (precision) {
84+
case 0:
85+
return mapcodePrecision0;
86+
case 1:
87+
return mapcodePrecision1;
88+
case 2:
89+
return mapcodePrecision2;
90+
default:
91+
throw new IllegalArgumentException("getMapcodePrecision: precision must be in [0..2]");
92+
}
93+
}
94+
7595
/**
7696
* Alias for {@link #getMapcode}.
7797
*
@@ -123,9 +143,7 @@ public String getMapcodePrecision2() {
123143
return mapcodePrecision2;
124144
}
125145

126-
/**
127-
* Deprecated alias for {@see #getMapcodePrecision2}.
128-
*/
146+
// Deprecated alias for {@see #getMapcodePrecision2}.
129147
@Deprecated
130148
@Nonnull
131149
public String getMapcodeHighPrecision() {
@@ -162,7 +180,7 @@ public enum MapcodeFormatType {
162180

163181
/**
164182
* This patterns/regular expressions is used for checking mapcode format strings.
165-
* They've been made pulkic to allow others to use the correct regular expressions as well.
183+
* They've been made public to allow others to use the correct regular expressions as well.
166184
*/
167185
@Nonnull public static final String REGEX_MAPCODE_FORMAT =
168186
REGEX_MAPCODE_FORMAT1 + REGEX_MAPCODE_FORMAT2 + '(' + REGEX_MAPCODE_PRECISION + ")?$";

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ public static Mapcode encodeToInternational(
189189
* because no territory context is supplied (world-wide).
190190
*
191191
* The accepted format is:
192-
* <mapcode>
193-
* <territory-code> <mapcode>
192+
* {mapcode}
193+
* {territory-code} {mapcode}
194194
*
195195
* @param mapcode Mapcode.
196196
* @return Point corresponding to mapcode.
197-
* @throws UnknownMapcodeException Thrown if the mapcode has the correct synaxt,
197+
* @throws UnknownMapcodeException Thrown if the mapcode has the correct syntax,
198198
* but cannot be decoded into a point.
199199
* @throws IllegalArgumentException Thrown if arguments are null, or if the syntax of the mapcode is incorrect.
200200
*/
@@ -231,7 +231,7 @@ public static Point decode(
231231
* Decode a mapcode to a Point. A reference territory is supplied for disambiguation (only used if applicable).
232232
*
233233
* The accepted format is:
234-
* <mapcode> (note that a territory code is not allowed here)
234+
* {mapcode} (note that a territory code is not allowed here)
235235
*
236236
* @param mapcode Mapcode.
237237
* @param territoryContext Territory for disambiguation purposes.
@@ -244,7 +244,7 @@ public static Point decode(
244244
@Nonnull final String mapcode,
245245
@Nonnull final Territory territoryContext) throws UnknownMapcodeException, IllegalArgumentException {
246246
checkNonnull("mapcode", mapcode);
247-
checkNonnull("territoryConext", territoryContext);
247+
checkNonnull("territoryContext", territoryContext);
248248
final String mapcodeTrimmed = mapcode.trim();
249249
if (!Mapcode.isValidMapcodeFormat(mapcodeTrimmed)) {
250250
throw new IllegalArgumentException(mapcode + " is not a correctly formatted mapcode; " +

0 commit comments

Comments
 (0)