@@ -76,8 +76,8 @@ public final class Mapcode {
7676 * territory information.
7777 */
7878 public Mapcode (
79- @ Nonnull final String code ,
80- @ Nonnull final Territory territory ) throws IllegalArgumentException {
79+ @ Nonnull final String code ,
80+ @ Nonnull final Territory territory ) throws IllegalArgumentException {
8181
8282 checkMapcodeCode ("code" , code );
8383 final String ascii = convertStringToPlainAscii (code );
@@ -90,17 +90,20 @@ public Mapcode(
9090 final int hyphenPos = codeUppercase .indexOf ('-' );
9191 if (hyphenPos < 0 ) {
9292 codeUppercase = codeUppercase + "-K3000000" ;
93- } else {
93+ }
94+ else {
9495 final int extensionLength = codeUppercase .length () - 1 - hyphenPos ;
9596 if (extensionLength < 8 ) {
9697 if ((extensionLength % 2 ) == 1 ) {
9798 // Odd extension.
9899 codeUppercase = codeUppercase + ("HH000000" .substring (0 , 8 - extensionLength ));
99- } else {
100+ }
101+ else {
100102 // Even extension.
101103 codeUppercase = codeUppercase + ("K3000000" .substring (0 , 8 - extensionLength ));
102104 }
103- } else if (extensionLength > 8 ) {
105+ }
106+ else if (extensionLength > 8 ) {
104107 // Cut to 8 characters.
105108 codeUppercase = codeUppercase .substring (0 , hyphenPos + 9 );
106109 }
@@ -154,9 +157,12 @@ public String getCode() {
154157 public String getCode (final int precision , @ Nullable final Alphabet alphabet ) {
155158 if (precision == 0 ) {
156159 return convertStringToAlphabet (codePrecision8 .substring (0 , codePrecision8 .length () - 9 ), alphabet );
157- } else if (precision <= 8 ) {
158- return convertStringToAlphabet (codePrecision8 .substring (0 , (codePrecision8 .length () - 8 ) + precision ), alphabet );
159- } else {
160+ }
161+ else if (precision <= 8 ) {
162+ return convertStringToAlphabet (codePrecision8 .substring (0 , (codePrecision8 .length () - 8 ) + precision ),
163+ alphabet );
164+ }
165+ else {
160166 throw new IllegalArgumentException ("getCodePrecision: precision must be in [0, 8]" );
161167 }
162168 }
@@ -250,11 +256,11 @@ public Territory getTerritory() {
250256 * provided as statics to only compile these patterns once.
251257 */
252258 @ Nonnull
253- static final String REGEX_TERRITORY = "[\\ p{L}\\ p{N}]{2,3}+([-_][\\ p{L}\\ p{N}]{2,3}+)?" ;
259+ static final String REGEX_TERRITORY = "[\\ p{L}\\ p{N}]{2,3}+([-_][\\ p{L}\\ p{N}]{2,3}+)?" ;
254260 @ Nonnull
255- static final String REGEX_CODE_PREFIX = "[\\ p{L}\\ p{N}]{2,5}+" ;
261+ static final String REGEX_CODE_PREFIX = "[\\ p{L}\\ p{N}]{2,5}+" ;
256262 @ Nonnull
257- static final String REGEX_CODE_POSTFIX = "[\\ p{L}\\ p{N}]{2,4}+" ;
263+ static final String REGEX_CODE_POSTFIX = "[\\ p{L}\\ p{N}]{2,4}+" ;
258264 @ Nonnull
259265 static final String REGEX_CODE_PRECISION = "[-][\\ p{L}\\ p{N}&&[^zZ]]{1,8}+" ;
260266
@@ -264,10 +270,10 @@ public Territory getTerritory() {
264270 */
265271 @ Nonnull
266272 public static final String REGEX_MAPCODE = '(' + REGEX_TERRITORY + "[ ]+)?" +
267- REGEX_CODE_PREFIX + "[.]" + REGEX_CODE_POSTFIX + '(' + REGEX_CODE_PRECISION + ")?" ;
273+ REGEX_CODE_PREFIX + "[.]" + REGEX_CODE_POSTFIX + '(' + REGEX_CODE_PRECISION + ")?" ;
268274
269275 @ Nonnull
270- static final Pattern PATTERN_MAPCODE = Pattern .compile ('^' + REGEX_MAPCODE + '$' );
276+ static final Pattern PATTERN_MAPCODE = Pattern .compile ('^' + REGEX_MAPCODE + '$' );
271277 @ Nonnull
272278 static final Pattern PATTERN_TERRITORY = Pattern .compile ('^' + REGEX_TERRITORY + ' ' );
273279 @ Nonnull
@@ -292,7 +298,7 @@ public static int getPrecisionFormat(@Nonnull final String mapcode) throws Unkno
292298 // Syntax needs to be OK.
293299 if (!PATTERN_MAPCODE .matcher (decodedMapcode ).matches ()) {
294300 throw new UnknownPrecisionFormatException (decodedMapcode + " is not a correctly formatted mapcode code; " +
295- "the regular expression for the mapcode code syntax is: " + REGEX_MAPCODE );
301+ "the regular expression for the mapcode code syntax is: " + REGEX_MAPCODE );
296302 }
297303
298304 // Precision part should be OK.
@@ -319,7 +325,8 @@ public static boolean isValidMapcodeFormat(@Nonnull final String mapcode) throws
319325 // Throws an exception if the format is incorrect.
320326 getPrecisionFormat (mapcode .toUpperCase ());
321327 return true ;
322- } catch (final UnknownPrecisionFormatException ignored ) {
328+ }
329+ catch (final UnknownPrecisionFormatException ignored ) {
323330 return false ;
324331 }
325332 }
@@ -341,15 +348,15 @@ public static boolean containsTerritory(@Nonnull final String mapcode) throws Il
341348 * location used for encoding the mapcode.
342349 */
343350 private static final double [] PRECISION_0_MAX_OFFSET_METERS = {
344- 7.49 , // PRECISION_0: 7.49 meters or less 7.5 m
345- 1.39 , // PRECISION_1: 1.39 meters or less 1.4 m
346- 0.251 , // PRECISION_2: 25.1 cm or less 25 cm
347- 0.0462 , // PRECISION_3: 4.62 cm or less 5 cm
348- 0.00837 , // PRECISION_4: 8.37 mm or less 1 cm
349- 0.00154 , // PRECISION_5: 1.54 mm or less 2 mm
350- 0.000279 , // PRECISION_6: 279 micrometer or less 1/3 mm
351- 0.0000514 , // PRECISION_7: 51.4 micrometer or less 1/20 mm
352- 0.0000093 // PRECISION_8: 9.3 micrometer or less 1/100 mm
351+ 7.49 , // PRECISION_0: 7.49 meters or less 7.5 m
352+ 1.39 , // PRECISION_1: 1.39 meters or less 1.4 m
353+ 0.251 , // PRECISION_2: 25.1 cm or less 25 cm
354+ 0.0462 , // PRECISION_3: 4.62 cm or less 5 cm
355+ 0.00837 , // PRECISION_4: 8.37 mm or less 1 cm
356+ 0.00154 , // PRECISION_5: 1.54 mm or less 2 mm
357+ 0.000279 , // PRECISION_6: 279 micrometer or less 1/3 mm
358+ 0.0000514 , // PRECISION_7: 51.4 micrometer or less 1/20 mm
359+ 0.0000093 // PRECISION_8: 9.3 micrometer or less 1/100 mm
353360 };
354361
355362 /**
@@ -392,7 +399,8 @@ static String convertStringToPlainAscii(@Nonnull final String string) {
392399 */
393400 @ Nonnull
394401 static String convertStringToAlphabet (@ Nonnull final String string , @ Nullable final Alphabet alphabet ) throws IllegalArgumentException {
395- return (alphabet != null ) ? Decoder .encodeUTF16 (string .toUpperCase (), alphabet .getNumber ()) : string .toUpperCase ();
402+ return (alphabet != null ) ? Decoder .encodeUTF16 (string .toUpperCase (), alphabet .getNumber ()) :
403+ string .toUpperCase ();
396404 }
397405
398406 /**
@@ -421,7 +429,7 @@ public boolean equals(@Nullable final Object o) {
421429 return false ;
422430 }
423431 final Mapcode that = (Mapcode ) o ;
424- return this .codePrecision8 .equals (that .codePrecision8 ) &&
425- ( this .territory .equals (that .territory ) );
432+ return this .territory .equals (that .territory ) &&
433+ this .codePrecision8 .equals (that .codePrecision8 );
426434 }
427435}
0 commit comments