Debian Codegraph @

current/shared/Parse.java

raw symbols SCIP
1 package shared;
2
3 import structures.ByteBuilder;
4 import structures.LongList;
5
6 public class Parse {
7
8
9 public static int parseIntKMG(String b){
10 long x=parseKMG(b);
11 assert(x<=Integer.MAX_VALUE && x>Integer.MIN_VALUE) : "Value "+x+" is out of range for integers: "+b;
12 return (int)x;
13 }
14
15 public static long parseKMG(final String b0){
16 String b=b0;
17 if(b==null){return 0;}
18 assert(b.length()>0);
19 final char c=Tools.toLowerCase(b.charAt(b.length()-1));
20 final boolean dot=b.indexOf('.')>=0;
21 if(!dot && !Tools.isLetter(c)){return Long.parseLong(b);}
22 // if(!Tools.isLetter(c) && !dot){return Long.parseLong(b);}
23
24 if(b.equalsIgnoreCase("big") || b.equalsIgnoreCase("inf") || b.equalsIgnoreCase("infinity") || b.equalsIgnoreCase("max") || b.equalsIgnoreCase("huge")){
25 return Long.MAX_VALUE;
26 }
27
28 long mult=1;
29 if(Tools.isLetter(c)){
30 if(c=='k'){mult=1000;}
31 else if(c=='m'){mult=1000000;}
32 else if(c=='g' || c=='b'){mult=1000000000;}
33 else if(c=='t'){mult=1000000000000L;}
34 else if(c=='p' || c=='q'){mult=1000000000000000L;}
35 else if(c=='e'){mult=1000000000000000000L;}
36 // else if(c=='z'){mult=1000000000000000000000L;}//Out of range
37 else if(c=='c' || c=='h'){mult=100;}
38 else if(c=='d'){mult=10;}
39 else{throw new RuntimeException(b);}
40 b=b.substring(0, b.length()-1);
41 }
42 assert(!Tools.endsWithLetter(b)) : "Too many letters at the end of "+b0;
43
44 //Calculate product, check for overflow, and return
45 if(!dot){
46 long m=Long.parseLong(b);
47 long p=m*mult;
48 assert(p>=m) : p+", "+m+", "+b;
49 return p;
50 }else{
51 double m=Double.parseDouble(b);
52 long p=(long)(m*mult);
53 assert(p>=m) : p+", "+m+", "+b;
54 return p;
55 }
56 }
57
58 public static double parseDoubleKMG(final String b0){
59 String b=b0;
60 if(b==null){return 0;}
61 assert(b.length()>0);
62 final char c=Tools.toLowerCase(b.charAt(b.length()-1));
63 final boolean dot=b.indexOf('.')>=0;
64 if(!dot && !Tools.isLetter(c)){return Long.parseLong(b);}
65 // if(!Tools.isLetter(c) && !dot){return Long.parseLong(b);}
66
67 if(b.equalsIgnoreCase("big") || b.equalsIgnoreCase("inf") || b.equalsIgnoreCase("infinity") || b.equalsIgnoreCase("max") || b.equalsIgnoreCase("huge")){
68 return Long.MAX_VALUE;
69 }
70
71 long mult=1;
72 if(Tools.isLetter(c)){
73 if(c=='k'){mult=1000;}
74 else if(c=='m'){mult=1000000;}
75 else if(c=='g' || c=='b'){mult=1000000000;}
76 else if(c=='t'){mult=1000000000000L;}
77 else if(c=='p' || c=='q'){mult=1000000000000000L;}
78 else if(c=='e'){mult=1000000000000000000L;}
79 // else if(c=='z'){mult=1000000000000000000000L;}//Out of range
80 else if(c=='c' || c=='h'){mult=100;}
81 else if(c=='d'){mult=10;}
82 else if(c=='f'){/* Ignore */}
83 else{throw new RuntimeException(b);}
84 b=b.substring(0, b.length()-1);
85 }
86 assert(!Tools.endsWithLetter(b)) : "Too many letters at the end of "+b0;
87
88 //Calculate product, check for overflow, and return
89 if(!dot){
90 double m=Double.parseDouble(b);
91 double p=m*mult;
92 assert(m<0 || p>=m) : p+", "+m+", "+b;
93 return p;
94 }else{
95 double m=Double.parseDouble(b);
96 double p=m*mult;
97 assert(m<0 || p>=m) : p+", "+m+", "+b;
98 return p;
99 }
100 }
101
102 public static long parseKMGBinary(String b){
103 if(b==null){return 0;}
104 char c=Tools.toLowerCase(b.charAt(b.length()-1));
105 boolean dot=b.indexOf('.')>=0;
106 if(!Tools.isLetter(c) && !dot){return Long.parseLong(b);}
107
108 long mult=1;
109 if(Tools.isLetter(c)){
110 if(c=='k'){mult=1024;}
111 else if(c=='m'){mult=1024*1024;}
112 else if(c=='g' || c=='b'){mult=1024*1024*1024;}
113 else if(c=='t'){mult=1024L*1024L*1024L*1024L;}
114 else{throw new RuntimeException(b);}
115 b=b.substring(0, b.length()-1);
116 }
117
118 if(!dot){return Long.parseLong(b)*mult;}
119
120 return (long)(Double.parseDouble(b)*mult);
121 }
122
123 public static boolean isNumber(String s){
124 if(s==null || s.length()==0){return false;}
125 char c=s.charAt(0);
126 return Tools.isDigit(c) || c=='.' || c=='-';
127 }
128
129 /**
130 * Parse this argument. More liberal than Boolean.parseBoolean.
131 * Null, t, true, or 1 all yield true.
132 * Everything else, including the String "null", is false.
133 * @param s Argument to parse
134 * @return boolean form
135 */
136 public static boolean parseBoolean(String s){
137 if(s==null || s.length()<1){return true;}
138 if(s.length()==1){
139 char c=Tools.toLowerCase(s.charAt(0));
140 return c=='t' || c=='1';
141 }
142 if(s.equalsIgnoreCase("null") || s.equalsIgnoreCase("none")){return false;}
143 return Boolean.parseBoolean(s);
144 }
145
146 public static boolean parseYesNo(String s){
147 if(s==null || s.length()<1){return true;}
148 if(s.length()==1){
149 char c=Tools.toLowerCase(s.charAt(0));
150 if(c=='y'){return true;}
151 if(c=='n'){return false;}
152 throw new RuntimeException(s);
153 }
154
155 if(s.equalsIgnoreCase("yes")){return true;}
156 if(s.equalsIgnoreCase("no")){return false;}
157 if(s.equalsIgnoreCase("unknown")){return false;} //Special case for IMG database
158
159 throw new RuntimeException(s);
160 }
161
162 public static float[] parseFloatArray(String s, String regex){return parseFloatArray(s, regex, null);}
163
164 public static float[] parseFloatArray(String s, String regex, String wildcard){
165 if(s==null || "null".equals(s)){return null;}
166 String[] split=s.split(regex);
167 float[] array=new float[split.length];
168 for(int i=0; i<split.length; i++){
169 array[i]=(split[i].equals(wildcard)) ? -1 : Float.parseFloat(split[i]);
170 }
171 return array;
172 }
173
174 public static int[] parseIntArray(String s, String regex){return parseIntArray(s, regex, null);}
175
176 public static int[] parseIntArray(String s, String regex, String wildcard){
177 if(s==null || "null".equals(s)){return null;}
178 String[] split=s.split(regex);
179 int[] array=new int[split.length];
180 for(int i=0; i<split.length; i++){
181 array[i]=(split[i].equals(wildcard)) ? -1 : Integer.parseInt(split[i]);
182 }
183 return array;
184 }
185
186 public static byte[] parseByteArray(String s, String regex){
187 if(s==null){return null;}
188 String[] split=s.split(regex);
189 byte[] array=new byte[split.length];
190 for(int i=0; i<split.length; i++){
191 array[i]=Byte.parseByte(split[i]);
192 }
193 return array;
194 }
195
196 public static int parseIntHexDecOctBin(final String s){
197 if(s==null || s.length()<1){return 0;}
198 int radix=10;
199 if(s.length()>1 && s.charAt(1)=='0'){
200 final char c=s.charAt(1);
201 if(c=='x' || c=='X'){radix=16;}
202 else if(c=='b' || c=='B'){radix=2;}
203 else if(c=='o' || c=='O'){radix=8;}
204 }
205 return Integer.parseInt(s, radix);
206 }
207
208 /**
209 * @param array Text
210 * @param a Index of first digit
211 * @param b Index after last digit (e.g., array.length)
212 * @return Parsed number
213 */
214 public static float parseFloat(byte[] array, int a, int b){
215 return (float)parseDouble(array, a, b);
216 }
217
218 /**
219 * @param array Text
220 * @param a Index of first digit
221 * @param b Index after last digit (e.g., array.length)
222 * @return Parsed number
223 */
224 public static float parseFloat(String array, int a, int b){
225 return (float)parseDouble(array, a, b);
226 }
227
228 public static float parseFloat(String s, String term, char delimiter) {
229 return (float)parseDouble(s, term, delimiter);
230 }
231
232 public static double parseDouble(String s, String term, char delimiter) {
233 int idx=s.indexOf(term);
234 assert(idx>=0) : "No "+term+" in String: '"+s+"'";
235 idx+=term.length();
236 int idx2=Tools.indexOf(s, delimiter, idx);
237 idx2=(idx2<0 ? s.length() : idx2);
238 double d=Parse.parseDouble(s, idx, idx2);
239 return d;
240 }
241
242 public static String parseString(String s, String term, char delimiter) {
243 int idx=s.indexOf(term);
244 // assert(idx>=0) : "No "+term+" in String: '"+s+"'";
245 if(idx<0) {return null;}
246 idx+=term.length();
247 int idx2=Tools.indexOf(s, delimiter, idx);
248 idx2=(idx2<0 ? s.length() : idx2);
249 return s.substring(idx, idx2);
250 }
251
252 /**
253 * @param array Text
254 * @param a Index of first digit
255 * @param b Index after last digit (e.g., array.length)
256 * @return Parsed number
257 */
258 public static double parseDoubleSlow(byte[] array, int a, int b){
259 String s=new String(array, a, b-a);
260 return Double.parseDouble(s);
261 }
262
263 public static double parseDouble(final byte[] array, final int start){
264 return parseDouble(array, start, array.length);
265 }
266
267 /**
268 * @param array Text
269 * @param a0 Index of first digit
270 * @param b Index after last digit (e.g., array.length)
271 * @return Parsed number
272 */
273 public static double parseDouble(final byte[] array, final int a0, final int b){
274 if(Tools.FORCE_JAVA_PARSE_DOUBLE){
275 return Double.parseDouble(new String(array, a0, b-a0));
276 }
277 int a=a0;
278 assert(b>a);
279 long upper=0;
280 final byte z='0';
281 long mult=1;
282 if(array[a]=='-'){mult=-1; a++;}
283
284 for(; a<b; a++){
285 final byte c=array[a];
286 if(c=='.'){break;}
287 final int x=(c-z);
288 assert(x<10 && x>=0) : x+" = "+(char)c+"\narray="+new String(array)+", start="+a+", stop="+b;
289 upper=(upper*10)+x;
290 }
291
292 long lower=0;
293 int places=0;
294 for(a++; a<b; a++){
295 final byte c=array[a];
296 final int x=(c-z);
297 assert(x<10 && x>=0) : x+" = "+(char)c+"\narray='"+new String(array)+"', start="+a+", stop="+b+", len="+array.length+" -> '"+new String(array, a, b-a)+"'"+
298 "\nThis function does not support exponents; if the input has an exponent, add the flag 'forceJavaParseDouble'.";
299 lower=(lower*10)+x;
300 places++;
301 }
302
303 double d=mult*(upper+lower*ByteBuilder.decimalInvMult[places]);
304 // assert(d==parseDoubleSlow(array, a0, b)) : d+", "+parseDoubleSlow(array, a0, b);
305 return d;
306 }
307
308 /**
309 * @param array Text
310 * @param a0 Index of first digit
311 * @param b Index after last digit (e.g., array.length)
312 * @return Parsed number
313 */
314 public static double parseDouble(final String array, final int a0, final int b){
315 if(Tools.FORCE_JAVA_PARSE_DOUBLE){
316 return Double.parseDouble(array.substring(a0, b));
317 }
318 int a=a0;
319 assert(b>a);
320 long upper=0;
321 final char z='0';
322 long mult=1;
323 if(array.charAt(a)=='-'){mult=-1; a++;}
324
325 for(; a<b; a++){
326 final char c=array.charAt(a);
327 if(c=='.'){break;}
328 final int x=(c-z);
329 assert(x<10 && x>=0) : x+" = "+(char)c+"\narray="+new String(array)+", start="+a+", stop="+b;
330 upper=(upper*10)+x;
331 }
332
333 long lower=0;
334 int places=0;
335 for(a++; a<b; a++){
336 final char c=array.charAt(a);
337 final int x=(c-z);
338 assert(x<10 && x>=0) : x+" = "+(char)c+"\narray='"+new String(array)+"', start="+a+", stop="+b+", len="+array.length()+" -> '"+array.substring(a, b)+"'"+
339 "\nThis function does not support exponents; if the input has an exponent, add the flag 'forceJavaParseDouble'.";
340 lower=(lower*10)+x;
341 places++;
342 }
343
344 double d=mult*(upper+lower*ByteBuilder.decimalInvMult[places]);
345 // assert(d==parseDoubleSlow(array, a0, b)) : d+", "+parseDoubleSlow(array, a0, b);
346 return d;
347 }
348
349 public static int parseInt(byte[] array, int start){
350 return parseInt(array, start, array.length);
351 }
352
353 // /**
354 // * @param array Text
355 // * @param a Index of first digit
356 // * @param b Index after last digit (e.g., array.length)
357 // * @return Parsed number
358 // */
359 // public static int parseInt(byte[] array, int a, int b){
360 // assert(b>a);
361 // int r=0;
362 // final byte z='0';
363 // int mult=1;
364 // if(array[a]=='-'){mult=-1; a++;}
365 // for(; a<b; a++){
366 // int x=(array[a]-z);
367 // assert(x<10 && x>=0) : x+" = "+(char)array[a]+"\narray="+new String(array)+", start="+a+", stop="+b;
368 // r=(r*10)+x;
369 // }
370 // return r*mult;
371 // }
372
373 /**
374 * Returns the int representation of a number represented in ASCII text, from position a to b.
375 * This function is much faster than creating a substring and calling Integer.parseInt()
376 * Throws Assertions rather than Exceptions for invalid input.
377 * This function does NOT detect overflows, e.g., values over 2^31-1 (Integer.MAX_VALUE).
378 * This function has no side-effects.
379 * @param array byte array containing the text to parse.
380 * @param a Index of the first digit of the number.
381 * @param b Index after the last digit (e.g., array.length).
382 * @return int representation of the parsed number.
383 * @throws Assertions rather than Exceptions for invalid input.
384 *
385 * @TODO Correctly represent Integer.MIN_VALUE
386 * @TODO Detect overflow.
387 */
388 public static int parseInt(byte[] array, int a, int b){
389 assert(b>a) : "The start position of the text to parse must come before the stop position: "+
390 a+","+b+","+new String(array);
391 int r=0; //Initialize the return value to 0.
392
393 //z holds the ASCII code for 0, which is subtracted from other ASCII codes
394 //to yield the int value of a character. For example, '7'-'0'=7,
395 //because ASCII '7'=55, while ASCII '0'=48, and 55-48=7.
396 final byte z='0';
397
398 //mult is 1 for positive numbers, or -1 for negative numbers.
399 //It will be multiplied by the unsigned result to yield the final signed result.
400 int mult=1;
401
402 //If the term starts with a minus sign, set the multiplier to -1 and increment the position.
403 if(array[a]=='-'){mult=-1; a++;}
404
405 //Iterate through every position, incrementing a, up to b (exclusive).
406 for(; a<b; a++){
407 //x is the numeric value of the character at position a.
408 //In other words, if array[a]='7',
409 //x would be 7, not the ASCII code for '7' (which is 55).
410 int x=(array[a]-z);
411
412 //Assert that x is in the range of 0-9; otherwise, the character was not a digit.
413 //The ASCII code will be printed here because in some cases the character could be
414 //a control character (like carriage return or vertical tab or bell) which is unprintable.
415 //But if possible the character will be printed to, as well as the position,
416 //and the entire String from which the number is to be parsed.
417 assert(x<10 && x>=0) : "Non-digit character with ASCII code "+(int)array[a]+" was encountered.\n"
418 +"x="+x+"; char="+(char)array[a]+"\narray="+new String(array)+", start="+a+", stop="+b;
419
420 //Multiply the old value by 10, then add the new 1's digit.
421 //This is because the text is assumed to be base-10,
422 //so each subsequent character will represent 1/10th the significance of the previous character.
423 r=(r*10)+x;
424 }
425
426 //Change the unsigned value into a signed result, and return it.
427 return r*mult;
428 }
429
430 /**
431 * @param array Text
432 * @param a Index of first digit
433 * @param b Index after last digit (e.g., array.length)
434 * @return Parsed number
435 */
436 public static int parseInt(String array, int a, int b){
437 // assert(false) : Character.toString(array.charAt(a));
438 assert(b>a);
439 int r=0;
440 final byte z='0';
441 int mult=1;
442 if(array.charAt(a)=='-'){mult=-1; a++;}
443 for(; a<b; a++){
444 int x=(array.charAt(a)-z);
445 assert(x<10 && x>=0) : x+" = "+array.charAt(a)+"\narray="+new String(array)+", start="+a+", stop="+b;
446 r=(r*10)+x;
447 }
448 return r*mult;
449 }
450
451 /**
452 * @param array Text
453 * @param a Index of first digit
454 * @return Parsed number
455 */
456 public static int parseInt(String array, int a){
457 int r=0;
458 final byte z='0';
459 int mult=1;
460 if(array.charAt(a)=='-'){mult=-1; a++;}
461 for(; a<array.length(); a++){
462 int x=(array.charAt(a)-z);
463 if(x<0 || x>9) {break;}//End of number
464 r=(r*10)+x;
465 }
466 return r*mult;
467 }
468
469 public static double parseDouble(String array, int a){
470 int b=a;
471 while(b<array.length()) {
472 char c=array.charAt(b);
473 if((c<'0' || c>'9') && c!='.' && c!='-') {break;}
474 b++;
475 }
476 return parseDouble(array, a, b);
477 }
478
479 public static float parseFloat(String array, int a){
480 return (float)parseDouble(array, a);
481 }
482
483 public static long parseLong(byte[] array){return parseLong(array, 0, array.length);}
484
485 public static long parseLong(byte[] array, int start){return parseLong(array, start, array.length);}
486
487 /**
488 * @param array Text
489 * @param a Index of first digit
490 * @param b Index after last digit (e.g., array.length)
491 * @return Parsed number
492 */
493 public static long parseLong(byte[] array, int a, int b){
494 assert(b>a);
495 long r=0;
496 final byte z='0';
497 long mult=1;
498 if(array[a]=='-'){mult=-1; a++;}
499 for(; a<b; a++){
500 int x=(array[a]-z);
501 assert(x<10 && x>=0) : x+" = "+(char)array[a]+"\narray="+new String(array)+", start="+a+", stop="+b;
502 r=(r*10)+x;
503 }
504 return r*mult;
505 }
506
507 /**
508 * @param array Text
509 * @param a Index of first digit
510 * @param b Index after last digit (e.g., array.length)
511 * @return Parsed number
512 */
513 public static long parseLong(String array, int a, int b){
514 assert(b>a);
515 long r=0;
516 final byte z='0';
517 long mult=1;
518 if(array.charAt(a)=='-'){mult=-1; a++;}
519 for(; a<b; a++){
520 int x=(array.charAt(a)-z);
521 assert(x<10 && x>=0) : x+" = "+array.charAt(a)+"\narray="+new String(array)+", start="+a+", stop="+b;
522 r=(r*10)+x;
523 }
524 return r*mult;
525 }
526
527
528 //Note: clen is optional, but allows poorly-formatted input like trailing whitespace
529 //Without clen ",,," would become {0,0,0,0}
530 public static long[] parseLongArray(String sub) {
531 if(sub==null || sub.length()<1){return null;}
532 long current=0;
533 // int clen=0;
534 LongList list=new LongList(min(8, 1+sub.length()/2));
535 for(int i=0, len=sub.length(); i<len; i++){
536 // System.err.println();
537 int c=sub.charAt(i)-'0';
538 if(c<0 || c>9){
539 // System.err.println('A');
540 //assert(clen>0);
541 list.add(current);
542 current=0;
543 // clen=0;
544 }else{
545 // System.err.println('B');
546 current=(current*10)+c;
547 // clen++;
548 }
549 // System.err.println("i="+i+", c="+c+", current="+current+", list="+list);
550 }
551 // if(clen>0){
552 list.add(current);
553 // }
554 // assert(false) : "\n'"+sub+"'\n"+Arrays.toString(list.toArray());
555 return list.toArray();
556 }
557
558 public static int parseZmw(String id){
559 //Example: m54283_190403_183820/4194374/919_2614
560 //Run ID is m54283_190403_183820
561 //zmw ID is 4194374.
562 //Read start/stop coordinates are 919_2614
563 int under=id.indexOf('_');
564 int slash=id.indexOf('/');
565 if(under<0 || slash<0){return -1;}
566 String[] split=id.split("/");
567 String z=split[1];
568 return Integer.parseInt(z);
569 }
570
571 public static String[] splitOnFirst(String s, char c) {
572 final int idx=s.indexOf(c);
573 if(idx<0) {return new String[] {s};}
574 final String a=s.substring(0, idx);
575 if(idx>=s.length()-1) {return new String[] {a};}
576 return new String[] {a, s.substring(idx+1)};
577 }
578
579 public static char parseSymbolToCharacter(String b){
580 b=parseSymbol(b);
581 while(b.length()>1 && b.charAt(0)=='\\'){
582 b=b.substring(1);
583 }
584 // System.err.println("Returning "+Character.toString(b.charAt(0)));
585 return b.length()>1 ? 0 : b.charAt(0);
586 }
587
588 public static String parseSymbol(String b){
589 if(b==null || b.length()<2){return b;}
590
591 //Convenience characters
592 if(b.equalsIgnoreCase("space")){
593 return " ";
594 }else if(b.equalsIgnoreCase("tab")){
595 return "\t";
596 }else if(b.equalsIgnoreCase("whitespace")){
597 return "\\s+";
598 }else if(b.equalsIgnoreCase("pound")){
599 return "#";
600 }else if(b.equalsIgnoreCase("greaterthan")){
601 return ">";
602 }else if(b.equalsIgnoreCase("lessthan")){
603 return "<";
604 }else if(b.equalsIgnoreCase("equals")){
605 return "=";
606 }else if(b.equalsIgnoreCase("colon")){
607 return ":";
608 }else if(b.equalsIgnoreCase("semicolon")){
609 return ";";
610 }else if(b.equalsIgnoreCase("comma")){
611 return ",";
612 }else if(b.equalsIgnoreCase("bang")){
613 return "!";
614 }else if(b.equalsIgnoreCase("and") || b.equalsIgnoreCase("ampersand")){
615 return "&";
616 }else if(b.equalsIgnoreCase("quote") || b.equalsIgnoreCase("doublequote")){
617 return "\"";
618 }else if(b.equalsIgnoreCase("singlequote") || b.equalsIgnoreCase("apostrophe")){
619 return "'";
620 }else if(b.equalsIgnoreCase("underscore")){
621 return "_";
622 }
623
624 //Java meta characters
625 if(b.equalsIgnoreCase("backslash")){
626 return "\\\\";
627 }else if(b.equalsIgnoreCase("hat") || b.equalsIgnoreCase("caret")){
628 return "\\^";
629 }else if(b.equalsIgnoreCase("dollar")){
630 return "\\$";
631 }else if(b.equalsIgnoreCase("dot")){
632 return "\\.";
633 }else if(b.equalsIgnoreCase("pipe") || b.equalsIgnoreCase("or")){
634 return "\\|";
635 }else if(b.equalsIgnoreCase("questionmark")){
636 return "\\?";
637 }else if(b.equalsIgnoreCase("star") || b.equalsIgnoreCase("asterisk")){
638 return "\\*";
639 }else if(b.equalsIgnoreCase("plus")){
640 return "\\+";
641 }else if(b.equalsIgnoreCase("openparen")){
642 return "\\(";
643 }else if(b.equalsIgnoreCase("closeparen")){
644 return "\\)";
645 }else if(b.equalsIgnoreCase("opensquare")){
646 return "\\[";
647 }else if(b.equalsIgnoreCase("closesquare")){
648 return "]";
649 }else if(b.equalsIgnoreCase("opencurly")){
650 return "\\{";
651 }else if(b.equalsIgnoreCase("closecurly")){
652 return "}";
653 }
654
655 //No matches, return the literal
656 return b;
657 }
658
659 public static byte[] parseRemap(String b){
660 final byte[] remap;
661 if(b==null || ("f".equalsIgnoreCase(b) || "false".equalsIgnoreCase(b))){
662 remap=null;
663 }else{
664 assert((b.length()&1)==0) : "Length of remap argument must be even. No whitespace is allowed.";
665
666 remap=new byte[128];
667 for(int j=0; j<remap.length; j++){remap[j]=(byte)j;}
668 for(int j=0; j<b.length(); j+=2){
669 char x=b.charAt(j), y=b.charAt(j+1);
670 remap[x]=(byte)y;
671 }
672 }
673 return remap;
674 }
675
676 public static final int min(int x, int y){return x<y ? x : y;}
677 public static final int max(int x, int y){return x>y ? x : y;}
678
679 }