1 15 package org.josql.internal; 16 17 import java.util.List ; 18 import java.util.ArrayList ; 19 import java.util.Map ; 20 import java.util.HashMap ; 21 import java.util.StringTokenizer ; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.Modifier ; 27 import java.lang.reflect.Constructor ; 28 29 public class Utilities 30 { 31 32 private static final String F = "f"; 33 private static final String E = "e"; 34 private static final String A = "a"; 35 private static final String N = "n"; 36 37 public static final int GT = 0; 38 public static final int GTE = 1; 39 public static final int LT = 2; 40 public static final int LTE = 3; 41 public static final int EQ = 4; 42 43 private static Map pCNames = new HashMap (); 44 private static Map primNames = new HashMap (); 45 private static Map primCls = new HashMap (); 46 47 static 48 { 49 50 Utilities.pCNames.put ("double", 51 ""); 52 Utilities.pCNames.put (Double .class.getName (), 53 ""); 54 Utilities.pCNames.put ("int", 55 ""); 56 Utilities.pCNames.put (Integer .class.getName (), 57 ""); 58 Utilities.pCNames.put ("float", 59 ""); 60 Utilities.pCNames.put (Float .class.getName (), 61 ""); 62 Utilities.pCNames.put ("long", 63 ""); 64 Utilities.pCNames.put (Long .class.getName (), 65 ""); 66 Utilities.pCNames.put ("short", 67 ""); 68 Utilities.pCNames.put (Short .class.getName (), 69 ""); 70 Utilities.pCNames.put ("byte", 71 ""); 72 Utilities.pCNames.put (Byte .class.getName (), 73 ""); 74 Utilities.pCNames.put (Number .class.getName (), 75 ""); 76 77 Utilities.primNames.put (Double.TYPE.getName (), 78 Double .class.getName ()); 79 Utilities.primNames.put (Double .class.getName (), 80 Double.TYPE.getName ()); 81 Utilities.primNames.put (Integer.TYPE.getName (), 82 Integer .class.getName ()); 83 Utilities.primNames.put (Integer .class.getName (), 84 Integer.TYPE.getName ()); 85 Utilities.primNames.put (Float.TYPE.getName (), 86 Float .class.getName ()); 87 Utilities.primNames.put (Float .class.getName (), 88 Float.TYPE.getName ()); 89 Utilities.primNames.put (Long.TYPE.getName (), 90 Long .class.getName ()); 91 Utilities.primNames.put (Long .class.getName (), 92 Long.TYPE.getName ()); 93 Utilities.primNames.put (Short.TYPE.getName (), 94 Short .class.getName ()); 95 Utilities.primNames.put (Short .class.getName (), 96 Short.TYPE.getName ()); 97 Utilities.primNames.put (Byte.TYPE.getName (), 98 Byte .class.getName ()); 99 Utilities.primNames.put (Byte .class.getName (), 100 Byte.TYPE.getName ()); 101 Utilities.primNames.put (Character.TYPE.getName (), 102 Character .class.getName ()); 103 Utilities.primNames.put (Character .class.getName (), 104 Character.TYPE.getName ()); 105 Utilities.primNames.put (Boolean.TYPE.getName (), 106 Boolean .class.getName ()); 107 Utilities.primNames.put (Boolean .class.getName (), 108 Boolean.TYPE.getName ()); 109 110 Utilities.primCls.put (Double.TYPE.getName (), 111 Double.TYPE); 112 Utilities.primCls.put (Double .class.getName (), 113 Double.TYPE); 114 115 Utilities.primCls.put (Integer.TYPE.getName (), 116 Integer.TYPE); 117 Utilities.primCls.put (Integer .class.getName (), 118 Integer.TYPE); 119 120 Utilities.primCls.put (Float.TYPE.getName (), 121 Float.TYPE); 122 Utilities.primCls.put (Float .class.getName (), 123 Float.TYPE); 124 125 Utilities.primCls.put (Long.TYPE.getName (), 126 Long.TYPE); 127 Utilities.primCls.put (Long .class.getName (), 128 Long.TYPE); 129 130 Utilities.primCls.put (Short.TYPE.getName (), 131 Short.TYPE); 132 Utilities.primCls.put (Short .class.getName (), 133 Short.TYPE); 134 135 Utilities.primCls.put (Byte.TYPE.getName (), 136 Byte.TYPE); 137 Utilities.primCls.put (Byte .class.getName (), 138 Byte.TYPE); 139 140 Utilities.primCls.put (Character.TYPE.getName (), 141 Character.TYPE); 142 Utilities.primCls.put (Character .class.getName (), 143 Character.TYPE); 144 145 Utilities.primCls.put (Boolean.TYPE.getName (), 146 Boolean.TYPE); 147 Utilities.primCls.put (Boolean .class.getName (), 148 Boolean.TYPE); 149 150 } 151 152 public static Class getObjectClass (Class c) 153 { 154 155 if (c.isPrimitive ()) 156 { 157 158 String n = c.getName (); 159 160 if (n.equals (Boolean.TYPE.getName ())) 161 { 162 163 return Boolean .class; 164 165 } 166 167 if (n.equals (Long.TYPE.getName ())) 168 { 169 170 return Long .class; 171 172 } 173 174 if (n.equals (Short.TYPE.getName ())) 175 { 176 177 return Short .class; 178 179 } 180 181 if (n.equals (Integer.TYPE.getName ())) 182 { 183 184 return Integer .class; 185 186 } 187 188 if (n.equals (Double.TYPE.getName ())) 189 { 190 191 return Double .class; 192 193 } 194 195 if (n.equals (Character.TYPE.getName ())) 196 { 197 198 return Character .class; 199 200 } 201 202 if (n.equals (Float.TYPE.getName ())) 203 { 204 205 return Float .class; 206 207 } 208 209 if (n.equals (Byte.TYPE.getName ())) 210 { 211 212 return Byte .class; 213 214 } 215 216 } 217 218 return c; 219 220 } 221 222 public static Class getPrimitiveClass (Class c) 223 { 224 225 return (Class ) Utilities.primCls.get (c.getName ()); 226 227 } 228 229 public static boolean isPrimitiveClass (Class c) 230 { 231 232 return Utilities.primNames.containsKey (c.getName ()); 233 234 } 235 236 public static boolean getResult (boolean v, 237 boolean n) 238 { 239 240 if (v) 241 { 242 243 if (n) 244 { 245 246 return false; 247 248 } 249 250 return true; 251 252 } 253 254 if (n) 255 { 256 257 return true; 258 259 } 260 261 return false; 262 263 } 264 265 308 public static boolean matches (Object l, 309 Object r, 310 boolean ignoreCase, 311 int type, 312 boolean not) 313 { 314 315 if (l instanceof Collection ) 316 { 317 318 if (r instanceof Collection ) 319 { 320 321 Collection cl = (Collection ) l; 322 Collection cr = (Collection ) r; 323 324 boolean lisra = (cl instanceof List ); 325 boolean risra = (cr instanceof List ); 326 327 List rl = null; 328 329 if (risra) 330 { 331 332 rl = (List ) cr; 333 334 } 335 336 int rs = cr.size () - 1; 337 338 if (lisra) 341 { 342 343 List ll = (List ) cl; 344 345 int s = ll.size () - 1; 347 348 for (int i = s; i > -1; i--) 349 { 350 351 l = Utilities.lowerValue (ll.get (i), 352 ignoreCase); 353 354 if (risra) 355 { 356 357 for (int j = rs; j > -1; j--) 358 { 359 360 r = Utilities.lowerValue (rl.get (j), 361 ignoreCase); 362 363 if (!Utilities.compare2 (l, 364 r, 365 type, 366 not)) 367 { 368 369 return false; 370 371 } 372 373 } 374 375 } else { 376 377 Iterator it = cr.iterator (); 378 379 while (it.hasNext ()) 380 { 381 382 r = Utilities.lowerValue (it.next (), 383 ignoreCase); 384 385 if (!Utilities.compare2 (l, 386 r, 387 type, 388 not)) 389 { 390 391 return false; 392 393 } 394 395 } 396 397 } 398 399 } 400 401 } else { 402 403 Iterator it = cl.iterator (); 404 405 while (it.hasNext ()) 406 { 407 408 l = Utilities.lowerValue (it.next (), 409 ignoreCase); 410 411 if (risra) 412 { 413 414 for (int j = rs; j > -1; j--) 415 { 416 417 r = Utilities.lowerValue (rl.get (j), 418 ignoreCase); 419 420 if (!Utilities.compare2 (l, 421 r, 422 type, 423 not)) 424 { 425 426 return false; 427 428 } 429 430 } 431 432 } else { 433 434 Iterator itr = cr.iterator (); 435 436 while (itr.hasNext ()) 437 { 438 439 r = Utilities.lowerValue (itr.next (), 440 ignoreCase); 441 442 if (!Utilities.compare2 (l, 443 r, 444 type, 445 not)) 446 { 447 448 return false; 449 450 } 451 452 } 453 454 } 455 456 } 457 458 } 459 460 return true; 464 465 } else { 466 467 Collection cl = (Collection ) l; 470 471 r = Utilities.lowerValue (r, 472 ignoreCase); 473 474 if (cl instanceof List ) 475 { 476 477 List ll = (List ) cl; 478 479 int ls = cl.size () - 1; 480 481 for (int i = ls; i > -1; i--) 482 { 483 484 l = Utilities.lowerValue (ll.get (i), 485 ignoreCase); 486 487 if (!Utilities.compare2 (l, 488 r, 489 type, 490 not)) 491 { 492 493 return false; 494 495 } 496 497 } 498 499 } else { 500 501 Iterator cli = cl.iterator (); 502 503 while (cli.hasNext ()) 504 { 505 506 l = Utilities.lowerValue (cli.next (), 507 ignoreCase); 508 509 if (!Utilities.compare2 (l, 510 r, 511 type, 512 not)) 513 { 514 515 return false; 516 517 } 518 519 } 520 521 } 522 523 return true; 526 527 } 528 529 } else { 530 531 if (r instanceof Collection ) 533 { 534 535 l = Utilities.lowerValue (l, 536 ignoreCase); 537 538 Collection cr = (Collection ) r; 539 540 if (cr instanceof List ) 541 { 542 543 List rl = (List ) cr; 544 545 int rs = rl.size () - 1; 546 547 for (int i = rs; i > -1; i--) 548 { 549 550 r = Utilities.lowerValue (rl.get (i), 551 ignoreCase); 552 553 if (!Utilities.compare2 (l, 554 r, 555 type, 556 not)) 557 { 558 559 return false; 560 561 } 562 563 } 564 565 } else { 566 567 Iterator cri = cr.iterator (); 568 569 while (cri.hasNext ()) 570 { 571 572 r = Utilities.lowerValue (cri.next (), 573 ignoreCase); 574 575 if (!Utilities.compare2 (l, 576 r, 577 type, 578 not)) 579 { 580 581 return false; 582 583 } 584 585 } 586 587 } 588 589 return true; 592 593 } 594 595 } 596 597 return Utilities.compare2 (Utilities.lowerValue (l, 602 ignoreCase), 603 Utilities.lowerValue (r, 604 ignoreCase), 605 type, 606 not); 607 608 } 609 610 private static Object lowerValue (Object o, 611 boolean ignoreCase) 612 { 613 614 if (ignoreCase) 615 { 616 617 o = o.toString (); 618 619 if (o != null) 620 { 621 622 o = ((String ) o).toLowerCase (); 623 624 } 625 626 } 627 628 return o; 629 630 } 631 632 private static boolean compare2 (Object l, 633 Object r, 634 int type, 635 boolean not) 636 { 637 638 int c = Utilities.compare (l, 639 r); 640 641 643 if ((type == 0) 645 && 646 (c < 1) 647 ) 648 { 649 650 if (not) 654 { 655 656 return true; 657 658 } 659 660 return false; 661 662 } 663 664 if (((type == 1) 666 || 667 (type == 4) 668 ) 669 && 670 (c < 0) 671 ) 672 { 673 674 if (not) 677 { 678 679 return true; 680 681 } 682 683 return false; 684 685 } 686 687 if ((type == 2) 689 && 690 (c > -1) 691 ) 692 { 693 694 if (not) 698 { 699 700 return true; 701 702 } 703 704 return false; 705 706 } 707 708 if (((type == 3) 710 || 711 (type == 4) 712 ) 713 && 714 (c > 0) 715 ) 716 { 717 718 if (not) 721 { 722 723 return true; 724 725 } 726 727 return false; 728 729 } 730 731 if (not) 732 { 733 734 return false; 735 736 } 737 738 return true; 739 740 } 741 742 public static int compare (Object o1, 743 Object o2) 744 { 745 746 if ((o1 == null) 747 && 748 (o2 == null) 749 ) 750 { 751 752 return 0; 753 754 } 755 756 if ((o1 == null) 757 || 758 (o2 == null) 759 ) 760 { 761 762 return -1; 763 764 } 765 766 if ((o1 instanceof Number ) 767 && 768 (o2 instanceof Number ) 769 ) 770 { 771 772 return Utilities.getDoubleObject (o1).compareTo (Utilities.getDoubleObject (o2)); 773 774 } 775 776 if ((o1 instanceof Comparable ) 777 && 778 (o2 instanceof Comparable ) 779 && 780 (o1.getClass ().isAssignableFrom (o2.getClass ())) 781 ) 782 { 783 784 return ((Comparable ) o1).compareTo ((Comparable ) o2); 785 786 } 787 788 String s1 = o1.toString (); 790 String s2 = o2.toString (); 791 792 return s1.compareTo (s2); 793 794 } 795 796 public static boolean isGTEquals (Object o1, 797 Object o2) 798 { 799 800 return Utilities.matches (o1, 801 o2, 802 false, 803 Utilities.GTE, 804 false); 805 806 } 807 808 public static boolean isLTEquals (Object o1, 809 Object o2) 810 { 811 812 return Utilities.matches (o1, 813 o2, 814 false, 815 Utilities.LTE, 816 false); 817 818 } 819 820 public static boolean isEquals (Object o1, 821 Object o2) 822 { 823 824 return Utilities.compare (o1, 825 o2) == 0; 826 827 } 828 829 public static Double getDoubleObject (Object o) 830 { 831 832 return new Double (Utilities.getDouble (o)); 833 834 } 835 836 public static double getDouble (Object o) 837 { 838 839 return ((Number ) o).doubleValue (); 840 841 } 842 843 public static boolean isNumber (Object o) 844 { 845 846 if (o == null) 847 { 848 849 return false; 850 851 } 852 853 return Utilities.pCNames.containsKey (o.getClass ().getName ()); 854 855 } 856 857 public static boolean isNumber (Class c) 858 { 859 860 return Utilities.pCNames.containsKey (c.getName ()); 861 862 } 863 864 public static String formatSignature (String name, 865 Class [] ps) 866 { 867 868 StringBuffer buf = new StringBuffer (name); 869 buf.append ("("); 870 871 if (ps != null) 872 { 873 874 for (int i = 0; i < ps.length; i++) 875 { 876 877 buf.append (ps[i].getName ()); 878 879 if (i < (ps.length - 1)) 880 { 881 882 buf.append (","); 883 884 } 885 886 } 887 888 } 889 890 buf.append (")"); 891 892 return buf.toString (); 893 894 } 895 896 public static boolean matchLikePattern (List p, 897 Object lhs, 898 boolean not, 899 boolean ignoreCase) 900 { 901 902 if (lhs instanceof Collection ) 903 { 904 905 return Utilities.matchLikePattern (p, 906 (Collection ) lhs, 907 not, 908 ignoreCase); 909 910 } 911 912 boolean v = Utilities.matchLikePattern (p, 913 lhs, 914 ignoreCase); 915 916 if ((!v) 917 && 918 (not) 919 ) 920 { 921 922 return true; 923 924 } 925 926 if ((v) 927 && 928 (not) 929 ) 930 { 931 932 return false; 933 934 } 935 936 return v; 937 938 } 939 940 public static boolean matchLikePattern (List p, 941 Collection lhs, 942 boolean not, 943 boolean ignoreCase) 944 { 945 946 if (lhs instanceof List ) 947 { 948 949 int s = lhs.size () - 1; 950 951 List l = (List ) lhs; 952 953 for (int i = s; i > -1; i--) 954 { 955 956 Object o = l.get (i); 957 958 if (!Utilities.matchLikePattern (p, 959 o, 960 ignoreCase)) 961 { 962 963 if (not) 964 { 965 966 return true; 967 968 } 969 970 return false; 971 972 } 973 974 } 975 976 if (not) 977 { 978 979 return false; 980 981 } 982 983 return true; 984 985 } 986 987 Iterator iter = lhs.iterator (); 988 989 while (iter.hasNext ()) 990 { 991 992 Object o = iter.next (); 993 994 if (!Utilities.matchLikePattern (p, 995 o, 996 ignoreCase)) 997 { 998 999 if (not) 1000 { 1001 1002 return true; 1003 1004 } 1005 1006 return false; 1007 1008 } 1009 1010 } 1011 1012 if (not) 1013 { 1014 1015 return false; 1016 1017 } 1018 1019 return true; 1020 1021 } 1022 1023 public static boolean matchLikePattern (List p, 1024 Object o, 1025 boolean ignoreCase) 1026 { 1027 1028 if (o == null) 1029 { 1030 1031 return false; 1032 1033 } 1034 1035 String st = o.toString (); 1036 1037 if (ignoreCase) 1038 { 1039 1040 st = st.toLowerCase (); 1041 1042 } 1043 1044 return Utilities.matchLikePattern (p, 1045 st); 1046 1047 } 1048 1049 public static boolean matchLikePattern (List p, 1050 String value) 1051 { 1052 1053 if (value == null) 1054 { 1055 1056 return false; 1057 1058 } 1059 1060 boolean accept = true; 1061 1062 String c = null; 1063 String pm = null; 1064 1065 int currPos = 0; 1066 int cmdPos = 0; 1067 1068 int s = p.size (); 1069 1070 while (cmdPos < s) 1071 { 1072 1073 c = (String ) p.get (cmdPos); 1074 pm = (String ) p.get (cmdPos + 1); 1075 1076 if (c.equals (Utilities.F)) 1077 { 1078 1079 if (pm.equals (Utilities.A)) 1082 { 1083 1084 break; 1085 1086 } 1087 1088 int nextPos = value.indexOf (pm, 1091 currPos); 1092 1093 if (nextPos >= 0) 1094 { 1095 1096 currPos = nextPos + pm.length (); 1098 1099 } else { 1100 1101 accept = false; 1102 break; 1103 1104 } 1105 1106 } else { 1107 1108 if (c.equals (Utilities.E)) 1109 { 1110 1111 if (pm.equals (Utilities.N)) 1114 { 1115 1116 if (currPos != value.length ()) 1117 { 1118 1119 accept = false; 1120 1121 } 1122 1123 break; 1126 1127 } else { 1128 1129 int nextPos = value.indexOf (pm, 1132 currPos); 1133 1134 if (nextPos != currPos) 1135 { 1136 1137 accept = false; 1138 break; 1139 1140 } 1141 1142 currPos += pm.length (); 1145 1146 } 1147 1148 } 1149 1150 } 1151 1152 cmdPos += 2; 1153 } 1154 1155 return accept; 1156 1157 } 1158 1159 public static boolean matchLikePattern (List p, 1160 String value, 1161 boolean not) 1162 { 1163 1164 boolean accept = Utilities.matchLikePattern (p, 1165 value); 1166 1167 if (not) 1168 { 1169 1170 return !accept; 1171 1172 } 1173 1174 return accept; 1175 1176 } 1177 1178 public static List getLikePattern (String value, 1179 String wildcard) 1180 { 1181 1182 List p = new ArrayList (); 1183 1184 StringTokenizer t = new StringTokenizer (value, 1185 wildcard, 1186 true); 1187 1188 String tok = null; 1189 1190 while (t.hasMoreTokens ()) 1191 { 1192 1193 tok = t.nextToken (); 1194 1195 if (tok.equals (wildcard)) 1196 { 1197 1198 p.add (Utilities.F); 1199 1200 if (t.hasMoreTokens ()) 1201 { 1202 1203 tok = t.nextToken (); 1204 p.add (tok); 1205 1206 } else { 1207 1208 p.add (Utilities.A); 1209 1210 } 1211 1212 } else { 1213 1214 p.add (Utilities.E); 1215 p.add (tok); 1216 1217 } 1218 1219 } 1220 1221 if (!tok.equals (wildcard)) 1222 { 1223 1224 p.add (Utilities.E); 1225 p.add (Utilities.N); 1226 1227 } 1228 1229 return p; 1230 1231 } 1232 1233 public static String stripQuotes (String s) 1234 { 1235 1236 if (s == null) 1237 { 1238 1239 return s; 1240 1241 } 1242 1243 if (((s.charAt (0) == '\'') 1244 && 1245 (s.charAt (s.length () - 1) == '\'') 1246 ) 1247 || 1248 ((s.charAt (0) == '"') 1249 && 1250 (s.charAt (s.length () - 1) == '"') 1251 ) 1252 ) 1253 { 1254 1255 return s.substring (1, 1256 s.length () - 1); 1257 1258 } 1259 1260 return s; 1261 1262 } 1263 1264 public static void getMethods (Class c, 1265 String name, 1266 int mods, 1267 List ms) 1268 { 1269 1270 if (c == null) 1271 { 1272 1273 return; 1274 1275 } 1276 1277 Method [] meths = c.getDeclaredMethods (); 1278 1279 for (int i = 0; i < meths.length; i++) 1280 { 1281 1282 Method m = meths[i]; 1283 1284 if ((m.getName ().equals (name)) 1285 && 1286 ((m.getModifiers () & mods) == mods) 1287 ) 1288 { 1289 1290 if (!ms.contains (m)) 1291 { 1292 1293 ms.add (m); 1295 1296 } 1297 1298 } 1299 1300 } 1301 1302 Class sup = c.getSuperclass (); 1304 1305 if (sup != null) 1306 { 1307 1308 Utilities.getMethods (sup, 1309 name, 1310 mods, 1311 ms); 1312 1313 } 1314 1315 Class [] ints = c.getInterfaces (); 1317 1318 for (int i = 0; i < ints.length; i++) 1319 { 1320 1321 Class in = ints[i]; 1322 1323 Utilities.getMethods (in, 1324 name, 1325 mods, 1326 ms); 1327 1328 } 1329 1330 } 1331 1332 public static int matchMethodArgs (Class [] args, 1333 Class [] compArgs) 1334 { 1335 1336 if ((compArgs == null) 1337 && 1338 (args == null) 1339 ) 1340 { 1341 1342 return 2; 1343 1344 } 1345 1346 if ((compArgs == null) 1347 && 1348 (args.length == 0) 1349 ) 1350 { 1351 1352 return 2; 1353 1354 } 1355 1356 if ((compArgs == null) 1357 && 1358 (args.length > 0) 1359 ) 1360 { 1361 1362 return 0; 1363 1364 } 1365 1366 if (args.length != compArgs.length) 1367 { 1368 1369 return 0; 1370 1371 } 1372 1373 int score = 0; 1377 1378 for (int i = 0; i < args.length; i++) 1379 { 1380 1381 Class c = args[i]; 1382 1383 if (c.getClass ().getName ().equals (Object .class.getName ())) 1385 { 1386 1387 score += 1; 1388 1389 continue; 1390 1391 } 1392 1393 Class cc = compArgs[i]; 1394 1395 if (cc == null) 1396 { 1397 1398 continue; 1400 1401 } else { 1402 1403 if (c.isAssignableFrom (cc)) 1404 { 1405 1406 score += 2; 1407 1408 continue; 1409 1410 } 1411 1412 } 1413 1414 if ((Utilities.isNumber (cc)) 1415 && 1416 (Utilities.isNumber (c)) 1417 ) 1418 { 1419 1420 score += 1; 1421 1422 continue; 1424 1425 } 1426 1427 if ((Utilities.isPrimitiveClass (c)) 1428 && 1429 (Utilities.isPrimitiveClass (cc)) 1430 ) 1431 { 1432 1433 if (Utilities.getPrimitiveClass (c).isAssignableFrom (Utilities.getPrimitiveClass (cc))) 1435 { 1436 1437 score += 1; 1438 1439 continue; 1441 1442 } 1443 1444 } 1445 1446 if (cc.getName ().equals (Object .class.getName ())) 1449 { 1450 1451 score += 1; 1452 1453 continue; 1454 1455 } 1456 1457 return 0; 1460 1461 } 1462 1463 return score; 1465 1466 } 1467 1468 public static Object [] convertArgs (Object [] args, 1469 Class [] argTypes) 1470 { 1471 1472 if (args == null) 1473 { 1474 1475 return args; 1476 1477 } 1478 1479 Object [] nargs = new Object [args.length]; 1480 1481 for (int i = 0; i < argTypes.length; i++) 1482 { 1483 1484 if (Utilities.isNumber (argTypes[i])) 1485 { 1486 1487 Class c = Utilities.getObjectClass (argTypes[i]); 1488 1489 Number arg = (Number ) args[i]; 1491 1492 if (Double .class.isAssignableFrom (c)) 1493 { 1494 1495 nargs[i] = arg; 1496 1497 continue; 1498 1499 } 1500 1501 if (Short .class.isAssignableFrom (c)) 1502 { 1503 1504 nargs[i] = new Short (arg.shortValue ()); 1505 1506 continue; 1507 1508 } 1509 1510 if (Integer .class.isAssignableFrom (c)) 1511 { 1512 1513 nargs[i] = new Integer (arg.intValue ()); 1514 1515 continue; 1516 1517 } 1518 1519 if (Long .class.isAssignableFrom (c)) 1520 { 1521 1522 nargs[i] = new Long (arg.longValue ()); 1523 1524 continue; 1525 1526 } 1527 1528 if (Float .class.isAssignableFrom (c)) 1529 { 1530 1531 nargs[i] = new Float (arg.floatValue ()); 1532 1533 continue; 1534 1535 } 1536 1537 if (Byte .class.isAssignableFrom (c)) 1538 { 1539 1540 nargs[i] = new Byte (arg.byteValue ()); 1541 1542 continue; 1543 1544 } 1545 1546 } else { 1547 1548 nargs[i] = args[i]; 1549 1550 } 1551 1552 } 1553 1554 return nargs; 1555 1556 } 1557 1558} 1559
| Popular Tags
|