@@ -49,7 +49,7 @@ public abstract class RadixIdConverter implements IdConverter {
4949 * 122.
5050 */
5151 static final char LOWERCASE_Z = 'z' ;
52-
52+
5353 static final char [] digits = {
5454 /*
5555 * offset: 0.
@@ -69,13 +69,13 @@ public abstract class RadixIdConverter implements IdConverter {
6969 LOWERCASE_A , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' ,
7070 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , LOWERCASE_Z ,
7171 };
72-
72+
7373 public static final char PAD_CHAR = ZERO ;
74-
74+
7575 private final boolean padStart ;
7676 private final int charSize ;
7777 private final long maxId ;
78-
78+
7979 protected RadixIdConverter (boolean padStart , int charSize ) {
8080 Preconditions .checkArgument (charSize > 0 && charSize <= getMaxCharSize (), "charSize cannot be greater than MAX_CHAR_SIZE[%s]!" , getMaxCharSize ());
8181 this .padStart = padStart ;
@@ -86,7 +86,7 @@ protected RadixIdConverter(boolean padStart, int charSize) {
8686 this .maxId = Double .valueOf (Math .pow (getRadix (), charSize )).longValue ();
8787 }
8888 }
89-
89+
9090 public static int offset (char digitChar ) {
9191 if (digitChar >= ZERO && digitChar <= NINE ) {
9292 return digitChar - ZERO ;
@@ -99,7 +99,7 @@ public static int offset(char digitChar) {
9999 }
100100 return -1 ;
101101 }
102-
102+
103103 public static int maxCharSize (int radix , int bits ) {
104104 long maxId = ~(-1L << bits );
105105 int divideTimes = 0 ;
@@ -109,34 +109,34 @@ public static int maxCharSize(int radix, int bits) {
109109 }
110110 return divideTimes ;
111111 }
112-
112+
113113 boolean isPadStart () {
114114 return padStart ;
115115 }
116-
116+
117117 public int getCharSize () {
118118 return charSize ;
119119 }
120-
120+
121121 public long getMaxId () {
122122 return maxId ;
123123 }
124-
124+
125125 abstract int getRadix ();
126-
126+
127127 abstract int getMaxCharSize ();
128-
128+
129129 @ Override
130130 public @ NonNull String asString (long id ) {
131-
131+
132132 Preconditions .checkArgument (id > -1 , "id[%s] must be greater than -1!" , id );
133-
133+
134134 final int maxCharSize = getMaxCharSize ();
135-
135+
136136 if (charSize < maxCharSize ) {
137137 Preconditions .checkArgument (id < maxId , "id[%s] cannot be greater than maxId:[%s]!" , id , maxId );
138138 }
139-
139+
140140 char [] buf = new char [charSize ];
141141 int charIdx = charSize ;
142142 final int radix = getRadix ();
@@ -145,16 +145,17 @@ public long getMaxId() {
145145 buf [--charIdx ] = digits [mod ];
146146 id = id / radix ;
147147 }
148-
148+
149149 if (padStart && charIdx > 0 ) {
150150 while (charIdx > 0 ) {
151151 buf [--charIdx ] = PAD_CHAR ;
152152 }
153153 }
154-
154+
155155 return new String (buf , charIdx , (charSize - charIdx ));
156156 }
157-
157+
158+ @ Override
158159 public long asLong (@ NonNull String idString ) {
159160 char firstChar = idString .charAt (0 );
160161 if (firstChar < ZERO ) {
@@ -178,7 +179,7 @@ public long asLong(@NonNull String idString) {
178179 }
179180 return result ;
180181 }
181-
182+
182183 @ Override
183184 public Stat stat () {
184185 return new RadixConverterStat (getClass ().getSimpleName (), getRadix (), getCharSize (), isPadStart (), getMaxId ());
0 commit comments