3434class Encoder {
3535 private static final Logger LOG = LoggerFactory .getLogger (Encoder .class );
3636
37+ private Encoder () {
38+ // Prevent instantiation.
39+ }
40+
3741 // ----------------------------------------------------------------------
3842 // Method called from public Java API.
3943 // ----------------------------------------------------------------------
@@ -84,7 +88,7 @@ else if (lonDeg < -180) {
8488
8589 final Point pointToEncode = Point .fromDeg (latDeg , lonDeg );
8690 final List <SubArea > areas = SubArea .getAreasForPoint (pointToEncode );
87- final List <Mapcode > results = new ArrayList <Mapcode >();
91+ final List <Mapcode > results = new ArrayList <>();
8892
8993 int lastbasesubareaID = -1 ;
9094
@@ -95,8 +99,8 @@ else if (lonDeg < -180) {
9599
96100 final Territory currentEncodeTerritory = subArea .getParentTerritory ();
97101
98- if (currentEncodeTerritory == Territory .AAA && !allowWorld &&
99- territory != Territory .AAA ) {
102+ if (( currentEncodeTerritory == Territory .AAA ) && !allowWorld &&
103+ ( territory != Territory .AAA ) ) {
100104 continue ;
101105 }
102106
@@ -110,10 +114,10 @@ else if (lonDeg < -180) {
110114
111115 final int i = subArea .getSubAreaID ();
112116 mapcoderData .dataSetup (i );
113- if (mapcoderData .getCodex () < 54 && mapcoderData .getMapcoderRect ().containsPoint (pointToEncode )) {
117+ if (( mapcoderData .getCodex () < 54 ) && mapcoderData .getMapcoderRect ().containsPoint (pointToEncode )) {
114118 String mapcode = "" ;
115119 final Territory territoryParent = currentEncodeTerritory .getParentTerritory ();
116- if (mapcoderData .isUseless () && i == upto && territoryParent != null ) {
120+ if (mapcoderData .isUseless () && ( i == upto ) && ( territoryParent != null ) ) {
117121
118122 if (!isRecursive ) {
119123 stateOverride = currentEncodeTerritory ;
@@ -124,8 +128,8 @@ else if (lonDeg < -180) {
124128
125129 continue ;
126130 }
127- if (mapcoderData .getPipeType () == 0 && !mapcoderData .isNameless ()) {
128- if (!mapcoderData .isUseless () || lastbasesubareaID == from ) {
131+ if (( mapcoderData .getPipeType () == 0 ) && !mapcoderData .isNameless ()) {
132+ if (!mapcoderData .isUseless () || ( lastbasesubareaID == from ) ) {
129133 mapcode = encodeGrid (i , pointToEncode , mapcoderData );
130134 }
131135 }
@@ -179,10 +183,10 @@ private static String addPostfix(final int extrax4, final int extray, final int
179183 final int gy = ((30 * extray ) / dividery );
180184 final int x1 = (gx / 6 );
181185 final int y1 = (gy / 5 );
182- String s = "-" + encode_chars [y1 * 5 + x1 ];
186+ String s = "-" + encode_chars [(( y1 * 5 ) + x1 ) ];
183187 final int x2 = (gx % 6 );
184188 final int y2 = (gy % 5 );
185- s += encode_chars [y2 * 6 + x2 ];
189+ s += encode_chars [(( y2 * 6 ) + x2 ) ];
186190 return s ;
187191 }
188192
@@ -206,12 +210,12 @@ private static String encodeGrid(final int m, final Point point, final Data mapc
206210 }
207211
208212 final int ygridsize =
209- (mapcoderData .getMapcoderRect ().getMaxY () - mapcoderData .getMapcoderRect ().getMinY () + divy - 1 )
213+ ((( mapcoderData .getMapcoderRect ().getMaxY () - mapcoderData .getMapcoderRect ().getMinY ()) + divy ) - 1 )
210214 / divy ;
211215 int rely = pointToEncode .getLatMicroDeg () - mapcoderData .getMapcoderRect ().getMinY ();
212216 rely = rely / ygridsize ;
213217 final int xgridsize =
214- (mapcoderData .getMapcoderRect ().getMaxX () - mapcoderData .getMapcoderRect ().getMinX () + divx - 1 )
218+ ((( mapcoderData .getMapcoderRect ().getMaxX () - mapcoderData .getMapcoderRect ().getMinX ()) + divx ) - 1 )
215219 / divx ;
216220
217221 int relx = pointToEncode .getLonMicroDeg () - mapcoderData .getMapcoderRect ().getMinX ();
@@ -234,25 +238,25 @@ else if (relx >= 360000000) {
234238 }
235239
236240 final int v ;
237- if (divx != divy && codex > 24 ) // D==6
241+ if (( divx != divy ) && ( codex > 24 ) ) // D==6
238242 {
239243 v = encode6 (relx , rely , divx , divy );
240244 }
241245 else {
242- v = relx * divy + divy - 1 - rely ;
246+ v = (( relx * divy ) + divy ) - 1 - rely ;
243247 }
244248
245249 String result = fastEncode (v , dc );
246250
247- if (dc == 4 && divx == xSide [4 ] && divy == ySide [4 ]) {
251+ if (( dc == 4 ) && ( divx == xSide [4 ]) && ( divy == ySide [4 ]) ) {
248252 result = String .valueOf (result .charAt (0 )) + result .charAt (2 ) + result .charAt (1 ) + result .charAt (3 );
249253 }
250254
251- rely = mapcoderData .getMapcoderRect ().getMinY () + rely * ygridsize ;
252- relx = mapcoderData .getMapcoderRect ().getMinX () + relx * xgridsize ;
255+ rely = mapcoderData .getMapcoderRect ().getMinY () + ( rely * ygridsize ) ;
256+ relx = mapcoderData .getMapcoderRect ().getMinX () + ( relx * xgridsize ) ;
253257
254- final int dividery = (ygridsize + ySide [codexlow ] - 1 ) / ySide [codexlow ];
255- final int dividerx = (xgridsize + xSide [codexlow ] - 1 ) / xSide [codexlow ];
258+ final int dividery = (( ygridsize + ySide [codexlow ]) - 1 ) / ySide [codexlow ];
259+ final int dividerx = (( xgridsize + xSide [codexlow ]) - 1 ) / xSide [codexlow ];
256260
257261 result += '.' ;
258262
@@ -275,7 +279,7 @@ else if (relx >= 360000000) {
275279 }
276280 else {
277281
278- String postfix = fastEncode ((difx ) * ySide [nrchars ] + dify , nrchars );
282+ String postfix = fastEncode ((( difx ) * ySide [nrchars ]) + dify , nrchars );
279283 if (nrchars == 4 ) {
280284 postfix = String .valueOf (postfix .charAt (0 )) + postfix .charAt (2 ) + postfix .charAt (1 ) + postfix .charAt (3 );
281285 }
@@ -300,11 +304,12 @@ private static String encodeStarpipe(final Point pointToEncode, final Data mapco
300304
301305 // search back to first pipe star
302306 int firstindex = thisindex ;
303- while (Data .calcStarPipe (firstindex - 1 ) && Data .calcCodexLen (firstindex - 1 ) == thiscodexlen ) {
307+ while (Data .calcStarPipe (firstindex - 1 ) && ( Data .calcCodexLen (firstindex - 1 ) == thiscodexlen ) ) {
304308 firstindex --;
305309 }
306310
307- for (int i = firstindex ; ; i ++) {
311+ int i = firstindex ;
312+ while (true ) {
308313 if (Data .calcCodexLen (i ) != thiscodexlen ) {
309314 return starpipe_result .toString ();
310315 }
@@ -316,26 +321,27 @@ private static String encodeStarpipe(final Point pointToEncode, final Data mapco
316321 final int minx = mapcoderData .getMapcoderRect ().getMinX ();
317322 final int miny = mapcoderData .getMapcoderRect ().getMinY ();
318323
319- int h = (maxy - miny + 89 ) / 90 ;
324+ int h = (( maxy - miny ) + 89 ) / 90 ;
320325 final int xdiv = xDivider (miny , maxy );
321- int w = ((maxx - minx ) * 4 + xdiv - 1 ) / xdiv ;
326+ int w = (((( maxx - minx ) * 4 ) + xdiv ) - 1 ) / xdiv ;
322327
323- h = 176 * ((h + 176 - 1 ) / 176 );
324- w = 168 * ((w + 168 - 1 ) / 168 );
328+ h = 176 * ((( h + 176 ) - 1 ) / 176 );
329+ w = 168 * ((( w + 168 ) - 1 ) / 168 );
325330
326331 int product = (w / 168 ) * (h / 176 ) * 961 * 31 ;
327332
328- final int goodRounder = mapcoderData .getCodex () >= 23 ? 961 * 961 * 31 : 961 * 961 ;
333+ final int goodRounder = ( mapcoderData .getCodex () >= 23 ) ? ( 961 * 961 * 31 ) : ( 961 * 961 ) ;
329334 if (mapcoderData .getPipeType () == 8 ) // *+
330335 {
331- product = ((storageStart + product + goodRounder - 1 ) / goodRounder ) * goodRounder - storageStart ;
336+ product =
337+ ((((storageStart + product + goodRounder ) - 1 ) / goodRounder ) * goodRounder ) - storageStart ;
332338 }
333339
334- if (i == thisindex && mapcoderData .getMapcoderRect ().containsPoint (pointToEncode )) {
335- final int dividerx = (maxx - minx + w - 1 ) / w ;
340+ if (( i == thisindex ) && mapcoderData .getMapcoderRect ().containsPoint (pointToEncode )) {
341+ final int dividerx = ((( maxx - minx ) + w ) - 1 ) / w ;
336342 int vx = (pointToEncode .getLonMicroDeg () - minx ) / dividerx ;
337343 final int extrax = (pointToEncode .getLonMicroDeg () - minx ) % dividerx ;
338- final int dividery = (maxy - miny + h - 1 ) / h ;
344+ final int dividery = ((( maxy - miny ) + h ) - 1 ) / h ;
339345 int vy = (maxy - pointToEncode .getLatMicroDeg ()) / dividery ;
340346 final int extray = (maxy - pointToEncode .getLatMicroDeg ()) % dividery ;
341347 final int spx = vx % 168 ;
@@ -345,9 +351,9 @@ private static String encodeStarpipe(final Point pointToEncode, final Data mapco
345351 vy = vy / 176 ;
346352
347353 // PIPELETTER ENCODE
348- final int value = vx * (h / 176 ) + vy ;
354+ final int value = ( vx * (h / 176 ) ) + vy ;
349355
350- starpipe_result .append (fastEncode (storageStart / (961 * 31 ) + value ,
356+ starpipe_result .append (fastEncode (( storageStart / (961 * 31 ) ) + value ,
351357 mapcoderData .getCodexLen () - 2 ));
352358 starpipe_result .append ('.' );
353359 starpipe_result .append (encodeTriple (spx , spy ));
@@ -359,6 +365,7 @@ private static String encodeStarpipe(final Point pointToEncode, final Data mapco
359365 }
360366 storageStart += product ;
361367 }
368+ i ++;
362369 }
363370 }
364371
@@ -383,22 +390,22 @@ private static String encodeNameless(final Point pointToEncode, final Data mapco
383390 if (a > 1 ) {
384391 int storage_offset ;
385392
386- if (mapcoderData .getCodex () != 21 && a <= 31 ) {
387- storage_offset = (nrX * p + (nrX < r ? nrX : r )) * (961 * 961 );
393+ if (( mapcoderData .getCodex () != 21 ) && ( a <= 31 ) ) {
394+ storage_offset = (( nrX * p ) + (( nrX < r ) ? nrX : r )) * (961 * 961 );
388395 }
389- else if (mapcoderData .getCodex () != 21 && a < 62 ) {
390- if (nrX < 62 - a ) {
396+ else if (( mapcoderData .getCodex () != 21 ) && ( a < 62 ) ) {
397+ if (nrX < ( 62 - a ) ) {
391398 storage_offset = nrX * 961 * 961 ;
392399 }
393400 else {
394- storage_offset = (62 - a + (nrX - 62 + a ) / 2 ) * 961 * 961 ;
401+ storage_offset = (( 62 - a ) + ((( nrX - 62 ) + a ) / 2 ) ) * 961 * 961 ;
395402 if (((nrX + a ) & 1 ) != 0 ) {
396403 storage_offset += 16 * 961 * 31 ;
397404 }
398405 }
399406 }
400407 else {
401- final int basePower = (mapcoderData .getCodex () == 21 ) ? 961 * 961 : 961 * 961 * 31 ;
408+ final int basePower = (mapcoderData .getCodex () == 21 ) ? ( 961 * 961 ) : ( 961 * 961 * 31 ) ;
402409 int basePowerA = basePower / a ;
403410 if (a == 62 ) {
404411 basePowerA ++;
@@ -415,7 +422,7 @@ else if (mapcoderData.getCodex() != 21 && a < 62) {
415422 int xSide = side ;
416423 if (mapcoderData .isSpecialShape ()) {
417424 xSide *= side ;
418- side = 1 + (maxy - miny ) / 90 ;
425+ side = 1 + (( maxy - miny ) / 90 ) ;
419426 xSide = xSide / side ;
420427 }
421428
@@ -425,7 +432,7 @@ else if (mapcoderData.getCodex() != 21 && a < 62) {
425432 final int dx = (4 * (x - minx )) / dividerx4 ;
426433 // div with floating point value
427434
428- final int extrax4 = (x - minx ) * 4 - (dx * dividerx4 ); // like modulus, but with floating point value
435+ final int extrax4 = (( x - minx ) * 4 ) - (dx * dividerx4 ); // like modulus, but with floating point value
429436
430437 final int dividery = 90 ;
431438 final int dy = (maxy - y ) / dividery ;
@@ -435,7 +442,7 @@ else if (mapcoderData.getCodex() != 21 && a < 62) {
435442 v += encode6 (dx , side - 1 - dy , xSide , side );
436443 }
437444 else {
438- v += dx * side + dy ;
445+ v += ( dx * side ) + dy ;
439446 }
440447
441448 String result = fastEncode (v , mapcoderData .getCodexLen () + 1 );
@@ -444,7 +451,7 @@ else if (mapcoderData.getCodex() != 21 && a < 62) {
444451 result = result .substring (0 , 2 ) + '.' + result .substring (2 );
445452 }
446453 else if (mapcoderData .getCodexLen () == 4 ) {
447- if (mapcoderData .getCodex () == 22 && a < 62 && orgSide == 961 && !mapcoderData .isSpecialShape ()) {
454+ if (( mapcoderData .getCodex () == 22 ) && ( a < 62 ) && ( orgSide == 961 ) && !mapcoderData .isSpecialShape ()) {
448455 result = result .substring (0 , 2 ) + result .charAt (3 ) + result .charAt (2 ) + result .charAt (4 );
449456 }
450457 if (mapcoderData .getCodex () == 13 ) {
@@ -468,9 +475,9 @@ private static String aeuPack(final String argStr) {
468475 int d ;
469476 String rest = "" ;
470477 for (d = 0 ; d < rlen ; d ++) {
471- if (str .charAt (d ) < '0' || str .charAt (d ) > '9' ) // not digit?
478+ if (( str .charAt (d ) < '0' ) || ( str .charAt (d ) > '9' ) ) // not digit?
472479 {
473- if (str .charAt (d ) == '.' && dotpos < 0 ) // first dot?
480+ if (( str .charAt (d ) == '.' ) && ( dotpos < 0 ) ) // first dot?
474481 {
475482 dotpos = d ;
476483 }
@@ -485,10 +492,10 @@ else if (str.charAt(d) == '-') {
485492 }
486493 }
487494
488- if (rlen - 2 > dotpos ) {
495+ if (( rlen - 2 ) > dotpos ) {
489496 // does r have a dot, AND at least 2 chars
490497 // after the dot?
491- final int v = (((int ) str .charAt (rlen - 2 )) - 48 ) * 10 + ((int ) str .charAt (rlen - 1 )) - 48 ;
498+ final int v = ((((( int ) str .charAt (rlen - 2 )) - 48 ) * 10 ) + ((int ) str .charAt (rlen - 1 ) )) - 48 ;
492499 final int last = v % 34 ;
493500 final char [] vowels = {'A' , 'E' , 'U' };
494501 str =
@@ -515,17 +522,17 @@ private static int encode6(final int x, final int y, final int width, final int
515522 final int maxcol = (width - 4 ) / 6 ;
516523 if (col >= maxcol ) {
517524 col = maxcol ;
518- d = width - maxcol * 6 ;
525+ d = width - ( maxcol * 6 ) ;
519526 }
520- return height * 6 * col + (height - 1 - y ) * d + x - col * 6 ;
527+ return (( height * 6 * col ) + (( height - 1 - y ) * d ) + x ) - ( col * 6 ) ;
521528 }
522529
523530 private static String encodeTriple (final int difx , final int dify ) {
524- if (dify < 4 * 34 ) {
525- return encode_chars [difx / 28 + 6 * (dify / 34 )] + fastEncode ((difx % 28 ) * 34 + dify % 34 , 2 );
531+ if (dify < ( 4 * 34 ) ) {
532+ return encode_chars [(( difx / 28 ) + ( 6 * (dify / 34 ))) ] + fastEncode ((( difx % 28 ) * 34 ) + ( dify % 34 ) , 2 );
526533 }
527534 else {
528- return encode_chars [difx / 24 + 24 ] + fastEncode ((difx % 24 ) * 40 + dify - 136 , 2 );
535+ return encode_chars [(( difx / 24 ) + 24 ) ] + fastEncode (((( difx % 24 ) * 40 ) + dify ) - 136 , 2 );
529536 }
530537 }
531538}
0 commit comments