-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDecoder.java.html
More file actions
1121 lines (1002 loc) · 85.7 KB
/
Decoder.java.html
File metadata and controls
1121 lines (1002 loc) · 85.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Decoder.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Mapcode Java Library</a> > <a href="index.source.html" class="el_package">com.mapcode</a> > <span class="el_source">Decoder.java</span></div><h1>Decoder.java</h1><pre class="source lang-java linenums">/*
* Copyright (C) 2014-2017, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mapcode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import static com.mapcode.Boundary.createBoundaryForTerritoryRecord;
// ----------------------------------------------------------------------------------------------
// Package private implementation class. For internal use within the mapcode implementation only.
//----------------------------------------------------------------------------------------------
/**
* This class contains decoder for mapcodes.
*/
<span class="pc bpc" id="L33" title="1 of 2 branches missed.">@SuppressWarnings({"MagicNumber", "StringConcatenationMissingWhitespace"})</span>
final class Decoder {
<span class="fc" id="L35"> private static final Logger LOG = LoggerFactory.getLogger(Decoder.class);</span>
// Get direct access to the data model singleton.
<span class="fc" id="L38"> private static final DataModel DATA_MODEL = DataModel.getInstance();</span>
private Decoder() {
// Prevent instantiation.
}
// ----------------------------------------------------------------------
// Method called from public Java API.
// ----------------------------------------------------------------------
@Nonnull
static MapcodeZone decodeToMapcodeZone(@Nonnull final String argMapcode,
@Nonnull final Territory argTerritory)
throws UnknownMapcodeException {
<span class="fc" id="L52"> LOG.trace("decode: mapcode={}, territory={}", argMapcode, argTerritory.name());</span>
<span class="fc" id="L54"> String mapcode = argMapcode;</span>
<span class="fc" id="L55"> Territory territory = argTerritory;</span>
<span class="fc" id="L57"> String precisionPostfix = "";</span>
<span class="fc" id="L58"> final int positionOfDash = mapcode.indexOf('-');</span>
<span class="fc bfc" id="L59" title="All 2 branches covered."> if (positionOfDash > 0) {</span>
<span class="fc" id="L60"> precisionPostfix = decodeUTF16(mapcode.substring(positionOfDash + 1).trim());</span>
<span class="pc bpc" id="L61" title="1 of 2 branches missed."> if (precisionPostfix.contains("Z")) {</span>
<span class="nc" id="L62"> throw new UnknownMapcodeException("Invalid character Z, mapcode=" + argMapcode + ", territory=" + argTerritory);</span>
}
// Cut the precision postfix from the mapcode.
<span class="fc" id="L66"> mapcode = mapcode.substring(0, positionOfDash);</span>
}
<span class="pc bpc" id="L68" title="2 of 4 branches missed."> assert !mapcode.contains("-");</span>
// TODO: Explain what AEU unpack does.
<span class="fc" id="L71"> mapcode = aeuUnpack(mapcode).trim();</span>
<span class="pc bpc" id="L72" title="1 of 2 branches missed."> if (mapcode.isEmpty()) {</span>
// TODO: Is this a useful log message?
<span class="nc" id="L74"> LOG.debug("decode: Failed to aeuUnpack {}", argMapcode);</span>
<span class="nc" id="L75"> throw new UnknownMapcodeException("Failed to AEU unpack, mapcode=" + argMapcode + ", territory=" + argTerritory);</span>
}
<span class="fc" id="L78"> final int codexLen = mapcode.length() - 1;</span>
// *** long codes in states are handled by the country
<span class="fc bfc" id="L81" title="All 2 branches covered."> if (codexLen >= 9) {</span>
// International codes are 9 characters.
<span class="pc bpc" id="L83" title="2 of 4 branches missed."> assert codexLen == 9;</span>
<span class="fc" id="L84"> territory = Territory.AAA;</span>
} else {
<span class="fc" id="L86"> final Territory parentTerritory = territory.getParentTerritory();</span>
<span class="fc bfc" id="L87" title="All 20 branches covered."> if (((codexLen >= 8) &&</span>
((parentTerritory == Territory.USA) || (parentTerritory == Territory.CAN) ||
(parentTerritory == Territory.AUS) || (parentTerritory == Territory.BRA) ||
(parentTerritory == Territory.CHN) || (parentTerritory == Territory.RUS))) ||
((codexLen >= 7) &&
((parentTerritory == Territory.IND) || (parentTerritory == Territory.MEX)))) {
<span class="fc" id="L93"> territory = parentTerritory;</span>
}
}
<span class="fc" id="L96"> final int territoryNumber = territory.getNumber();</span>
<span class="fc" id="L98"> final int fromTerritoryRecord = DATA_MODEL.getDataFirstRecord(territoryNumber);</span>
<span class="fc" id="L99"> final int uptoTerritoryRecord = DATA_MODEL.getDataLastRecord(territoryNumber);</span>
// Determine the codex pattern as 2-digits: length-of-left-part * 10 + length-of-right-part.
<span class="fc" id="L102"> final int positionOfDot = mapcode.indexOf('.');</span>
<span class="fc" id="L103"> final int codex = (positionOfDot * 10) + (codexLen - positionOfDot);</span>
<span class="fc" id="L105"> MapcodeZone mapcodeZone = new MapcodeZone();</span>
<span class="fc bfc" id="L106" title="All 2 branches covered."> for (int territoryRecord = fromTerritoryRecord; territoryRecord <= uptoTerritoryRecord; territoryRecord++) {</span>
<span class="fc" id="L107"> final int codexOfTerritory = Data.getCodex(territoryRecord);</span>
<span class="fc" id="L108"> final Boundary boundaryOfTerritory = createBoundaryForTerritoryRecord(territoryRecord);</span>
<span class="fc bfc" id="L109" title="All 2 branches covered."> if (Data.getTerritoryRecordType(territoryRecord) == Data.TERRITORY_RECORD_TYPE_NONE) {</span>
<span class="fc bfc" id="L111" title="All 2 branches covered."> if (Data.isNameless(territoryRecord)) {</span>
// i = nameless
<span class="fc bfc" id="L113" title="All 12 branches covered."> if (((codexOfTerritory == 21) && (codex == 22)) ||</span>
((codexOfTerritory == 22) && (codex == 32)) ||
((codexOfTerritory == 13) && (codex == 23))) {
<span class="fc" id="L116"> mapcodeZone = decodeNameless(mapcode, territoryRecord, precisionPostfix);</span>
<span class="fc" id="L117"> break;</span>
}
} else {
// i = grid without headerletter
<span class="pc bpc" id="L122" title="1 of 6 branches missed."> if ((codexOfTerritory == codex) ||</span>
((codex == 22) && (codexOfTerritory == 21))) {
<span class="fc" id="L125"> mapcodeZone = decodeGrid(mapcode,</span>
<span class="fc" id="L126"> boundaryOfTerritory.getLonMicroDegMin(), boundaryOfTerritory.getLatMicroDegMin(),</span>
<span class="fc" id="L127"> boundaryOfTerritory.getLonMicroDegMax(), boundaryOfTerritory.getLatMicroDegMax(),</span>
territoryRecord, precisionPostfix);
// first of all, make sure the zone fits the country
<span class="fc" id="L131"> mapcodeZone = mapcodeZone.restrictZoneTo(createBoundaryForTerritoryRecord(uptoTerritoryRecord));</span>
<span class="fc bfc" id="L133" title="All 4 branches covered."> if (Data.isRestricted(territoryRecord) && !mapcodeZone.isEmpty()) {</span>
<span class="fc" id="L134"> int nrZoneOverlaps = 0;</span>
int j;
<span class="fc" id="L136"> final Point result = mapcodeZone.getCenter();</span>
// see if midpoint of mapcode zone is in any sub-area...
<span class="fc bfc" id="L138" title="All 2 branches covered."> for (j = territoryRecord - 1; j >= fromTerritoryRecord; j--) {</span>
<span class="pc bpc" id="L139" title="1 of 2 branches missed."> if (!Data.isRestricted(j)) {</span>
<span class="fc bfc" id="L140" title="All 2 branches covered."> if (createBoundaryForTerritoryRecord(j).containsPoint(result)) {</span>
<span class="fc" id="L141"> nrZoneOverlaps++;</span>
<span class="fc" id="L142"> break;</span>
}
}
}
<span class="fc bfc" id="L147" title="All 2 branches covered."> if (nrZoneOverlaps == 0) {</span>
// see if mapcode zone OVERLAPS any sub-area...
<span class="fc" id="L149"> MapcodeZone zfound = new MapcodeZone();</span>
<span class="fc bfc" id="L150" title="All 2 branches covered."> for (j = fromTerritoryRecord; j < territoryRecord; j++) { // try all smaller rectangles j</span>
<span class="pc bpc" id="L151" title="1 of 2 branches missed."> if (!Data.isRestricted(j)) {</span>
<span class="fc" id="L152"> final MapcodeZone z = mapcodeZone.restrictZoneTo(createBoundaryForTerritoryRecord(j));</span>
<span class="fc bfc" id="L153" title="All 2 branches covered."> if (!z.isEmpty()) {</span>
<span class="fc" id="L154"> nrZoneOverlaps++;</span>
<span class="fc bfc" id="L155" title="All 2 branches covered."> if (nrZoneOverlaps == 1) {</span>
// first fit! remember...
<span class="fc" id="L157"> zfound = new MapcodeZone(z);</span>
} else { // nrZoneOverlaps > 1
// more than one hit
break; // give up!
}
}
}
}
<span class="fc bfc" id="L165" title="All 2 branches covered."> if (nrZoneOverlaps == 1) { // intersected exactly ONE sub-area?</span>
<span class="fc" id="L166"> mapcodeZone = new MapcodeZone(zfound); // use the intersection found...</span>
}
}
<span class="fc bfc" id="L170" title="All 2 branches covered."> if (nrZoneOverlaps == 0) {</span>
<span class="fc" id="L171"> mapcodeZone = new MapcodeZone();</span>
}
<span class="fc" id="L173"> }</span>
break;
}
}
<span class="fc bfc" id="L177" title="All 2 branches covered."> } else if (Data.getTerritoryRecordType(territoryRecord) == Data.TERRITORY_RECORD_TYPE_PIPE) {</span>
// i = grid with headerletter
<span class="fc bfc" id="L179" title="All 2 branches covered."> if ((codex == (codexOfTerritory + 10)) &&</span>
<span class="fc bfc" id="L180" title="All 2 branches covered."> (Data.headerLetter(territoryRecord).charAt(0) == mapcode.charAt(0))) {</span>
<span class="fc" id="L181"> mapcodeZone = decodeGrid(mapcode.substring(1),</span>
<span class="fc" id="L182"> boundaryOfTerritory.getLonMicroDegMin(), boundaryOfTerritory.getLatMicroDegMin(),</span>
<span class="fc" id="L183"> boundaryOfTerritory.getLonMicroDegMax(), boundaryOfTerritory.getLatMicroDegMax(),</span>
territoryRecord, precisionPostfix);
<span class="fc" id="L185"> break;</span>
}
} else {
<span class="pc bpc" id="L188" title="1 of 4 branches missed."> assert (Data.getTerritoryRecordType(territoryRecord) == Data.TERRITORY_RECORD_TYPE_PLUS) ||</span>
<span class="pc bpc" id="L189" title="1 of 2 branches missed."> (Data.getTerritoryRecordType(territoryRecord) == Data.TERRITORY_RECORD_TYPE_STAR);</span>
// i = autoheader
<span class="pc bpc" id="L191" title="1 of 8 branches missed."> if (((codex == 23) && (codexOfTerritory == 22)) ||</span>
((codex == 33) && (codexOfTerritory == 23))) {
<span class="fc" id="L193"> mapcodeZone = decodeAutoHeader(mapcode, territoryRecord, precisionPostfix);</span>
<span class="fc" id="L194"> break;</span>
}
}
}
<span class="fc" id="L199"> mapcodeZone = mapcodeZone.restrictZoneTo(createBoundaryForTerritoryRecord(uptoTerritoryRecord));</span>
<span class="fc" id="L200"> LOG.trace("decode: zone={}", mapcodeZone);</span>
<span class="fc" id="L201"> return mapcodeZone;</span>
}
// ----------------------------------------------------------------------
// Private methods.
// ----------------------------------------------------------------------
<span class="fc" id="L208"> private final static int[] DECODE_CHARS = {</span>
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
-1, -2, 10, 11, 12, -3, 13, 14, 15, 1, 16, 17, 18, 19, 20, 0,
21, 22, 23, 24, 25, -4, 26, 27, 28, 29, 30, -1, -1, -1, -1, -1,
-1, -2, 10, 11, 12, -3, 13, 14, 15, 1, 16, 17, 18, 19, 20, 0,
21, 22, 23, 24, 25, -4, 26, 27, 28, 29, 30, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
private static class Unicode2Ascii {
final char min;
final char max;
@Nonnull
final String convert;
<span class="fc" id="L234"> Unicode2Ascii(final char min, final char max, @Nonnull final String convert) {</span>
<span class="fc" id="L235"> this.min = min;</span>
<span class="fc" id="L236"> this.max = max;</span>
<span class="fc" id="L237"> this.convert = convert;</span>
<span class="fc" id="L238"> }</span>
}
// Greek character A.
private static final char GREEK_CAPITAL_ALPHA = '\u0391';
// Special character '?' indicating missing character in alphabet.
private static final char MISSCODE = '?';
// @formatter:off
<span class="fc" id="L248"> @SuppressWarnings("LongLine") private final static char[][] ASCII2LANGUAGE = {</span>
// Character: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9
/* Roman */ {'\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004a', '\u004b', '\u004c', '\u004d', '\u004e', '\u004f', '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005a', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Roman
/* Greek */ {'\u0391', '\u0392', '\u039e', '\u0394', '\u0388', '\u0395', '\u0393', '\u0397', '\u0399', '\u03a0', '\u039a', '\u039b', '\u039c', '\u039d', '\u039f', '\u03a1', '\u0398', '\u03a8', '\u03a3', '\u03a4', '\u0389', '\u03a6', '\u03a9', '\u03a7', '\u03a5', '\u0396', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Greek
/* Cyrillic */ {'\u0410', '\u0412', '\u0421', '\u0414', '\u0415', '\u0416', '\u0413', '\u041d', '\u0418', '\u041f', '\u041a', '\u041b', '\u041c', '\u0417', '\u041e', '\u0420', '\u0424', '\u042f', '\u0426', '\u0422', '\u042d', '\u0427', '\u0428', '\u0425', '\u0423', '\u0411', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Cyrillic
/* Hebrew */ {'\u05d0', '\u05d1', '\u05d2', '\u05d3', '\u05e3', '\u05d4', '\u05d6', '\u05d7', '\u05d5', '\u05d8', '\u05d9', '\u05da', '\u05db', '\u05dc', '\u05e1', '\u05dd', '\u05de', '\u05e0', '\u05e2', '\u05e4', '\u05e5', '\u05e6', '\u05e7', '\u05e8', '\u05e9', '\u05ea', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Hebrew
/* Devanag. */ {'\u0905', '\u0915', '\u0917', '\u0918', '\u090f', '\u091a', '\u091c', '\u091f', MISSCODE, '\u0920', '\u0923', '\u0924', '\u0926', '\u0927', MISSCODE, '\u0928', '\u092a', '\u092d', '\u092e', '\u0930', '\u092b', '\u0932', '\u0935', '\u0938', '\u0939', '\u092c', '\u0966', '\u0967', '\u0968', '\u0969', '\u096a', '\u096b', '\u096c', '\u096d', '\u096e', '\u096f'}, // Devanagiri
/* Malay */ {'\u0d12', '\u0d15', '\u0d16', '\u0d17', '\u0d0b', '\u0d1a', '\u0d1c', '\u0d1f', '\u0d07', '\u0d21', '\u0d24', '\u0d25', '\u0d26', '\u0d27', '\u0d20', '\u0d28', '\u0d2e', '\u0d30', '\u0d31', '\u0d32', '\u0d09', '\u0d34', '\u0d35', '\u0d36', '\u0d38', '\u0d39', '\u0d66', '\u0d67', '\u0d68', '\u0d69', '\u0d6a', '\u0d6b', '\u0d6c', '\u0d6d', '\u0d6e', '\u0d6f'}, // Malay
/* Georgian */ {'\u10a0', '\u10a1', '\u10a3', '\u10a6', '\u10a4', '\u10a9', '\u10ab', '\u10ac', '\u10b3', '\u10ae', '\u10b0', '\u10b1', '\u10b2', '\u10b4', '\u10ad', '\u10b5', '\u10b6', '\u10b7', '\u10b8', '\u10b9', '\u10a8', '\u10ba', '\u10bb', '\u10bd', '\u10be', '\u10bf', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Georgian
/* Katakana */ {'\u30a2', '\u30ab', '\u30ad', '\u30af', '\u30aa', '\u30b1', '\u30b3', '\u30b5', '\u30a4', '\u30b9', '\u30c1', '\u30c8', '\u30ca', '\u30cc', '\u30a6', '\u30d2', '\u30d5', '\u30d8', '\u30db', '\u30e1', '\u30a8', '\u30e2', '\u30e8', '\u30e9', '\u30ed', '\u30f2', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Katakana
/* Thai */ {'\u0e30', '\u0e01', '\u0e02', '\u0e04', '\u0e32', '\u0e07', '\u0e08', '\u0e09', '\u0e31', '\u0e0a', '\u0e11', '\u0e14', '\u0e16', '\u0e17', '\u0e0d', '\u0e18', '\u0e1a', '\u0e1c', '\u0e21', '\u0e23', '\u0e2c', '\u0e25', '\u0e27', '\u0e2d', '\u0e2e', '\u0e2f', '\u0e50', '\u0e51', '\u0e52', '\u0e53', '\u0e54', '\u0e55', '\u0e56', '\u0e57', '\u0e58', '\u0e59'}, // Thai
/* Laos */ {'\u0eb0', '\u0e81', '\u0e82', '\u0e84', '\u0ec3', '\u0e87', '\u0e88', '\u0e8a', '\u0ec4', '\u0e8d', '\u0e94', '\u0e97', '\u0e99', '\u0e9a', '\u0ec6', '\u0e9c', '\u0e9e', '\u0ea1', '\u0ea2', '\u0ea3', '\u0ebd', '\u0ea7', '\u0eaa', '\u0eab', '\u0ead', '\u0eaf', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Laos
/* Armenian */ {'\u0556', '\u0532', '\u0533', '\u0534', '\u0535', '\u0538', '\u0539', '\u053a', '\u053b', '\u053d', '\u053f', '\u0540', '\u0541', '\u0543', '\u0555', '\u0547', '\u0548', '\u054a', '\u054d', '\u054e', '\u0545', '\u054f', '\u0550', '\u0551', '\u0552', '\u0553', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Armenian
/* Bengali */ {'\u099c', '\u0998', '\u0995', '\u0996', '\u09ae', '\u0997', '\u0999', '\u099a', '\u09ab', '\u099d', '\u09a0', '\u09a1', '\u09a2', '\u09a3', '\u099e', '\u09a4', '\u09a5', '\u09a6', '\u09a8', '\u09aa', '\u099f', '\u09ac', '\u09ad', '\u09af', '\u09b2', '\u09b9', '\u09e6', '\u09e7', '\u09e8', '\u09e9', '\u09ea', '\u09eb', '\u09ec', '\u09ed', '\u09ee', '\u09ef'}, // Bengali/Assamese
/* Gurmukhi */ {'\u0a05', '\u0a15', '\u0a17', '\u0a18', '\u0a0f', '\u0a1a', '\u0a1c', '\u0a1f', MISSCODE, '\u0a20', '\u0a23', '\u0a24', '\u0a26', '\u0a27', MISSCODE, '\u0a28', '\u0a2a', '\u0a2d', '\u0a2e', '\u0a30', '\u0a2b', '\u0a32', '\u0a35', '\u0a38', '\u0a39', '\u0a21', '\u0a66', '\u0a67', '\u0a68', '\u0a69', '\u0a6a', '\u0a6b', '\u0a6c', '\u0a6d', '\u0a6e', '\u0a6f'}, // Gurmukhi
/* Tibetan */ {'\u0f58', '\u0f40', '\u0f41', '\u0f42', '\u0f64', '\u0f44', '\u0f45', '\u0f46', MISSCODE, '\u0f47', '\u0f49', '\u0f55', '\u0f50', '\u0f4f', MISSCODE, '\u0f51', '\u0f53', '\u0f54', '\u0f56', '\u0f5e', '\u0f60', '\u0f5f', '\u0f61', '\u0f62', '\u0f63', '\u0f66', '\u0f20', '\u0f21', '\u0f22', '\u0f23', '\u0f24', '\u0f25', '\u0f26', '\u0f27', '\u0f28', '\u0f29'}, // Tibetan
/* Arabic */ {'\u0628', '\u062a', '\u062d', '\u062e', '\u062B', '\u062f', '\u0630', '\u0631', '\u0627', '\u0632', '\u0633', '\u0634', '\u0635', '\u0636', '\u0647', '\u0637', '\u0638', '\u0639', '\u063a', '\u0641', '\u0642', '\u062C', '\u0644', '\u0645', '\u0646', '\u0648', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Arabic
/* Korean */ {'\u1112', '\u1100', '\u1102', '\u1103', '\u1166', '\u1105', '\u1107', '\u1109', '\u1175', '\u1110', '\u1111', '\u1161', '\u1162', '\u1163', '\u110b', '\u1164', '\u1165', '\u1167', '\u1169', '\u1172', '\u1174', '\u110c', '\u110e', '\u110f', '\u116d', '\u116e', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Korean
/* Burmese */ {'\u1005', '\u1000', '\u1001', '\u1002', '\u1013', '\u1003', '\u1004', '\u101a', '\u101b', '\u1007', '\u100c', '\u100d', '\u100e', '\u1010', '\u101d', '\u1011', '\u1012', '\u101e', '\u1014', '\u1015', '\u1016', '\u101f', '\u1017', '\u1018', '\u100f', '\u101c', '\u1040', '\u1041', '\u1042', '\u1043', '\u1044', '\u1045', '\u1046', '\u1047', '\u1048', '\u1049'}, // Burmese
/* Khmer */ {'\u1789', '\u1780', '\u1781', '\u1782', '\u1785', '\u1783', '\u1784', '\u1787', '\u179a', '\u1788', '\u178a', '\u178c', '\u178d', '\u178e', '\u179c', '\u1791', '\u1792', '\u1793', '\u1794', '\u1795', '\u179f', '\u1796', '\u1798', '\u179b', '\u17a0', '\u17a2', '\u17e0', '\u17e1', '\u17e2', '\u17e3', '\u17e4', '\u17e5', '\u17e6', '\u17e7', '\u17e8', '\u17e9'}, // Khmer
/* Sinhalese*/ {'\u0d85', '\u0d9a', '\u0d9c', '\u0d9f', '\u0d89', '\u0da2', '\u0da7', '\u0da9', '\u0dc2', '\u0dac', '\u0dad', '\u0daf', '\u0db1', '\u0db3', '\u0dc5', '\u0db4', '\u0db6', '\u0db8', '\u0db9', '\u0dba', '\u0d8b', '\u0dbb', '\u0dbd', '\u0dc0', '\u0dc3', '\u0dc4', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Sinhalese
/* Thaana */ {'\u0794', '\u0780', '\u0781', '\u0782', '\u0797', '\u0783', '\u0784', '\u0785', '\u07a4', '\u0786', '\u0787', '\u0788', '\u0789', '\u078a', '\u0796', '\u078b', '\u078c', '\u078d', '\u078e', '\u078f', '\u079c', '\u0790', '\u0791', '\u0792', '\u0793', '\u07b1', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Thaana
/* Chinese */ {'\u3123', '\u3105', '\u3108', '\u3106', '\u3114', '\u3107', '\u3109', '\u310a', '\u311e', '\u310b', '\u310c', '\u310d', '\u310e', '\u310f', '\u3120', '\u3115', '\u3116', '\u3110', '\u3111', '\u3112', '\u3113', '\u3129', '\u3117', '\u3128', '\u3118', '\u3119', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Chinese
/* Tifinagh */ {'\u2D49', '\u2D31', '\u2D33', '\u2D37', '\u2D53', '\u2D3C', '\u2D3D', '\u2D40', '\u2D4F', '\u2D43', '\u2D44', '\u2D45', '\u2D47', '\u2D4D', '\u2D54', '\u2D4E', '\u2D55', '\u2D56', '\u2D59', '\u2D5A', '\u2D62', '\u2D5B', '\u2D5C', '\u2D5F', '\u2D61', '\u2D63', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Tifinagh (BERBER)
/* Tamil */ {'\u0b99', '\u0b95', '\u0b9a', '\u0b9f', '\u0b86', '\u0ba4', '\u0ba8', '\u0baa', '\u0ba9', '\u0bae', '\u0baf', '\u0bb0', '\u0bb2', '\u0bb5', '\u0b9e', '\u0bb4', '\u0bb3', '\u0bb1', '\u0b85', '\u0b88', '\u0b93', '\u0b89', '\u0b8e', '\u0b8f', '\u0b90', '\u0b92', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Tamil (digits 0xBE6-0xBEF)
/* Amharic */ {'\u121B', '\u1260', '\u1264', '\u12F0', '\u121E', '\u134A', '\u1308', '\u1200', '\u12A0', '\u12E8', '\u12AC', '\u1208', '\u1293', '\u1350', '\u12D0', '\u1354', '\u1240', '\u1244', '\u122C', '\u1220', '\u12C8', '\u1226', '\u1270', '\u1276', '\u1338', '\u12DC', '\u1372', '\u1369', '\u136a', '\u136b', '\u136c', '\u136d', '\u136e', '\u136f', '\u1370', '\u1371'}, // Amharic (digits 1372|1369-1371)
/* Telugu */ {'\u0C1E', '\u0C15', '\u0C17', '\u0C19', '\u0C2B', '\u0C1A', '\u0C1C', '\u0C1F', '\u0C1B', '\u0C20', '\u0C21', '\u0C23', '\u0C24', '\u0C25', '\u0C16', '\u0C26', '\u0C27', '\u0C28', '\u0C2A', '\u0C2C', '\u0C2D', '\u0C2E', '\u0C30', '\u0C32', '\u0C33', '\u0C35', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Telugu
/* Odia */ {'\u0B1D', '\u0B15', '\u0B16', '\u0B17', '\u0B23', '\u0B18', '\u0B1A', '\u0B1C', '\u0B2B', '\u0B1F', '\u0B21', '\u0B22', '\u0B24', '\u0B25', '\u0B20', '\u0B26', '\u0B27', '\u0B28', '\u0B2A', '\u0B2C', '\u0B39', '\u0B2E', '\u0B2F', '\u0B30', '\u0B33', '\u0B38', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Odia
/* Kannada */ {'\u0C92', '\u0C95', '\u0C96', '\u0C97', '\u0C8E', '\u0C99', '\u0C9A', '\u0C9B', '\u0C85', '\u0C9C', '\u0CA0', '\u0CA1', '\u0CA3', '\u0CA4', '\u0C89', '\u0CA6', '\u0CA7', '\u0CA8', '\u0CAA', '\u0CAB', '\u0C87', '\u0CAC', '\u0CAD', '\u0CB0', '\u0CB2', '\u0CB5', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Kannada
/* Gujarati */ {'\u0AB3', '\u0A97', '\u0A9C', '\u0AA1', '\u0A87', '\u0AA6', '\u0AAC', '\u0A95', '\u0A8F', '\u0A9A', '\u0A9F', '\u0AA4', '\u0AAA', '\u0AA0', '\u0A8D', '\u0AB0', '\u0AB5', '\u0A9E', '\u0AAE', '\u0AAB', '\u0A89', '\u0AB7', '\u0AA8', '\u0A9D', '\u0AA2', '\u0AAD', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'} // Gujarati
};
// @formatter:on
// @formatter:off
<span class="fc" id="L282"> @SuppressWarnings("LongLine") private final static Unicode2Ascii[] UNICODE2ASCII = {</span>
/* Roman */ new Unicode2Ascii('\u0041', '\u005a', "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), // Roman
/* Greek */ new Unicode2Ascii('\u0388', '\u03a9', "EU???????ABGDFZHQIKLMNCOJP?STYVXRW"), // Greek
/* Cyrillic */ new Unicode2Ascii('\u0410', '\u042f', "AZBGDEFNI?KLMHOJPCTYQXSVW????U?R"), // Cyrillic
/* Hebrew */ new Unicode2Ascii('\u05d0', '\u05ea', "ABCDFIGHJKLMNPQ?ROSETUVWXYZ"), // Hebrew
/* Devanag. */ new Unicode2Ascii('\u0905', '\u0939', "A?????????E?????B?CD?F?G??HJZ?KL?MNP?QUZRS?T?V??W??XY"), // Devanagiri
/* Malay */ new Unicode2Ascii('\u0d07', '\u0d39', "I?U?E??????A??BCD??F?G??HOJ??KLMNP?????Q?RST?VWX?YZ"), // Malai
/* Georgian */ new Unicode2Ascii('\u10a0', '\u10bf', "AB?CE?D?UF?GHOJ?KLMINPQRSTVW?XYZ"), // Georgian
/* Katakana */ new Unicode2Ascii('\u30a2', '\u30f2', "A?I?O?U?EB?C?D?F?G?H???J???????K??????L?M?N?????P??Q??R??S?????TV?????WX???Y????Z"), // Katakana
/* Thai */ new Unicode2Ascii('\u0e01', '\u0e32', "BC?D??FGHJ??O???K??L?MNP?Q?R????S?T?V?W????UXYZAIE"), // Thai
/* Laos */ new Unicode2Ascii('\u0e81', '\u0ec6', "BC?D??FG?H??J??????K??L?MN?P?Q??RST???V??WX?Y?ZA????????????U?????EI?O"), // Lao
/* Armenian */ new Unicode2Ascii('\u0532', '\u0556', "BCDE??FGHI?J?KLM?N?U?PQ?R??STVWXYZ?OA"), // Armenian
/* Bengali */ new Unicode2Ascii('\u0995', '\u09b9', "CDFBGH?AJOUKLMNPQR?S?TIVWEX??Y??????Z"), // Bengali/Assamese
/* Gurmukhi */ new Unicode2Ascii('\u0a05', '\u0a39', "A?????????E?????B?CD?F?G??HJZ?KL?MNP?QU?RS?T?V??W??XY"), // Gurmukhi
/* Tibetan */ new Unicode2Ascii('\u0f40', '\u0f66', "BCD?FGHJ?K?????NMP?QRLS?A?????TVUWXYE?Z"), // Tibetan
/* Arabic */ new Unicode2Ascii('\u0627', '\u0648', "IA?BEVCDFGHJKLMNPQRS??????TU?WXYOZ"), // Arabic
/* Devanag. */ new Unicode2Ascii('\u0966', '\u096f', ""), // Devanagari digits
/* Malai */ new Unicode2Ascii('\u0d66', '\u0d6f', ""), // Malayalam digits
/* Thai */ new Unicode2Ascii('\u0e50', '\u0e59', ""), // Thai digits
/* Bengali */ new Unicode2Ascii('\u09e6', '\u09ef', ""), // Bengali digits
/* Gurmukhi */ new Unicode2Ascii('\u0a66', '\u0a6f', ""), // Gurmukhi digits
/* Tibetan */ new Unicode2Ascii('\u0f20', '\u0f29', ""), // Tibetan digits
/* Burmese */ new Unicode2Ascii('\u1040', '\u1049', ""), // Burmese digits
/* Khmer */ new Unicode2Ascii('\u17e0', '\u17e9', ""), // Khmer digits
/* Tamil */ new Unicode2Ascii('\u0be6', '\u0bef', ""), // Tamil digits
/* Amharic */ new Unicode2Ascii('\u1369', '\u1372', "1234567890"), // Amharic digits [1-9][0]
/* Korean */ new Unicode2Ascii('\u1100', '\u1175', "B?CD?F?G?H?OV?WXJKA??????????????????????????????????????????????????????????????????????????????LMNPQER?S???YZ???T?UI"), // Korean
/* Burmese */ new Unicode2Ascii('\u1000', '\u101f', "BCDFGA?J????KLMYNPQESTUWX?HIZORV"), // Burmese
/* Khmer */ new Unicode2Ascii('\u1780', '\u17a2', "BCDFGE?HJAK?LMN??PQRSTV?W?IXO??UY?Z"), // Khmer
/* Sinhalese*/ new Unicode2Ascii('\u0d85', '\u0dc5', "A???E?U??????????????B?C??D??F????G?H??JK?L?M?NP?Q?RSTV?W??X?IYZO"), // Sinhalese
/* Thaana */ new Unicode2Ascii('\u0780', '\u07b1', "BCDFGHJKLMNPQRSTVWXYA?OE????U???????I????????????Z"), // Thaana
/* Chinese */ new Unicode2Ascii('\u3105', '\u3129', "BDFCGHJKLMNRSTUEPQWYZ????I?O??A????XV"), // Chinese
/* Tifinagh */ new Unicode2Ascii('\u2d31', '\u2d63', "B?C???D????FG??H??JKL?M?A???NPI???EOQR??STVW??X?YUZ"), // Tifinagh
/* Tamil */ new Unicode2Ascii('\u0b85', '\u0bb5', "SE?TV????WXY?ZU?B???AC???OD????F???GIH???JKLRMQPN"), // Tamil
/* Amharic */ new Unicode2Ascii('\u1200', '\u1354', "H???????L??????????????????A??E?T?????V?????S???????????????????Q???R???????????????????????????B???C???????????W?????X????????????????????????????M????????????I???????????K???????????????????????????U???????O???????????Z???????????J???????D???????????????????????G???????????????????????????????????????????????Y?????????????????F?????N???P"), // Amharic
/* Telugu */ new Unicode2Ascii('\u0c15', '\u0c35', "BOC?DFIG?AHJK?LMNPQR?SETUV?W?XY?Z"), // Telugu
/* Odia */ new Unicode2Ascii('\u0b15', '\u0b39', "BCDF?G?HA?JOKLEMNPQR?SIT?VWX??Y????ZU"), // Odia
/* Kannada */ new Unicode2Ascii('\u0c85', '\u0cb5', "I?U?O????E???A??BCD?FGHJ???KL?MN?PQR?STVW??X?Y??Z"), // Kannada
/* Gujarati */ new Unicode2Ascii('\u0a87', '\u0ab7', "E?U???O?I?????H?B??J?CXRKNDY?L?F?W?MTGZS?P??A?Q?V"), // Gujarati
// Lowercase variants:
/* Greek */ new Unicode2Ascii('\u03ad', '\u03c9', "EU??ABGDFZHQIKLMNCOJP?STYVXRW"),
/* Georgian */ new Unicode2Ascii('\u10d0', '\u10ef', "AB?CE?D?UF?GHOJ?KLMINPQRSTVW?XYZ"),
/* Armenian */ new Unicode2Ascii('\u0562', '\u0586', "BCDE??FGHI?J?KLM?N?U?PQ?R??STVWXYZ?OA")
};
// @formatter:on
@Nonnull
private static MapcodeZone decodeGrid(
@Nonnull final String str,
final int minx,
final int miny,
final int maxx,
final int maxy,
final int m,
@Nonnull final String extrapostfix) {
// for a well-formed result, and integer variables
<span class="fc" id="L341"> String result = str;</span>
int relx;
int rely;
<span class="fc" id="L344"> final int codexlen = result.length() - 1; // length ex dot</span>
<span class="fc" id="L345"> int prelen = result.indexOf('.'); // dot position</span>
<span class="pc bpc" id="L347" title="1 of 4 branches missed."> if ((prelen == 1) && (codexlen == 5)) {</span>
<span class="fc" id="L348"> prelen++;</span>
<span class="fc" id="L349"> result = result.substring(0, 1) + result.charAt(2) + '.' + result.substring(3);</span>
}
<span class="fc" id="L351"> final int postlen = codexlen - prelen;</span>
final int divx;
int divy;
<span class="fc" id="L355"> divy = DATA_MODEL.getSmartDiv(m);</span>
<span class="fc bfc" id="L356" title="All 2 branches covered."> if (divy == 1) {</span>
<span class="fc" id="L357"> divx = Common.X_SIDE[prelen];</span>
<span class="fc" id="L358"> divy = Common.Y_SIDE[prelen];</span>
} else {
<span class="fc" id="L360"> divx = Common.NC[prelen] / divy;</span>
}
<span class="pc bpc" id="L363" title="1 of 6 branches missed."> if ((prelen == 4) && (divx == 961) && (divy == 961)) {</span>
<span class="fc" id="L364"> result = result.substring(0, 1) + result.charAt(2) + result.charAt(1) + result.substring(3);</span>
}
<span class="fc" id="L367"> int v = decodeBase31(result);</span>
<span class="fc bfc" id="L369" title="All 4 branches covered."> if ((divx != divy) && (prelen > 2)) // D==6</span>
{
<span class="fc" id="L371"> final Point d = decodeSixWide(v, divx, divy);</span>
<span class="fc" id="L372"> relx = d.getLonMicroDeg();</span>
<span class="fc" id="L373"> rely = d.getLatMicroDeg();</span>
<span class="fc" id="L374"> } else {</span>
<span class="fc" id="L375"> relx = v / divy;</span>
<span class="fc" id="L376"> rely = divy - 1 - (v % divy);</span>
}
<span class="fc" id="L379"> final int ygridsize = (((maxy - miny) + divy) - 1) / divy;</span>
<span class="fc" id="L380"> final int xgridsize = (((maxx - minx) + divx) - 1) / divx;</span>
<span class="fc" id="L382"> rely = miny + (rely * ygridsize);</span>
<span class="fc" id="L383"> relx = minx + (relx * xgridsize);</span>
<span class="fc" id="L385"> final int yp = Common.Y_SIDE[postlen];</span>
<span class="fc" id="L386"> final int dividery = ((ygridsize + yp) - 1) / yp;</span>
<span class="fc" id="L387"> final int xp = Common.X_SIDE[postlen];</span>
<span class="fc" id="L388"> final int dividerx = ((xgridsize + xp) - 1) / xp;</span>
<span class="fc" id="L390"> String rest = result.substring(prelen + 1);</span>
// decode relative (postfix vs rely, relx)
final int difx;
int dify;
<span class="fc bfc" id="L396" title="All 2 branches covered."> if (postlen == 3) {</span>
<span class="fc" id="L397"> final Point d = decodeTriple(rest);</span>
<span class="fc" id="L398"> difx = d.getLonMicroDeg();</span>
<span class="fc" id="L399"> dify = d.getLatMicroDeg();</span>
<span class="fc" id="L400"> } else {</span>
<span class="fc bfc" id="L401" title="All 2 branches covered."> if (postlen == 4) {</span>
<span class="fc" id="L402"> rest = String.valueOf(rest.charAt(0)) + rest.charAt(2) + rest.charAt(1) + rest.charAt(3);</span>
}
<span class="fc" id="L404"> v = decodeBase31(rest);</span>
<span class="fc" id="L405"> difx = v / yp;</span>
<span class="fc" id="L406"> dify = v % yp;</span>
}
<span class="fc" id="L409"> dify = yp - 1 - dify;</span>
<span class="fc" id="L411"> final int cornery = rely + (dify * dividery);</span>
<span class="fc" id="L412"> final int cornerx = relx + (difx * dividerx);</span>
<span class="fc" id="L414"> final Point pt = Point.fromMicroDeg(cornery, cornerx);</span>
<span class="pc bpc" id="L415" title="1 of 2 branches missed."> if (!(createBoundaryForTerritoryRecord(m).containsPoint(pt))) {</span>
<span class="nc" id="L416"> LOG.info("decodeGrid: Failed decodeGrid({}): {} not in {}", str, pt, createBoundaryForTerritoryRecord(m));</span>
<span class="nc" id="L417"> return new MapcodeZone(); // already out of range</span>
}
<span class="fc bfc" id="L420" title="All 2 branches covered."> final int decodeMaxx = ((relx + xgridsize) < maxx) ? (relx + xgridsize) : maxx;</span>
<span class="fc bfc" id="L421" title="All 2 branches covered."> final int decodeMaxy = ((rely + ygridsize) < maxy) ? (rely + ygridsize) : maxy;</span>
<span class="fc" id="L422"> return decodeExtension(cornery, cornerx, dividerx << 2, dividery, extrapostfix,</span>
0, decodeMaxy, decodeMaxx); // grid
}
@Nonnull
private static MapcodeZone decodeNameless(
@Nonnull final String str,
final int firstrec,
@Nonnull final String extrapostfix) {
<span class="fc" id="L431"> String result = str;</span>
<span class="fc" id="L432"> final int codexm = Data.getCodex(firstrec);</span>
<span class="fc bfc" id="L433" title="All 2 branches covered."> if (codexm == 22) {</span>
<span class="fc" id="L434"> result = result.substring(0, 3) + result.substring(4);</span>
} else {
<span class="fc" id="L436"> result = result.substring(0, 2) + result.substring(3);</span>
}
<span class="fc" id="L439"> final int a = Common.countCityCoordinatesForCountry(codexm, firstrec, firstrec);</span>
<span class="fc" id="L441"> final int p = 31 / a;</span>
<span class="fc" id="L442"> final int r = 31 % a;</span>
<span class="fc" id="L443"> int v = 0;</span>
int nrX;
<span class="fc" id="L445"> boolean swapletters = false;</span>
<span class="fc bfc" id="L447" title="All 4 branches covered."> if ((codexm != 21) && (a <= 31)) {</span>
<span class="fc" id="L448"> final int offset = DECODE_CHARS[(int) result.charAt(0)];</span>
<span class="fc bfc" id="L450" title="All 2 branches covered."> if (offset < (r * (p + 1))) {</span>
<span class="fc" id="L451"> nrX = offset / (p + 1);</span>
} else {
<span class="fc bfc" id="L453" title="All 4 branches covered."> swapletters = (p == 1) && (codexm == 22);</span>
<span class="fc" id="L454"> nrX = r + ((offset - (r * (p + 1))) / p);</span>
}
<span class="fc bfc" id="L456" title="All 4 branches covered."> } else if ((codexm != 21) && (a < 62)) {</span>
<span class="fc" id="L457"> nrX = DECODE_CHARS[(int) result.charAt(0)];</span>
<span class="fc bfc" id="L458" title="All 2 branches covered."> if (nrX < (62 - a)) {</span>
<span class="pc bpc" id="L459" title="1 of 2 branches missed."> swapletters = codexm == 22;</span>
} else {
<span class="fc" id="L461"> nrX = ((nrX + nrX) - 62) + a;</span>
}
} else {
// codex==21 || A>=62
<span class="fc bfc" id="L465" title="All 2 branches covered."> final int basePower = (codexm == 21) ? (961 * 961) : (961 * 961 * 31);</span>
<span class="fc" id="L466"> int basePowerA = basePower / a;</span>
<span class="pc bpc" id="L467" title="1 of 2 branches missed."> if (a == 62) {</span>
<span class="nc" id="L468"> basePowerA++;</span>
} else {
<span class="fc" id="L470"> basePowerA = 961 * (basePowerA / 961);</span>
}
// decode and determine x
<span class="fc" id="L474"> v = decodeBase31(result);</span>
<span class="fc" id="L475"> nrX = v / basePowerA;</span>
<span class="fc" id="L476"> v %= basePowerA;</span>
}
<span class="fc bfc" id="L479" title="All 4 branches covered."> if (swapletters && !Data.isSpecialShape(firstrec + nrX)) {</span>
<span class="fc" id="L480"> result = result.substring(0, 2) + result.charAt(3) + result.charAt(2) + result.charAt(4);</span>
}
<span class="fc bfc" id="L483" title="All 4 branches covered."> if ((codexm != 21) && (a <= 31)) {</span>
<span class="fc" id="L484"> v = decodeBase31(result);</span>
<span class="fc bfc" id="L485" title="All 2 branches covered."> if (nrX > 0) {</span>
<span class="fc bfc" id="L486" title="All 2 branches covered."> v -= ((nrX * p) + ((nrX < r) ? nrX : r)) * 961 * 961;</span>
}
<span class="fc bfc" id="L488" title="All 4 branches covered."> } else if ((codexm != 21) && (a < 62)) {</span>
<span class="fc" id="L489"> v = decodeBase31(result.substring(1));</span>
<span class="fc bfc" id="L490" title="All 4 branches covered."> if ((nrX >= (62 - a)) && (v >= (16 * 961 * 31))) {</span>
<span class="fc" id="L491"> v -= 16 * 961 * 31;</span>
<span class="fc" id="L492"> nrX++;</span>
}
}
<span class="pc bpc" id="L496" title="1 of 2 branches missed."> if (nrX > a) { // past end!</span>
<span class="nc" id="L497"> return new MapcodeZone();</span>
}
<span class="fc" id="L500"> final int territoryRecord = firstrec + nrX;</span>
<span class="fc" id="L502"> int side = DATA_MODEL.getSmartDiv(territoryRecord);</span>
<span class="fc" id="L503"> int xSIDE = side;</span>
<span class="fc" id="L505"> final Boundary boundary = createBoundaryForTerritoryRecord(territoryRecord);</span>
<span class="fc" id="L506"> final int maxx = boundary.getLonMicroDegMax();</span>
<span class="fc" id="L507"> final int maxy = boundary.getLatMicroDegMax();</span>
<span class="fc" id="L508"> final int minx = boundary.getLonMicroDegMin();</span>
<span class="fc" id="L509"> final int miny = boundary.getLatMicroDegMin();</span>
final int dx;
final int dy;
<span class="fc bfc" id="L514" title="All 2 branches covered."> if (Data.isSpecialShape(territoryRecord)) {</span>
<span class="fc" id="L515"> xSIDE *= side;</span>
<span class="fc" id="L516"> side = 1 + ((maxy - miny) / 90);</span>
<span class="fc" id="L517"> xSIDE = xSIDE / side;</span>
<span class="fc" id="L519"> final Point d = decodeSixWide(v, xSIDE, side);</span>
<span class="fc" id="L520"> dx = d.getLonMicroDeg();</span>
<span class="fc" id="L521"> dy = side - 1 - d.getLatMicroDeg();</span>
<span class="fc" id="L522"> } else {</span>
<span class="fc" id="L523"> dy = v % side;</span>
<span class="fc" id="L524"> dx = v / side;</span>
}
<span class="pc bpc" id="L527" title="1 of 2 branches missed."> if (dx >= xSIDE) // else out-of-range!</span>
{
<span class="nc" id="L529"> LOG.error("decodeGrid: Failed, decodeNameless({}): dx {} > xSIDE {}", str, dx, xSIDE);</span>
<span class="nc" id="L530"> return new MapcodeZone(); // return undefined (out of range!)</span>
}
<span class="fc" id="L533"> final int dividerx4 = Common.xDivider(miny, maxy); // 4 times too large!</span>
<span class="fc" id="L534"> final int dividery = 90;</span>
<span class="fc" id="L536"> final int cornerx = minx + ((dx * dividerx4) / 4);</span>
<span class="fc" id="L537"> final int cornery = maxy - (dy * dividery);</span>
<span class="fc" id="L538"> return decodeExtension(cornery, cornerx, dividerx4, -dividery, extrapostfix,</span>
((dx * dividerx4) % 4), miny, maxx); // nameless
}
@Nonnull
private static MapcodeZone decodeAutoHeader(
final String input,
final int m,
@Nonnull final String extrapostfix) {
// returns Point.isUndefined() in case or error
<span class="fc" id="L548"> int storageStart = 0;</span>
<span class="fc" id="L549"> final int codexm = Data.getCodex(m);</span>
<span class="fc" id="L551"> int value = decodeBase31(input); // decode top (before dot)</span>
<span class="fc" id="L552"> value *= 961 * 31;</span>
<span class="fc" id="L553"> final Point triple = decodeTriple(input.substring(input.length() - 3));</span>
// decode bottom 3 chars
int i;
<span class="fc" id="L557"> i = m;</span>
while (true) {
<span class="pc bpc" id="L559" title="2 of 4 branches missed."> if ((Data.getTerritoryRecordType(i) < Data.TERRITORY_RECORD_TYPE_PLUS) || (Data.getCodex(i) != codexm)) {</span>
<span class="nc" id="L560"> LOG.error("decodeGrid: Failed, decodeAutoHeader({}): out of {} records", input, codexm);</span>
<span class="nc" id="L561"> return new MapcodeZone(); // return undefined</span>
}
<span class="fc" id="L564"> final int maxx = createBoundaryForTerritoryRecord(i).getLonMicroDegMax();</span>
<span class="fc" id="L565"> final int maxy = createBoundaryForTerritoryRecord(i).getLatMicroDegMax();</span>
<span class="fc" id="L566"> final int minx = createBoundaryForTerritoryRecord(i).getLonMicroDegMin();</span>
<span class="fc" id="L567"> final int miny = createBoundaryForTerritoryRecord(i).getLatMicroDegMin();</span>
<span class="fc" id="L569"> int h = ((maxy - miny) + 89) / 90;</span>
<span class="fc" id="L570"> final int xdiv = Common.xDivider(miny, maxy);</span>
<span class="fc" id="L571"> int w = ((((maxx - minx) * 4) + xdiv) - 1) / xdiv;</span>
<span class="fc" id="L573"> h = 176 * (((h + 176) - 1) / 176);</span>
<span class="fc" id="L574"> w = 168 * (((w + 168) - 1) / 168);</span>
<span class="fc" id="L576"> int product = (w / 168) * (h / 176) * 961 * 31;</span>
<span class="fc bfc" id="L578" title="All 2 branches covered."> if (Data.getTerritoryRecordType(i) == Data.TERRITORY_RECORD_TYPE_PLUS) {</span>
<span class="fc bfc" id="L579" title="All 2 branches covered."> final int goodRounder = (codexm >= 23) ? (961 * 961 * 31) : (961 * 961);</span>
<span class="fc" id="L580"> product = ((((storageStart + product + goodRounder) - 1) / goodRounder) * goodRounder) - storageStart;</span>
}
<span class="pc bpc" id="L583" title="1 of 4 branches missed."> if ((value >= storageStart) && (value < (storageStart + product))) {</span>
// code belongs here?
<span class="fc" id="L585"> final int dividerx = (((maxx - minx) + w) - 1) / w;</span>
<span class="fc" id="L586"> final int dividery = (((maxy - miny) + h) - 1) / h;</span>
<span class="fc" id="L588"> value -= storageStart;</span>
<span class="fc" id="L589"> value = value / (961 * 31);</span>
<span class="fc" id="L591"> int vx = value / (h / 176);</span>
<span class="fc" id="L592"> vx = (vx * 168) + triple.getLonMicroDeg();</span>
<span class="fc" id="L593"> final int vy = ((value % (h / 176)) * 176) + triple.getLatMicroDeg();</span>
<span class="fc" id="L595"> final int cornery = maxy - (vy * dividery);</span>
<span class="fc" id="L596"> final int cornerx = minx + (vx * dividerx);</span>
<span class="pc bpc" id="L598" title="4 of 8 branches missed."> if ((cornerx < minx) || (cornerx >= maxx) || (cornery < miny) || (cornery > maxy)) {</span>
<span class="nc" id="L599"> LOG.error("decodeGrid: Failed, decodeAutoHeader({}): corner {}, {} out of bounds", input, cornery, cornerx);</span>
<span class="nc" id="L600"> return new MapcodeZone(); // corner out of bounds</span>
}
<span class="fc" id="L603"> return decodeExtension(cornery, cornerx, dividerx << 2, -dividery, extrapostfix,</span>
0, miny, maxx); // autoheader
}
<span class="fc" id="L606"> storageStart += product;</span>
<span class="fc" id="L607"> i++;</span>
<span class="fc" id="L608"> }</span>
}
@Nonnull
private static String aeuUnpack(@Nonnull final String argStr) {
// unpack encoded into all-digit
// (assume str already uppercase!), returns "" in case of error
<span class="fc" id="L615"> String str = decodeUTF16(argStr);</span>
<span class="fc" id="L616"> boolean voweled = false;</span>
<span class="fc" id="L617"> final int lastpos = str.length() - 1;</span>
<span class="fc" id="L618"> int dotpos = str.indexOf('.');</span>
<span class="pc bpc" id="L619" title="1 of 4 branches missed."> if ((dotpos < 2) || (lastpos < (dotpos + 2))) {</span>
<span class="fc" id="L620"> return ""; // Error: no dot, or less than 2 letters before dot, or</span>
}
// less than 2 letters after dot
<span class="fc bfc" id="L624" title="All 2 branches covered."> if (str.charAt(0) == 'A') { // v1.50</span>
<span class="fc" id="L625"> int v1 = DECODE_CHARS[(int) str.charAt(lastpos)];</span>
<span class="pc bpc" id="L626" title="1 of 2 branches missed."> if (v1 < 0) {</span>
<span class="nc" id="L627"> v1 = 31;</span>
}
<span class="fc" id="L629"> int v2 = DECODE_CHARS[(int) str.charAt(lastpos - 1)];</span>
<span class="pc bpc" id="L630" title="1 of 2 branches missed."> if (v2 < 0) {</span>
<span class="nc" id="L631"> v2 = 31;</span>
}
<span class="fc" id="L633"> final String s = String.valueOf(1000 + v1 + (32 * v2));</span>
<span class="fc" id="L634"> str = s.charAt(1) + str.substring(1, lastpos - 1) + s.charAt(2) + s.charAt(3);</span>
<span class="fc" id="L635"> voweled = true;</span>
<span class="pc bpc" id="L636" title="1 of 2 branches missed."> } else if (str.charAt(0) == 'U') { // v.1.50 debug decoding of U+alldigitmapcode</span>
<span class="nc" id="L637"> voweled = true;</span>
<span class="nc" id="L638"> str = str.substring(1);</span>
<span class="nc" id="L639"> dotpos--;</span>
} else {
<span class="fc" id="L641"> int v = str.charAt(lastpos - 1);</span>
<span class="fc bfc" id="L642" title="All 2 branches covered."> if (v == 'A') {</span>
<span class="fc" id="L643"> v = 0;</span>
<span class="fc bfc" id="L644" title="All 2 branches covered."> } else if (v == 'E') {</span>
<span class="fc" id="L645"> v = 34;</span>
<span class="fc bfc" id="L646" title="All 2 branches covered."> } else if (v == 'U') {</span>
<span class="fc" id="L647"> v = 68;</span>
} else {
<span class="fc" id="L649"> v = -1;</span>
}
<span class="fc bfc" id="L651" title="All 2 branches covered."> if (v >= 0) {</span>
<span class="fc" id="L652"> final char e = str.charAt(lastpos);</span>
<span class="pc bpc" id="L653" title="1 of 2 branches missed."> if (e == 'A') {</span>
<span class="nc" id="L654"> v += 31;</span>
<span class="fc bfc" id="L655" title="All 2 branches covered."> } else if (e == 'E') {</span>
<span class="fc" id="L656"> v += 32;</span>
<span class="fc bfc" id="L657" title="All 2 branches covered."> } else if (e == 'U') {</span>
<span class="fc" id="L658"> v += 33;</span>
} else {
<span class="fc" id="L660"> final int ve = DECODE_CHARS[(int) str.charAt(lastpos)];</span>
<span class="pc bpc" id="L661" title="1 of 2 branches missed."> if (ve < 0) {</span>
<span class="nc" id="L662"> return "";</span>
}
<span class="fc" id="L664"> v += ve;</span>
}
<span class="pc bpc" id="L666" title="1 of 2 branches missed."> if (v >= 100) {</span>
<span class="nc" id="L667"> return "";</span>
}
<span class="fc" id="L669"> voweled = true;</span>
<span class="fc" id="L670"> str = str.substring(0, lastpos - 1) + Data.ENCODE_CHARS[v / 10]</span>
+ Data.ENCODE_CHARS[v % 10];
}
}
<span class="pc bpc" id="L675" title="2 of 4 branches missed."> if ((dotpos < 2) || (dotpos > 5)) {</span>
<span class="nc" id="L676"> return "";</span>
}
<span class="fc bfc" id="L679" title="All 2 branches covered."> for (int v = 0; v <= lastpos; v++) {</span>
<span class="fc bfc" id="L680" title="All 2 branches covered."> if (v != dotpos) {</span>
<span class="fc" id="L681"> final int i = (int) str.charAt(v);</span>
<span class="pc bpc" id="L682" title="1 of 2 branches missed."> if (DECODE_CHARS[i] < 0) {</span>
<span class="nc" id="L683"> return ""; // bad char!</span>
<span class="pc bpc" id="L684" title="1 of 4 branches missed."> } else if (voweled && (DECODE_CHARS[(int) str.charAt(v)] > 9)) {</span>
<span class="nc" id="L685"> return ""; // no-nodigit!</span>
}
}
}
<span class="fc" id="L690"> return str;</span>
}
/**
* This method decodes a Unicode string to ASCII. Package private for access by other modules.
*
* @param mapcode Unicode string.
* @return ASCII string.
*/
@Nonnull
static String decodeUTF16(@Nonnull final String mapcode) {
String result;
<span class="fc" id="L702"> final StringBuilder asciiBuf = new StringBuilder();</span>
<span class="fc bfc" id="L703" title="All 2 branches covered."> for (final char ch : mapcode.toCharArray()) {</span>
<span class="fc bfc" id="L704" title="All 2 branches covered."> if (ch == '.') {</span>
<span class="fc" id="L705"> asciiBuf.append(ch);</span>
<span class="pc bpc" id="L706" title="1 of 4 branches missed."> } else if ((ch >= 1) && (ch <= 'z')) {</span>
// normal ascii
<span class="fc" id="L708"> asciiBuf.append(ch);</span>
} else {
<span class="fc" id="L710"> boolean found = false;</span>
<span class="pc bpc" id="L711" title="1 of 2 branches missed."> for (final Unicode2Ascii unicode2Ascii : UNICODE2ASCII) {</span>
<span class="fc bfc" id="L712" title="All 4 branches covered."> if ((ch >= unicode2Ascii.min) && (ch <= unicode2Ascii.max)) {</span>
<span class="fc" id="L713"> final int pos = ((int) ch) - (int) unicode2Ascii.min;</span>
<span class="fc" id="L714"> asciiBuf.append(unicode2Ascii.convert.charAt(pos));</span>
<span class="fc" id="L715"> found = true;</span>
<span class="fc" id="L716"> break;</span>
}
}
<span class="pc bpc" id="L719" title="1 of 2 branches missed."> if (!found) {</span>
<span class="nc" id="L720"> asciiBuf.append('?');</span>
<span class="nc" id="L721"> break;</span>
}
}
}
<span class="fc" id="L725"> result = asciiBuf.toString();</span>
// Repack if this was a Greek 'alpha' code. This will have been converted to a regular 'A' after one iteration.
<span class="fc bfc" id="L728" title="All 2 branches covered."> if (mapcode.startsWith(String.valueOf(GREEK_CAPITAL_ALPHA))) {</span>
<span class="fc" id="L729"> final String unpacked = aeuUnpack(result);</span>
<span class="pc bpc" id="L730" title="1 of 2 branches missed."> if (unpacked.isEmpty()) {</span>
<span class="nc" id="L731"> throw new AssertionError("decodeUTF16: cannot decode " + mapcode);</span>
}
<span class="fc" id="L733"> result = Encoder.aeuPack(unpacked, false);</span>
}
<span class="fc bfc" id="L736" title="All 2 branches covered."> if (isAbjadScript(mapcode)) {</span>
<span class="fc" id="L737"> return convertFromAbjad(result);</span>
} else {
<span class="fc" id="L739"> return result;</span>
}
}
@Nonnull
static String encodeUTF16(
@Nonnull final String mapcodeInput,
final int alphabetCode) throws IllegalArgumentException {
final String mapcode;
<span class="fc bfc" id="L749" title="All 2 branches covered."> if ((alphabetCode == Alphabet.GREEK.getNumber()) ||</span>
<span class="fc bfc" id="L750" title="All 2 branches covered."> (alphabetCode == Alphabet.HEBREW.getNumber()) ||</span>
<span class="fc bfc" id="L751" title="All 2 branches covered."> (alphabetCode == Alphabet.KOREAN.getNumber()) ||</span>
<span class="fc bfc" id="L752" title="All 2 branches covered."> (alphabetCode == Alphabet.ARABIC.getNumber())) {</span>
<span class="fc" id="L753"> mapcode = convertToAbjad(mapcodeInput);</span>
} else {
<span class="fc" id="L755"> mapcode = mapcodeInput;</span>
}
final String mapcodeToEncode;
<span class="fc bfc" id="L759" title="All 6 branches covered."> if ((alphabetCode == Alphabet.GREEK.getNumber()) && ((mapcode.indexOf('E') != -1) || (mapcode.indexOf('U') != -1))) {</span>
<span class="fc" id="L760"> final String unpacked = aeuUnpack(mapcode);</span>
<span class="pc bpc" id="L761" title="1 of 2 branches missed."> if (unpacked.isEmpty()) {</span>
<span class="nc" id="L762"> throw new IllegalArgumentException("encodeToAlphabetCode: cannot encode '" + mapcode +</span>
"' to alphabet " + alphabetCode);
}
<span class="fc" id="L765"> mapcodeToEncode = Encoder.aeuPack(unpacked, true);</span>
<span class="fc" id="L766"> } else {</span>
<span class="fc" id="L767"> mapcodeToEncode = mapcode;</span>
}
<span class="fc" id="L770"> final StringBuilder sb = new StringBuilder();</span>
<span class="fc bfc" id="L771" title="All 2 branches covered."> for (char ch : mapcodeToEncode.toCharArray()) {</span>
<span class="fc" id="L772"> ch = Character.toUpperCase(ch);</span>
<span class="pc bpc" id="L773" title="1 of 2 branches missed."> if (ch > 'Z') {</span>
// Not in any valid range?
<span class="nc" id="L775"> sb.append('?');</span>
<span class="fc bfc" id="L776" title="All 2 branches covered."> } else if (ch < 'A') {</span>
// Valid but not a letter (e.g. a dot, a space...). Leave untranslated.
<span class="fc" id="L778"> sb.append(ch);</span>
} else {
<span class="fc" id="L780"> sb.append(ASCII2LANGUAGE[alphabetCode][(int) ch - (int) 'A']);</span>
}
}
<span class="fc" id="L783"> return sb.toString();</span>
}
@Nonnull
private static Point decodeTriple(@Nonnull final String str) {
<span class="fc" id="L788"> final int c1 = DECODE_CHARS[(int) str.charAt(0)];</span>
<span class="fc" id="L789"> final int x = decodeBase31(str.substring(1));</span>
<span class="fc bfc" id="L790" title="All 2 branches covered."> if (c1 < 24) {</span>
<span class="fc" id="L791"> return Point.fromMicroDeg(((c1 / 6) * 34) + (x % 34), ((c1 % 6) * 28) + (x / 34));</span>
}
<span class="fc" id="L793"> return Point.fromMicroDeg((x % 40) + 136, (x / 40) + (24 * (c1 - 24)));</span>
}
@Nonnull
private static Point decodeSixWide(
final int v,
final int width,
final int height) {
final int d;
<span class="fc" id="L802"> int col = v / (height * 6);</span>
<span class="fc" id="L803"> final int maxcol = (width - 4) / 6;</span>
<span class="fc bfc" id="L804" title="All 2 branches covered."> if (col >= maxcol) {</span>
<span class="fc" id="L805"> col = maxcol;</span>
<span class="fc" id="L806"> d = width - (maxcol * 6);</span>
} else {
<span class="fc" id="L808"> d = 6;</span>
}
<span class="fc" id="L810"> final int w = v - (col * height * 6);</span>
<span class="fc" id="L811"> return Point.fromMicroDeg(height - 1 - (w / d), (col * 6) + (w % d));</span>
}
// / lowest level encode/decode routines
// decode up to dot or EOS;
// returns negative in case of error
private static int decodeBase31(@Nonnull final String code) {
<span class="fc" id="L818"> int value = 0;</span>
<span class="fc bfc" id="L819" title="All 2 branches covered."> for (final char c : code.toCharArray()) {</span>
<span class="fc bfc" id="L820" title="All 2 branches covered."> if (c == '.') {</span>
<span class="fc" id="L821"> return value;</span>
}
<span class="pc bpc" id="L823" title="1 of 2 branches missed."> if (DECODE_CHARS[c] < 0) {</span>
<span class="nc" id="L824"> return -1;</span>
}
<span class="fc" id="L826"> value = (value * 31) + DECODE_CHARS[c];</span>
}
<span class="fc" id="L828"> return value;</span>
}
@Nonnull
private static MapcodeZone decodeExtension(
final int y,
final int x,
final int dividerx0,
final int dividery0,
@Nonnull final String extrapostfix,
final int lon_offset4,
final int extremeLatMicroDeg,
final int maxLonMicroDeg) {
<span class="fc" id="L841"> final MapcodeZone mapcodeZone = new MapcodeZone();</span>
<span class="fc" id="L842"> double dividerx4 = (double) dividerx0;</span>
<span class="fc" id="L843"> double dividery = (double) dividery0;</span>
<span class="fc" id="L844"> double processor = 1;</span>
<span class="fc" id="L845"> int lon32 = 0;</span>
<span class="fc" id="L846"> int lat32 = 0;</span>
<span class="fc" id="L847"> boolean odd = false;</span>
<span class="fc" id="L848"> int idx = 0;</span>
// decode up to 8 characters
<span class="pc bpc" id="L850" title="1 of 2 branches missed."> final int len = (extrapostfix.length() > 8) ? 8 : extrapostfix.length();</span>
<span class="fc bfc" id="L851" title="All 2 branches covered."> while (idx < len) {</span>
<span class="fc" id="L852"> int c1 = (int) extrapostfix.charAt(idx);</span>
<span class="fc" id="L853"> idx++;</span>
<span class="fc" id="L854"> c1 = DECODE_CHARS[c1];</span>
<span class="pc bpc" id="L855" title="2 of 4 branches missed."> if ((c1 < 0) || (c1 == 30)) {</span>
<span class="nc" id="L856"> LOG.error("decodeGrid; Failed, decodeExtension({}): illegal c1 {}", extrapostfix, c1);</span>
<span class="nc" id="L857"> return new MapcodeZone();</span>
}
<span class="fc" id="L859"> final int y1 = c1 / 5;</span>
<span class="fc" id="L860"> final int x1 = c1 % 5;</span>
final int y2;
final int x2;
<span class="fc bfc" id="L863" title="All 2 branches covered."> if (idx < len) {</span>
<span class="fc" id="L864"> int c2 = (int) extrapostfix.charAt(idx);</span>
<span class="fc" id="L865"> idx++;</span>
<span class="fc" id="L866"> c2 = DECODE_CHARS[c2];</span>
<span class="pc bpc" id="L867" title="2 of 4 branches missed."> if ((c2 < 0) || (c2 == 30)) {</span>
<span class="nc" id="L868"> LOG.error("decodeGrid: Failed, decodeExtension({}): illegal c2 {}", extrapostfix, c2);</span>
<span class="nc" id="L869"> return new MapcodeZone();</span>
}
<span class="fc" id="L871"> y2 = c2 / 6;</span>
<span class="fc" id="L872"> x2 = c2 % 6;</span>
<span class="fc" id="L873"> } else {</span>
<span class="fc" id="L874"> odd = true;</span>
<span class="fc" id="L875"> y2 = 0;</span>
<span class="fc" id="L876"> x2 = 0;</span>
}
<span class="fc" id="L879"> processor *= 30;</span>
<span class="fc" id="L880"> lon32 = (lon32 * 30) + (x1 * 6) + x2;</span>
<span class="fc" id="L881"> lat32 = (lat32 * 30) + (y1 * 5) + y2;</span>
<span class="fc" id="L882"> }</span>
<span class="fc bfc" id="L884" title="All 2 branches covered."> while (processor < Point.MAX_PRECISION_FACTOR) {</span>
<span class="fc" id="L885"> dividerx4 *= 30;</span>
<span class="fc" id="L886"> dividery *= 30;</span>
<span class="fc" id="L887"> processor *= 30;</span>
}
<span class="fc" id="L890"> final double lon4 = (x * 4 * Point.MAX_PRECISION_FACTOR) + (lon32 * dividerx4) + (lon_offset4 * Point.MAX_PRECISION_FACTOR);</span>
<span class="fc" id="L891"> final double lat1 = (y * Point.MAX_PRECISION_FACTOR) + (lat32 * dividery);</span>
// determine the range of coordinates that are encode to this mapcode
<span class="fc bfc" id="L894" title="All 2 branches covered."> if (odd) { // odd</span>
<span class="fc" id="L895"> mapcodeZone.setFromFractions(lat1, lon4, 5 * dividery, 6 * dividerx4);</span>
} else { // not odd
<span class="fc" id="L897"> mapcodeZone.setFromFractions(lat1, lon4, dividery, dividerx4);</span>
} // not odd
// FORCE_RECODE - restrict the coordinate range to the extremes that were provided
<span class="fc bfc" id="L901" title="All 2 branches covered."> if (mapcodeZone.getLonFractionMax() > (maxLonMicroDeg * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR)) {</span>
<span class="fc" id="L902"> mapcodeZone.setLonFractionMax(maxLonMicroDeg * Point.LON_MICRODEG_TO_FRACTIONS_FACTOR);</span>
}
<span class="fc bfc" id="L904" title="All 2 branches covered."> if (dividery >= 0) {</span>
<span class="fc bfc" id="L905" title="All 2 branches covered."> if (mapcodeZone.getLatFractionMax() > (extremeLatMicroDeg * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR)) {</span>
<span class="fc" id="L906"> mapcodeZone.setLatFractionMax(extremeLatMicroDeg * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR);</span>
}
} else {
<span class="fc bfc" id="L909" title="All 2 branches covered."> if (mapcodeZone.getLatFractionMin() < (extremeLatMicroDeg * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR)) {</span>
<span class="fc" id="L910"> mapcodeZone.setLatFractionMin(extremeLatMicroDeg * Point.LAT_MICRODEG_TO_FRACTIONS_FACTOR);</span>
}
}
<span class="fc" id="L913"> return mapcodeZone;</span>
}
private static boolean isAbjadScript(@Nonnull final String argStr) {
<span class="fc bfc" id="L917" title="All 2 branches covered."> for (final char ch : argStr.toCharArray()) {</span>
<span class="fc" id="L918"> final int c = (int) ch;</span>
<span class="fc bfc" id="L919" title="All 4 branches covered."> if ((c >= 0x0628) && (c <= 0x0649)) {</span>
<span class="fc" id="L920"> return true; // Arabic</span>
}
<span class="fc bfc" id="L922" title="All 4 branches covered."> if ((c >= 0x05d0) && (c <= 0x05ea)) {</span>
<span class="fc" id="L923"> return true; // Hebrew</span>
}
<span class="fc bfc" id="L925" title="All 4 branches covered."> if ((c >= 0x388) && (c <= 0x3C9)) {</span>
<span class="fc" id="L926"> return true; // Greek uppercase and lowercase</span>
}
<span class="pc bpc" id="L928" title="3 of 8 branches missed."> if (((c >= 0x1100) && (c <= 0x1174)) || ((c >= 0xad6c) && (c <= 0xd314))) {</span>
<span class="fc" id="L929"> return true; // Korean</span>
}
}
<span class="fc" id="L932"> return false;</span>
}
@Nonnull
private static String convertFromAbjad(@Nonnull final String mapcode) {
// split into prefix, s, postfix
<span class="fc" id="L938"> int p = mapcode.lastIndexOf(' ');</span>
<span class="fc bfc" id="L939" title="All 2 branches covered."> if (p < 0) {</span>
<span class="fc" id="L940"> p = 0;</span>
} else {
<span class="fc" id="L942"> p++;</span>
}
<span class="fc" id="L944"> final String prefix = mapcode.substring(0, p);</span>
<span class="fc" id="L945"> final String remainder = mapcode.substring(p);</span>
final String postfix;
<span class="fc" id="L947"> final int h = remainder.indexOf('-');</span>
final String s;
<span class="fc bfc" id="L949" title="All 2 branches covered."> if (h > 0) {</span>
<span class="fc" id="L950"> postfix = remainder.substring(h);</span>
<span class="fc" id="L951"> s = aeuUnpack(remainder.substring(0, h));</span>
} else {
<span class="fc" id="L953"> postfix = "";</span>
<span class="fc" id="L954"> s = aeuUnpack(remainder);</span>
}
<span class="fc" id="L957"> final int len = s.length();</span>
<span class="fc" id="L958"> final int dot = s.indexOf('.');</span>
<span class="pc bpc" id="L959" title="1 of 4 branches missed."> if ((dot < 2) || (dot > 5)) {</span>
<span class="fc" id="L960"> return mapcode;</span>
}
<span class="fc" id="L962"> final int form = (10 * dot) + (len - dot - 1);</span>
<span class="fc" id="L964"> String newstr = "";</span>
<span class="fc bfc" id="L965" title="All 2 branches covered."> if (form == 23) {</span>
<span class="fc" id="L966"> final int c = (DECODE_CHARS[(int) s.charAt(3)] * 8) + (DECODE_CHARS[(int) s.charAt(4)] - 18);</span>
<span class="pc bpc" id="L967" title="2 of 4 branches missed."> if ((c >= 0) && (c < 31)) {</span>
<span class="fc" id="L968"> newstr = s.substring(0, 2) + '.' + Data.ENCODE_CHARS[c] + s.charAt(5);</span>
}
<span class="fc bfc" id="L970" title="All 2 branches covered."> } else if (form == 24) {</span>
<span class="fc" id="L971"> final int c = (DECODE_CHARS[(int) s.charAt(3)] * 8) + (DECODE_CHARS[(int) s.charAt(4)] - 18);</span>
<span class="pc bpc" id="L972" title="1 of 4 branches missed."> if ((c >= 32) && (c < 63)) {</span>
<span class="fc" id="L973"> newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c - 32] + '.' + s.charAt(5) + s.charAt(6);</span>
<span class="pc bpc" id="L974" title="2 of 4 branches missed."> } else if ((c >= 0) && (c < 31)) {</span>
<span class="fc" id="L975"> newstr = s.substring(0, 2) + '.' + Data.ENCODE_CHARS[c % 31] + s.charAt(5) + s.charAt(6);</span>
}
<span class="fc bfc" id="L977" title="All 2 branches covered."> } else if (form == 34) {</span>
<span class="fc" id="L978"> final int c = (DECODE_CHARS[(int) s.charAt(2)] * 10) + (DECODE_CHARS[(int) s.charAt(5)] - 7);</span>
<span class="pc bpc" id="L979" title="1 of 4 branches missed."> if ((c >= 0) && (c < 31)) {</span>
<span class="fc" id="L980"> newstr = s.substring(0, 2) + '.' + Data.ENCODE_CHARS[c] + s.charAt(4) + s.charAt(6) + s.charAt(7);</span>
<span class="pc bpc" id="L981" title="1 of 4 branches missed."> } else if ((c >= 31) && (c < 62)) {</span>
<span class="fc" id="L982"> newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c - 31] + '.' + s.charAt(4) + s.charAt(6) + s.charAt(7);</span>
<span class="pc bpc" id="L983" title="2 of 4 branches missed."> } else if ((c >= 62) && (c < 93)) {</span>
<span class="fc" id="L984"> newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c - 62] + s.charAt(4) + '.' + s.charAt(6) + s.charAt(7);</span>
}
<span class="fc bfc" id="L986" title="All 2 branches covered."> } else if (form == 35) {</span>
<span class="fc" id="L987"> final int c = ((DECODE_CHARS[(int) s.charAt(2)] * 8) + (DECODE_CHARS[(int) s.charAt(6)] - 18));</span>
<span class="pc bpc" id="L988" title="1 of 4 branches missed."> if ((c >= 32) && (c < 63)) {</span>
<span class="fc" id="L989"> newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c - 32] + s.charAt(4) + '.' + s.charAt(5) + s.charAt(7) +</span>
<span class="fc" id="L990"> s.charAt(8);</span>
<span class="pc bpc" id="L991" title="2 of 4 branches missed."> } else if ((c >= 0) && (c < 31)) {</span>
<span class="fc" id="L992"> newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c] + '.' + s.charAt(4) + s.charAt(5) + s.charAt(7) +</span>
<span class="fc" id="L993"> s.charAt(8);</span>
}
<span class="fc bfc" id="L995" title="All 2 branches covered."> } else if (form == 45) {</span>
<span class="fc" id="L996"> final int c = (DECODE_CHARS[(int) s.charAt(2)] * 100) + (DECODE_CHARS[(int) s.charAt(5)] * 10) +</span>
<span class="fc" id="L997"> (DECODE_CHARS[(int) s.charAt(8)] - 39);</span>
<span class="pc bpc" id="L998" title="2 of 4 branches missed."> if ((c >= 0) && (c < 961)) {</span>
<span class="fc" id="L999"> newstr = s.substring(0, 2) + Data.ENCODE_CHARS[c / 31] + s.charAt(3) + '.' + s.charAt(6) + s.charAt(7) +</span>
<span class="fc" id="L1000"> s.charAt(9) + Data.ENCODE_CHARS[c % 31];</span>