2424/**
2525 * This class defines a single mapcode encoding result, including the mapcode itself and the
2626 * territory definition.
27- *
27+ * <p/>
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 UnknownMapcodeException}, because the mapcode
29+ * is not correct. It does not throw an {@link com.mapcode. UnknownMapcodeException}, because the mapcode
3030 * is not checked for validity, other than its syntax.
3131 */
3232public final class Mapcode {
@@ -63,7 +63,7 @@ public Mapcode(
6363 /**
6464 * Get the Mapcode string (without territory information) with standard precision.
6565 * The returned mapcode does not include the '-' separator and additional digits.
66- *
66+ * <p/>
6767 * The returned precision is approximately 5 meters. The precision is defined as the maximum distance to the
6868 * (latitude, longitude) pair that encoded to this mapcode, which means the mapcode defines an area of
6969 * approximately 10 x 10 meters (100 m2).
@@ -75,6 +75,24 @@ public String getMapcode() {
7575 return mapcodePrecision0 ;
7676 }
7777
78+ /**
79+ * Get the Mapcode string (without territory information) with a specified precision.
80+ * The returned mapcode includes a '-' separator and additional digits for precisions 1 and 2.
81+ *
82+ * The precision defines the size of a geographical area a single mapcode covers. This means It also defines
83+ * the maximum distance to the location, a (latitude, longitude) pair, that encoded to this mapcode.
84+ *
85+ * Precision 0 uses an area of approx 10 x 10 meters, which means the original location and the location
86+ * as obtained by decoding the encoded mapcode are no further than 5 meters apart.
87+ *
88+ * Precision 1 uses an area of approx 10 x 10 meters, which means the original location and the location
89+ * as obtained by decoding the encoded mapcode are no further than 5 meters apart.
90+ *
91+ * Precision 2 uses an area of approx 10 x 10 meters, which means the original location and the location
92+ * as obtained by decoding the encoded mapcode are no further than 5 meters apart.
93+ *
94+ * @return Mapcode string.
95+ */
7896 /**
7997 * Alias for {@link #getMapcode}.
8098 *
@@ -100,6 +118,7 @@ public String getMapcodePrecision(final int precision) {
100118 *
101119 * @return Mapcode string.
102120 */
121+ @ Deprecated
103122 @ Nonnull
104123 public String getMapcodePrecision0 () {
105124 return mapcodePrecision0 ;
@@ -109,7 +128,7 @@ public String getMapcodePrecision0() {
109128 * Get the medium-precision mapcode string (without territory information).
110129 * The returned mapcode includes the '-' separator and 1 additional digit, if available.
111130 * If a medium precision code is not available, the regular mapcode is returned.
112- *
131+ * <p/>
113132 * The returned precision is approximately 1 meter. The precision is defined as the maximum distance to the
114133 * (latitude, longitude) pair that encoded to this mapcode, which means the mapcode defines an area of
115134 * approximately 2 x 2 meters (4 m2).
@@ -134,7 +153,7 @@ public String getMapcodeMediumPrecision() {
134153 * Get the high-precision mapcode string (without territory information).
135154 * The returned mapcode includes the '-' separator and 2 additional digit2, if available.
136155 * If a high precision code is not available, the regular mapcode is returned.
137- *
156+ * <p/>
138157 * The returned precision is approximately 16 centimeters. The precision is defined as the maximum distance to the
139158 * (latitude, longitude) pair that encoded to this mapcode, which means the mapcode defines an area of
140159 * approximately 32 x 32 centimeters (0.1 m2).
@@ -203,7 +222,7 @@ public enum MapcodeFormatType {
203222 * This method return the mapcode type, given a mapcode string. If the mapcode string has an invalid
204223 * format, {@link MapcodeFormatType#MAPCODE_TYPE_INVALID} is returned. If another value is returned,
205224 * the precision of the mapcode is given.
206- *
225+ * <p/>
207226 * Note that this method only checks the syntactic validity of the mapcode, the string format. It does not
208227 * check if the mapcode is really a valid mapcode representing a position on Earth.
209228 *
@@ -258,7 +277,7 @@ public static String convertToAscii(@Nonnull final String mapcode) {
258277
259278 /**
260279 * Return the local mapcode string, potentially ambiguous.
261- *
280+ * <p/>
262281 * Example:
263282 * 49.4V
264283 *
@@ -273,13 +292,19 @@ public String asLocal() {
273292 * Return the full international mapcode, including the full name of the territory and the Mapcode itself.
274293 * The format of the code is:
275294 * full-territory-name mapcode
276- *
295+ * <p/>
277296 * Example:
278297 * Netherlands 49.4V (regular code)
279298 * Netherlands 49.4V-K2 (high precision code)
280299 *
300+ * @param precision Precision specifier. Range: [0, 2].
281301 * @return Full international mapcode.
282302 */
303+ @ Nonnull
304+ public String asInternationalFullName (final int precision ) {
305+ return territory .getFullName () + ' ' + getMapcodePrecision (precision );
306+ }
307+
283308 @ Nonnull
284309 public String asInternationalFullName () {
285310 return territory .getFullName () + ' ' + mapcodePrecision0 ;
@@ -290,18 +315,25 @@ public String asInternationalFullName() {
290315 * International codes use a territory code "AAA".
291316 * The format of the code is:
292317 * short-territory-name mapcode
293- *
318+ * <p/>
294319 * Example:
295320 * NLD 49.4V (regular code)
296321 * NLD 49.4V-K2 (high-precision code)
297322 *
323+ * @param precision Precision specifier. Range: [0, 2].
298324 * @return Short-hand international mapcode.
299325 */
326+ @ Nonnull
327+ public String asInternationalISO (final int precision ) {
328+ return territory .toString () + ' ' + getMapcodePrecision (precision );
329+ }
330+
300331 @ Nonnull
301332 public String asInternationalISO () {
302333 return territory .toString () + ' ' + mapcodePrecision0 ;
303334 }
304335
336+
305337 @ Nonnull
306338 @ Override
307339 public String toString () {
@@ -310,7 +342,7 @@ public String toString() {
310342
311343 @ Override
312344 public int hashCode () {
313- return Arrays .deepHashCode (new Object []{mapcodePrecision0 , territory });
345+ return Arrays .deepHashCode (new Object []{mapcodePrecision0 , mapcodePrecision1 , mapcodePrecision2 , territory });
314346 }
315347
316348 @ Override
@@ -322,6 +354,9 @@ public boolean equals(final Object obj) {
322354 return false ;
323355 }
324356 final Mapcode that = (Mapcode ) obj ;
325- return mapcodePrecision0 .equals (that .mapcodePrecision0 ) && (this .territory .equals (that .territory ));
357+ return mapcodePrecision0 .equals (that .mapcodePrecision0 ) &&
358+ mapcodePrecision1 .equals (that .mapcodePrecision1 ) &&
359+ mapcodePrecision2 .equals (that .mapcodePrecision2 ) &&
360+ (this .territory .equals (that .territory ));
326361 }
327362}
0 commit comments