2121
2222import javax .annotation .Nonnull ;
2323
24- import static com .mapcode .Boundary .createFromTerritoryRecord ;
24+ import static com .mapcode .Boundary .createBoundaryForTerritoryRecord ;
2525
2626class Decoder {
2727 private static final Logger LOG = LoggerFactory .getLogger (Decoder .class );
@@ -93,7 +93,7 @@ static Point decode(@Nonnull final String argMapcode,
9393
9494 for (int territoryRecord = fromTerritoryRecord ; territoryRecord <= uptoTerritoryRecord ; territoryRecord ++) {
9595 final int codexi = Data .getCodex (territoryRecord );
96- Boundary boundary = createFromTerritoryRecord (territoryRecord );
96+ final Boundary boundary = createBoundaryForTerritoryRecord (territoryRecord );
9797 if (Data .getTerritoryRecordType (territoryRecord ) == Data .TERRITORY_RECORD_TYPE_NONE ) {
9898 if (Data .isNameless (territoryRecord )) {
9999 // i = nameless
@@ -113,16 +113,16 @@ static Point decode(@Nonnull final String argMapcode,
113113 territoryRecord , extrapostfix );
114114
115115 // first of all, make sure the zone fits the country
116- mapcodeZone = mapcodeZone .restrictZoneTo (createFromTerritoryRecord (uptoTerritoryRecord ));
116+ mapcodeZone = mapcodeZone .restrictZoneTo (createBoundaryForTerritoryRecord (uptoTerritoryRecord ));
117117
118118 if (Data .isRestricted (territoryRecord ) && !mapcodeZone .isEmpty ()) {
119119 int nrZoneOverlaps = 0 ;
120120 int j ;
121- Point result = mapcodeZone .getMidPoint ();
121+ final Point result = mapcodeZone .getMidPoint ();
122122 // see if midpoint of mapcode zone is in any sub-area...
123123 for (j = territoryRecord - 1 ; j >= fromTerritoryRecord ; j --) {
124124 if (!Data .isRestricted (j )) {
125- if (createFromTerritoryRecord (j ).containsPoint (result )) {
125+ if (createBoundaryForTerritoryRecord (j ).containsPoint (result )) {
126126 nrZoneOverlaps ++;
127127 break ;
128128 }
@@ -131,10 +131,10 @@ static Point decode(@Nonnull final String argMapcode,
131131
132132 if (nrZoneOverlaps == 0 ) {
133133 // see if mapcode zone OVERLAPS any sub-area...
134- MapcodeZone zfound = MapcodeZone .empty ();
134+ final MapcodeZone zfound = MapcodeZone .empty ();
135135 for (j = fromTerritoryRecord ; j < territoryRecord ; j ++) { // try all smaller rectangles j
136136 if (!Data .isRestricted (j )) {
137- MapcodeZone z = mapcodeZone .restrictZoneTo (createFromTerritoryRecord (j ));
137+ final MapcodeZone z = mapcodeZone .restrictZoneTo (createBoundaryForTerritoryRecord (j ));
138138 if (!z .isEmpty ()) {
139139 nrZoneOverlaps ++;
140140 if (nrZoneOverlaps == 1 ) {
@@ -177,7 +177,7 @@ static Point decode(@Nonnull final String argMapcode,
177177 }
178178 }
179179
180- mapcodeZone = mapcodeZone .restrictZoneTo (createFromTerritoryRecord (uptoTerritoryRecord ));
180+ mapcodeZone = mapcodeZone .restrictZoneTo (createBoundaryForTerritoryRecord (uptoTerritoryRecord ));
181181
182182 final Point result = mapcodeZone .getMidPoint ();
183183
@@ -308,8 +308,14 @@ public Unicode2Ascii(final char min, final char max, @Nonnull final String conve
308308 };
309309
310310 @ Nonnull
311- private static MapcodeZone decodeGrid (final String str , final int minx , final int miny , final int maxx , final int maxy ,
312- final int m , final String extrapostfix ) {
311+ private static MapcodeZone decodeGrid (
312+ @ Nonnull final String str ,
313+ final int minx ,
314+ final int miny ,
315+ final int maxx ,
316+ final int maxy ,
317+ final int m ,
318+ @ Nonnull final String extrapostfix ) {
313319 // for a well-formed result, and integer variables
314320 String result = str ;
315321 int relx ;
@@ -384,9 +390,9 @@ private static MapcodeZone decodeGrid(final String str, final int minx, final in
384390 final int cornery = rely + (dify * dividery );
385391 final int cornerx = relx + (difx * dividerx );
386392
387- Point pt = Point .fromMicroDeg (cornery , cornerx );
388- if (!(createFromTerritoryRecord (m ).containsPoint (pt ))) {
389- LOG .info ("decodeGrid: Failed decodeGrid({}): {} not in {}" , str , pt , createFromTerritoryRecord (m ));
393+ final Point pt = Point .fromMicroDeg (cornery , cornerx );
394+ if (!(createBoundaryForTerritoryRecord (m ).containsPoint (pt ))) {
395+ LOG .info ("decodeGrid: Failed decodeGrid({}): {} not in {}" , str , pt , createBoundaryForTerritoryRecord (m ));
390396 return MapcodeZone .empty (); // already out of range
391397 }
392398
@@ -397,7 +403,10 @@ private static MapcodeZone decodeGrid(final String str, final int minx, final in
397403 }
398404
399405 @ Nonnull
400- private static MapcodeZone decodeNameless (final String str , final int firstrec , final String extrapostfix ) {
406+ private static MapcodeZone decodeNameless (
407+ @ Nonnull final String str ,
408+ final int firstrec ,
409+ @ Nonnull final String extrapostfix ) {
401410 String result = str ;
402411 final int codexm = Data .getCodex (firstrec );
403412 if (codexm == 22 ) {
@@ -406,7 +415,7 @@ private static MapcodeZone decodeNameless(final String str, final int firstrec,
406415 result = result .substring (0 , 2 ) + result .substring (3 );
407416 }
408417
409- int a = Common .countCityCoordinatesForCountry (codexm , firstrec , firstrec );
418+ final int a = Common .countCityCoordinatesForCountry (codexm , firstrec , firstrec );
410419
411420 final int p = 31 / a ;
412421 final int r = 31 % a ;
@@ -472,7 +481,7 @@ private static MapcodeZone decodeNameless(final String str, final int firstrec,
472481 int side = dataModel .getSmartDiv (territoryRecord );
473482 int xSIDE = side ;
474483
475- Boundary boundary = createFromTerritoryRecord (territoryRecord );
484+ final Boundary boundary = createBoundaryForTerritoryRecord (territoryRecord );
476485 final int maxx = boundary .getLonMicroDegMax ();
477486 final int maxy = boundary .getLatMicroDegMax ();
478487 final int minx = boundary .getLonMicroDegMin ();
@@ -510,7 +519,10 @@ private static MapcodeZone decodeNameless(final String str, final int firstrec,
510519 }
511520
512521 @ Nonnull
513- private static MapcodeZone decodeAutoHeader (final String input , final int m , final String extrapostfix ) {
522+ private static MapcodeZone decodeAutoHeader (
523+ final String input ,
524+ final int m ,
525+ @ Nonnull final String extrapostfix ) {
514526 // returns Point.isUndefined() in case or error
515527 int storageStart = 0 ;
516528 final int codexm = Data .getCodex (m );
@@ -528,10 +540,10 @@ private static MapcodeZone decodeAutoHeader(final String input, final int m, fin
528540 return MapcodeZone .empty (); // return undefined
529541 }
530542
531- final int maxx = createFromTerritoryRecord (i ).getLonMicroDegMax ();
532- final int maxy = createFromTerritoryRecord (i ).getLatMicroDegMax ();
533- final int minx = createFromTerritoryRecord (i ).getLonMicroDegMin ();
534- final int miny = createFromTerritoryRecord (i ).getLatMicroDegMin ();
543+ final int maxx = createBoundaryForTerritoryRecord (i ).getLonMicroDegMax ();
544+ final int maxy = createBoundaryForTerritoryRecord (i ).getLatMicroDegMax ();
545+ final int minx = createBoundaryForTerritoryRecord (i ).getLonMicroDegMin ();
546+ final int miny = createBoundaryForTerritoryRecord (i ).getLatMicroDegMin ();
535547
536548 int h = ((maxy - miny ) + 89 ) / 90 ;
537549 final int xdiv = Common .xDivider (miny , maxy );
@@ -576,7 +588,7 @@ private static MapcodeZone decodeAutoHeader(final String input, final int m, fin
576588 }
577589
578590 @ Nonnull
579- private static String aeuUnpack (final String argStr ) {
591+ private static String aeuUnpack (@ Nonnull final String argStr ) {
580592 // unpack encoded into all-digit
581593 // (assume str already uppercase!), returns "" in case of error
582594 String str = decodeUTF16 (argStr );
@@ -663,7 +675,8 @@ private static String aeuUnpack(final String argStr) {
663675 * @param mapcode Unicode string.
664676 * @return ASCII string.
665677 */
666- static String decodeUTF16 (final String mapcode ) {
678+ @ Nonnull
679+ static String decodeUTF16 (@ Nonnull final String mapcode ) {
667680 String result ;
668681 final StringBuilder asciiBuf = new StringBuilder ();
669682 for (final char ch : mapcode .toCharArray ()) {
@@ -706,7 +719,10 @@ static String decodeUTF16(final String mapcode) {
706719 }
707720 }
708721
709- static String encodeUTF16 (final String mapcodeInput , final int alphabetCode ) throws IllegalArgumentException {
722+ @ Nonnull
723+ static String encodeUTF16 (
724+ @ Nonnull final String mapcodeInput ,
725+ final int alphabetCode ) throws IllegalArgumentException {
710726
711727 final String mapcode ;
712728 if ((alphabetCode == Alphabet .GREEK .getNumber ()) ||
@@ -747,7 +763,7 @@ static String encodeUTF16(final String mapcodeInput, final int alphabetCode) thr
747763 }
748764
749765 @ Nonnull
750- private static Point decodeTriple (final String str ) {
766+ private static Point decodeTriple (@ Nonnull final String str ) {
751767 final int c1 = DECODE_CHARS [(int ) str .charAt (0 )];
752768 final int x = decodeBase31 (str .substring (1 ));
753769 if (c1 < 24 ) {
@@ -757,8 +773,11 @@ private static Point decodeTriple(final String str) {
757773 }
758774
759775 @ Nonnull
760- private static Point decodeSixWide (final int v , final int width , final int height ) {
761- int d ;
776+ private static Point decodeSixWide (
777+ final int v ,
778+ final int width ,
779+ final int height ) {
780+ final int d ;
762781 int col = v / (height * 6 );
763782 final int maxcol = (width - 4 ) / 6 ;
764783 if (col >= maxcol ) {
@@ -774,7 +793,7 @@ private static Point decodeSixWide(final int v, final int width, final int heigh
774793 // / lowest level encode/decode routines
775794 // decode up to dot or EOS;
776795 // returns negative in case of error
777- private static int decodeBase31 (final String code ) {
796+ private static int decodeBase31 (@ Nonnull final String code ) {
778797 int value = 0 ;
779798 for (final char c : code .toCharArray ()) {
780799 if (c == '.' ) {
@@ -789,9 +808,16 @@ private static int decodeBase31(final String code) {
789808 }
790809
791810 @ Nonnull
792- private static MapcodeZone decodeExtension (final int y , final int x , final int dividerx0 , final int dividery0 ,
793- final String extrapostfix , final int lon_offset4 , final int extremeLatMicroDeg , final int maxLonMicroDeg ) {
794- MapcodeZone mapcodeZone = new MapcodeZone ();
811+ private static MapcodeZone decodeExtension (
812+ final int y ,
813+ final int x ,
814+ final int dividerx0 ,
815+ final int dividery0 ,
816+ @ Nonnull final String extrapostfix ,
817+ final int lon_offset4 ,
818+ final int extremeLatMicroDeg ,
819+ final int maxLonMicroDeg ) {
820+ final MapcodeZone mapcodeZone = new MapcodeZone ();
795821 double dividerx4 = (double ) dividerx0 ;
796822 double dividery = (double ) dividery0 ;
797823 double processor = 1 ;
@@ -840,8 +866,8 @@ private static MapcodeZone decodeExtension(final int y, final int x, final int d
840866 processor *= 30 ;
841867 }
842868
843- double lon4 = (x * 4 * Point .MAX_PRECISION_FACTOR ) + (lon32 * dividerx4 ) + (lon_offset4 * Point .MAX_PRECISION_FACTOR );
844- double lat1 = (y * Point .MAX_PRECISION_FACTOR ) + (lat32 * dividery );
869+ final double lon4 = (x * 4 * Point .MAX_PRECISION_FACTOR ) + (lon32 * dividerx4 ) + (lon_offset4 * Point .MAX_PRECISION_FACTOR );
870+ final double lat1 = (y * Point .MAX_PRECISION_FACTOR ) + (lat32 * dividery );
845871
846872 // determine the range of coordinates that are encode to this mapcode
847873 if (odd ) { // odd
@@ -866,9 +892,9 @@ private static MapcodeZone decodeExtension(final int y, final int x, final int d
866892 return mapcodeZone ;
867893 }
868894
869- private static boolean isAbjadScript (final String argStr ) {
895+ private static boolean isAbjadScript (@ Nonnull final String argStr ) {
870896 for (final char ch : argStr .toCharArray ()) {
871- int c = (int ) ch ;
897+ final int c = (int ) ch ;
872898 if ((c >= 0x0628 ) && (c <= 0x0649 )) {
873899 return true ; // Arabic
874900 }
@@ -878,14 +904,15 @@ private static boolean isAbjadScript(final String argStr) {
878904 if ((c >= 0x388 ) && (c <= 0x3C9 )) {
879905 return true ; // Greek uppercase and lowecase
880906 }
881- if ((c >= 0x1100 ) && (c <= 0x1174 ) || (c >= 0xad6c ) && (c <= 0xd314 )) {
907+ if ((( c >= 0x1100 ) && (c <= 0x1174 )) || (( c >= 0xad6c ) && (c <= 0xd314 ) )) {
882908 return true ; // Korean
883909 }
884910 }
885911 return false ;
886912 }
887913
888- private static String convertFromAbjad (final String mapcode ) {
914+ @ Nonnull
915+ private static String convertFromAbjad (@ Nonnull final String mapcode ) {
889916 // split into prefix, s, postfix
890917 int p = mapcode .lastIndexOf (' ' );
891918 if (p < 0 ) {
@@ -894,7 +921,7 @@ private static String convertFromAbjad(final String mapcode) {
894921 p ++;
895922 }
896923 final String prefix = mapcode .substring (0 , p );
897- String remainder = mapcode .substring (p );
924+ final String remainder = mapcode .substring (p );
898925 final String postfix ;
899926 final int h = remainder .indexOf ('-' );
900927 final String s ;
@@ -961,7 +988,8 @@ private static String convertFromAbjad(final String mapcode) {
961988 }
962989
963990 @ SuppressWarnings ("NumericCastThatLosesPrecision" )
964- private static String convertToAbjad (final String mapcode ) {
991+ @ Nonnull
992+ private static String convertToAbjad (@ Nonnull final String mapcode ) {
965993 String str ;
966994 final String rest ;
967995 final int h = mapcode .indexOf ('-' );
0 commit comments