1 2 4 package jodd.util; 5 6 import java.lang.reflect.Array ; 7 8 11 public class ArraysUtil { 12 13 14 15 17 20 public static Object [] join(Object [] first, Object [] second) { 21 return join(first, second, null); 22 } 23 24 27 public static Object [] join(Object [] first, Object [] second, Class elementType) { 28 if (elementType == null) { 29 elementType = first.getClass().getComponentType(); 30 } 31 Object [] temp = (Object []) Array.newInstance(elementType, first.length + second.length); 32 System.arraycopy(first, 0, temp, 0, first.length); 33 System.arraycopy(second, 0, temp, first.length, second.length); 34 return temp; 35 } 36 37 38 41 public static String [] join(String [] first, String [] second) { 42 String [] temp = new String [first.length + second.length]; 43 System.arraycopy(first, 0, temp, 0, first.length); 44 System.arraycopy(second, 0, temp, first.length, second.length); 45 return temp; 46 } 47 48 51 public static byte[] join(byte[] first, byte[] second) { 52 byte[] temp = new byte[first.length + second.length]; 53 System.arraycopy(first, 0, temp, 0, first.length); 54 System.arraycopy(second, 0, temp, first.length, second.length); 55 return temp; 56 } 57 58 61 public static char[] join(char[] first, char[] second) { 62 char[] temp = new char[first.length + second.length]; 63 System.arraycopy(first, 0, temp, 0, first.length); 64 System.arraycopy(second, 0, temp, first.length, second.length); 65 return temp; 66 } 67 68 71 public static short[] join(short[] first, short[] second) { 72 short[] temp = new short[first.length + second.length]; 73 System.arraycopy(first, 0, temp, 0, first.length); 74 System.arraycopy(second, 0, temp, first.length, second.length); 75 return temp; 76 } 77 78 81 public static int[] join(int[] first, int[] second) { 82 int[] temp = new int[first.length + second.length]; 83 System.arraycopy(first, 0, temp, 0, first.length); 84 System.arraycopy(second, 0, temp, first.length, second.length); 85 return temp; 86 } 87 88 91 public static long[] join(long[] first, long[] second) { 92 long[] temp = new long[first.length + second.length]; 93 System.arraycopy(first, 0, temp, 0, first.length); 94 System.arraycopy(second, 0, temp, first.length, second.length); 95 return temp; 96 } 97 98 101 public static float[] join(float[] first, float[] second) { 102 float[] temp = new float[first.length + second.length]; 103 System.arraycopy(first, 0, temp, 0, first.length); 104 System.arraycopy(second, 0, temp, first.length, second.length); 105 return temp; 106 } 107 108 111 public static double[] join(double[] first, double[] second) { 112 double[] temp = new double[first.length + second.length]; 113 System.arraycopy(first, 0, temp, 0, first.length); 114 System.arraycopy(second, 0, temp, first.length, second.length); 115 return temp; 116 } 117 118 121 public static boolean[] join(boolean[] first, boolean[] second) { 122 boolean[] temp = new boolean[first.length + second.length]; 123 System.arraycopy(first, 0, temp, 0, first.length); 124 System.arraycopy(second, 0, temp, first.length, second.length); 125 return temp; 126 } 127 128 129 131 134 public static Object [] resize(Object buffer[], int newSize) { 135 return resize(buffer, newSize, null); 136 } 137 138 141 public static Object [] resize(Object buffer[], int newSize, Class elementType) { 142 if (elementType == null) { 143 elementType = buffer.getClass().getComponentType(); 144 } 145 Object [] temp = (Object []) Array.newInstance(elementType, newSize); 146 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 147 return temp; 148 } 149 150 153 public static String [] resize(String buffer[], int newSize) { 154 String temp[] = new String [newSize]; 155 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 156 return temp; 157 } 158 159 162 public static byte[] resize(byte buffer[], int newSize) { 163 byte temp[] = new byte[newSize]; 164 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 165 return temp; 166 } 167 168 171 public static char[] resize(char buffer[], int newSize) { 172 char temp[] = new char[newSize]; 173 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 174 return temp; 175 } 176 177 180 public static short[] resize(short buffer[], int newSize) { 181 short temp[] = new short[newSize]; 182 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 183 return temp; 184 } 185 186 189 public static int[] resize(int buffer[], int newSize) { 190 int temp[] = new int[newSize]; 191 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 192 return temp; 193 } 194 195 198 public static long[] resize(long buffer[], int newSize) { 199 long temp[] = new long[newSize]; 200 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 201 return temp; 202 } 203 204 207 public static float[] resize(float buffer[], int newSize) { 208 float temp[] = new float[newSize]; 209 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 210 return temp; 211 } 212 213 216 public static double[] resize(double buffer[], int newSize) { 217 double temp[] = new double[newSize]; 218 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 219 return temp; 220 } 221 222 225 public static boolean[] resize(boolean buffer[], int newSize) { 226 boolean temp[] = new boolean[newSize]; 227 System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length); 228 return temp; 229 } 230 231 232 234 237 public static Object [] subarray(Object buffer[], int offset, int length) { 238 return subarray(buffer, offset, length, null); 239 } 240 241 244 public static Object [] subarray(Object buffer[], int offset, int length, Class elementType) { 245 if (elementType == null) { 246 elementType = buffer.getClass().getComponentType(); 247 } 248 Object [] temp = (Object []) Array.newInstance(elementType, length); 249 System.arraycopy(buffer, offset, temp, 0, length); 250 return temp; 251 } 252 253 256 public static String [] subarray(String buffer[], int offset, int length) { 257 String temp[] = new String [length]; 258 System.arraycopy(buffer, offset, temp, 0, length); 259 return temp; 260 } 261 262 265 public static byte[] subarray(byte buffer[], int offset, int length) { 266 byte temp[] = new byte[length]; 267 System.arraycopy(buffer, offset, temp, 0, length); 268 return temp; 269 } 270 271 274 public static char[] subarray(char buffer[], int offset, int length) { 275 char temp[] = new char[length]; 276 System.arraycopy(buffer, offset, temp, 0, length); 277 return temp; 278 } 279 280 283 public static short[] subarray(short buffer[], int offset, int length) { 284 short temp[] = new short[length]; 285 System.arraycopy(buffer, offset, temp, 0, length); 286 return temp; 287 } 288 289 292 public static int[] subarray(int buffer[], int offset, int length) { 293 int temp[] = new int[length]; 294 System.arraycopy(buffer, offset, temp, 0, length); 295 return temp; 296 } 297 298 301 public static long[] subarray(long buffer[], int offset, int length) { 302 long temp[] = new long[length]; 303 System.arraycopy(buffer, offset, temp, 0, length); 304 return temp; 305 } 306 307 310 public static float[] subarray(float buffer[], int offset, int length) { 311 float temp[] = new float[length]; 312 System.arraycopy(buffer, offset, temp, 0, length); 313 return temp; 314 } 315 316 319 public static double[] subarray(double buffer[], int offset, int length) { 320 double temp[] = new double[length]; 321 System.arraycopy(buffer, offset, temp, 0, length); 322 return temp; 323 } 324 325 328 public static boolean[] subarray(boolean buffer[], int offset, int length) { 329 boolean temp[] = new boolean[length]; 330 System.arraycopy(buffer, offset, temp, 0, length); 331 return temp; 332 } 333 334 335 337 340 public static Object [] insert(Object [] dest, Object [] src, int offset) { 341 return insert(dest, src, offset, null); 342 } 343 344 347 public static Object [] insert(Object [] dest, Object [] src, int offset, Class elementType) { 348 if (elementType == null) { 349 elementType = dest.getClass().getComponentType(); 350 } 351 Object [] temp = (Object []) Array.newInstance(elementType, dest.length + src.length); 352 System.arraycopy(dest, 0, temp, 0, offset); 353 System.arraycopy(src, 0, temp, offset, src.length); 354 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 355 return temp; 356 } 357 358 361 public static String [] insert(String [] dest, String [] src, int offset) { 362 String [] temp = new String [dest.length + src.length]; 363 System.arraycopy(dest, 0, temp, 0, offset); 364 System.arraycopy(src, 0, temp, offset, src.length); 365 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 366 return temp; 367 } 368 369 372 public static byte[] insert(byte[] dest, byte[] src, int offset) { 373 byte[] temp = new byte[dest.length + src.length]; 374 System.arraycopy(dest, 0, temp, 0, offset); 375 System.arraycopy(src, 0, temp, offset, src.length); 376 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 377 return temp; 378 } 379 380 383 public static char[] insert(char[] dest, char[] src, int offset) { 384 char[] temp = new char[dest.length + src.length]; 385 System.arraycopy(dest, 0, temp, 0, offset); 386 System.arraycopy(src, 0, temp, offset, src.length); 387 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 388 return temp; 389 } 390 391 394 public static short[] insert(short[] dest, short[] src, int offset) { 395 short[] temp = new short[dest.length + src.length]; 396 System.arraycopy(dest, 0, temp, 0, offset); 397 System.arraycopy(src, 0, temp, offset, src.length); 398 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 399 return temp; 400 } 401 402 405 public static int[] insert(int[] dest, int[] src, int offset) { 406 int[] temp = new int[dest.length + src.length]; 407 System.arraycopy(dest, 0, temp, 0, offset); 408 System.arraycopy(src, 0, temp, offset, src.length); 409 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 410 return temp; 411 } 412 413 416 public static long[] insert(long[] dest, long[] src, int offset) { 417 long[] temp = new long[dest.length + src.length]; 418 System.arraycopy(dest, 0, temp, 0, offset); 419 System.arraycopy(src, 0, temp, offset, src.length); 420 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 421 return temp; 422 } 423 424 427 public static float[] insert(float[] dest, float[] src, int offset) { 428 float[] temp = new float[dest.length + src.length]; 429 System.arraycopy(dest, 0, temp, 0, offset); 430 System.arraycopy(src, 0, temp, offset, src.length); 431 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 432 return temp; 433 } 434 435 438 public static double[] insert(double[] dest, double[] src, int offset) { 439 double[] temp = new double[dest.length + src.length]; 440 System.arraycopy(dest, 0, temp, 0, offset); 441 System.arraycopy(src, 0, temp, offset, src.length); 442 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 443 return temp; 444 } 445 446 449 public static boolean[] insert(boolean[] dest, boolean[] src, int offset) { 450 boolean[] temp = new boolean[dest.length + src.length]; 451 System.arraycopy(dest, 0, temp, 0, offset); 452 System.arraycopy(src, 0, temp, offset, src.length); 453 System.arraycopy(dest, offset, temp, src.length + offset, dest.length - offset); 454 return temp; 455 } 456 457 458 460 463 public static Object [] insertAt(Object [] dest, Object [] src, int offset) { 464 return insertAt(dest, src, offset, null); 465 } 466 467 470 public static Object [] insertAt(Object [] dest, Object [] src, int offset, Class elementType) { 471 if (elementType == null) { 472 elementType = dest.getClass().getComponentType(); 473 } 474 Object [] temp = (Object []) Array.newInstance(elementType, dest.length + src.length - 1); 475 System.arraycopy(dest, 0, temp, 0, offset); 476 System.arraycopy(src, 0, temp, offset, src.length); 477 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 478 return temp; 479 } 480 481 484 public static String [] insertAt(String [] dest, String [] src, int offset) { 485 String [] temp = new String [dest.length + src.length - 1]; 486 System.arraycopy(dest, 0, temp, 0, offset); 487 System.arraycopy(src, 0, temp, offset, src.length); 488 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 489 return temp; 490 } 491 492 495 public static byte[] insertAt(byte[] dest, byte[] src, int offset) { 496 byte[] temp = new byte[dest.length + src.length - 1]; 497 System.arraycopy(dest, 0, temp, 0, offset); 498 System.arraycopy(src, 0, temp, offset, src.length); 499 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 500 return temp; 501 } 502 503 506 public static char[] insertAt(char[] dest, char[] src, int offset) { 507 char[] temp = new char[dest.length + src.length - 1]; 508 System.arraycopy(dest, 0, temp, 0, offset); 509 System.arraycopy(src, 0, temp, offset, src.length); 510 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 511 return temp; 512 } 513 514 517 public static short[] insertAt(short[] dest, short[] src, int offset) { 518 short[] temp = new short[dest.length + src.length - 1]; 519 System.arraycopy(dest, 0, temp, 0, offset); 520 System.arraycopy(src, 0, temp, offset, src.length); 521 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 522 return temp; 523 } 524 525 528 public static int[] insertAt(int[] dest, int[] src, int offset) { 529 int[] temp = new int[dest.length + src.length - 1]; 530 System.arraycopy(dest, 0, temp, 0, offset); 531 System.arraycopy(src, 0, temp, offset, src.length); 532 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 533 return temp; 534 } 535 536 539 public static long[] insertAt(long[] dest, long[] src, int offset) { 540 long[] temp = new long[dest.length + src.length - 1]; 541 System.arraycopy(dest, 0, temp, 0, offset); 542 System.arraycopy(src, 0, temp, offset, src.length); 543 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 544 return temp; 545 } 546 547 550 public static float[] insertAt(float[] dest, float[] src, int offset) { 551 float[] temp = new float[dest.length + src.length - 1]; 552 System.arraycopy(dest, 0, temp, 0, offset); 553 System.arraycopy(src, 0, temp, offset, src.length); 554 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 555 return temp; 556 } 557 558 561 public static double[] insertAt(double[] dest, double[] src, int offset) { 562 double[] temp = new double[dest.length + src.length - 1]; 563 System.arraycopy(dest, 0, temp, 0, offset); 564 System.arraycopy(src, 0, temp, offset, src.length); 565 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 566 return temp; 567 } 568 569 572 public static boolean[] insertAt(boolean[] dest, boolean[] src, int offset) { 573 boolean[] temp = new boolean[dest.length + src.length - 1]; 574 System.arraycopy(dest, 0, temp, 0, offset); 575 System.arraycopy(src, 0, temp, offset, src.length); 576 System.arraycopy(dest, offset + 1, temp, src.length + offset, dest.length - offset - 1); 577 return temp; 578 } 579 580 581 583 584 587 static public int indexOf(byte[] array, byte value) { 588 for (int i = 0; i < array.length; i++) { 589 if (array[i] == value) { 590 return i; 591 } 592 } 593 return -1; 594 } 595 598 public static int indexOf(byte[] array, byte value, int startIndex) { 599 for (int i = startIndex; i < array.length; i++) { 600 if (array[i] == value) { 601 return i; 602 } 603 } 604 return -1; 605 } 606 609 public static int indexOf(byte[] array, byte value, int startIndex, int endIndex) { 610 for (int i = startIndex; i < endIndex; i++) { 611 if (array[i] == value) { 612 return i; 613 } 614 } 615 return -1; 616 } 617 618 621 static public int indexOf(char[] array, char value) { 622 for (int i = 0; i < array.length; i++) { 623 if (array[i] == value) { 624 return i; 625 } 626 } 627 return -1; 628 } 629 632 public static int indexOf(char[] array, char value, int startIndex) { 633 for (int i = startIndex; i < array.length; i++) { 634 if (array[i] == value) { 635 return i; 636 } 637 } 638 return -1; 639 } 640 643 public static int indexOf(char[] array, char value, int startIndex, int endIndex) { 644 for (int i = startIndex; i < endIndex; i++) { 645 if (array[i] == value) { 646 return i; 647 } 648 } 649 return -1; 650 } 651 652 655 static public int indexOf(short[] array, short value) { 656 for (int i = 0; i < array.length; i++) { 657 if (array[i] == value) { 658 return i; 659 } 660 } 661 return -1; 662 } 663 666 public static int indexOf(short[] array, short value, int startIndex) { 667 for (int i = startIndex; i < array.length; i++) { 668 if (array[i] == value) { 669 return i; 670 } 671 } 672 return -1; 673 } 674 677 public static int indexOf(short[] array, short value, int startIndex, int endIndex) { 678 for (int i = startIndex; i < endIndex; i++) { 679 if (array[i] == value) { 680 return i; 681 } 682 } 683 return -1; 684 } 685 686 689 static public int indexOf(int[] array, int value) { 690 for (int i = 0; i < array.length; i++) { 691 if (array[i] == value) { 692 return i; 693 } 694 } 695 return -1; 696 } 697 700 public static int indexOf(int[] array, int value, int startIndex) { 701 for (int i = startIndex; i < array.length; i++) { 702 if (array[i] == value) { 703 return i; 704 } 705 } 706 return -1; 707 } 708 711 public static int indexOf(int[] array, int value, int startIndex, int endIndex) { 712 for (int i = startIndex; i < endIndex; i++) { 713 if (array[i] == value) { 714 return i; 715 } 716 } 717 return -1; 718 } 719 720 723 static public int indexOf(long[] array, long value) { 724 for (int i = 0; i < array.length; i++) { 725 if (array[i] == value) { 726 return i; 727 } 728 } 729 return -1; 730 } 731 734 public static int indexOf(long[] array, long value, int startIndex) { 735 for (int i = startIndex; i < array.length; i++) { 736 if (array[i] == value) { 737 return i; 738 } 739 } 740 return -1; 741 } 742 745 public static int indexOf(long[] array, long value, int startIndex, int endIndex) { 746 for (int i = startIndex; i < endIndex; i++) { 747 if (array[i] == value) { 748 return i; 749 } 750 } 751 return -1; 752 } 753 754 757 static public int indexOf(float[] array, float value) { 758 for (int i = 0; i < array.length; i++) { 759 if (array[i] == value) { 760 return i; 761 } 762 } 763 return -1; 764 } 765 768 public static int indexOf(float[] array, float value, int startIndex) { 769 for (int i = startIndex; i < array.length; i++) { 770 if (array[i] == value) { 771 return i; 772 } 773 } 774 return -1; 775 } 776 779 public static int indexOf(float[] array, float value, int startIndex, int endIndex) { 780 for (int i = startIndex; i < endIndex; i++) { 781 if (array[i] == value) { 782 return i; 783 } 784 } 785 return -1; 786 } 787 788 791 static public int indexOf(double[] array, double value) { 792 for (int i = 0; i < array.length; i++) { 793 if (array[i] == value) { 794 return i; 795 } 796 } 797 return -1; 798 } 799 802 public static int indexOf(double[] array, double value, int startIndex) { 803 for (int i = startIndex; i < array.length; i++) { 804 if (array[i] == value) { 805 return i; 806 } 807 } 808 return -1; 809 } 810 813 public static int indexOf(double[] array, double value, int startIndex, int endIndex) { 814 for (int i = startIndex; i < endIndex; i++) { 815 if (array[i] == value) { 816 return i; 817 } 818 } 819 return -1; 820 } 821 822 825 static public int indexOf(boolean[] array, boolean value) { 826 for (int i = 0; i < array.length; i++) { 827 if (array[i] == value) { 828 return i; 829 } 830 } 831 return -1; 832 } 833 836 public static int indexOf(boolean[] array, boolean value, int startIndex) { 837 for (int i = startIndex; i < array.length; i++) { 838 if (array[i] == value) { 839 return i; 840 } 841 } 842 return -1; 843 } 844 847 public static int indexOf(boolean[] array, boolean value, int startIndex, int endIndex) { 848 for (int i = startIndex; i < endIndex; i++) { 849 if (array[i] == value) { 850 return i; 851 } 852 } 853 return -1; 854 } 855 856 857 859 860 863 public static int indexOf(byte[] array, byte[] sub) { 864 return indexOf(array, sub, 0, array.length); 865 } 866 867 870 public static int indexOf(byte[] array, byte[] sub, int startIndex) { 871 return indexOf(array, sub, startIndex, array.length); 872 } 873 874 877 public static int indexOf(byte[] array, byte[] sub, int startIndex, int endIndex) { 878 int sublen = sub.length; 879 if (sublen == 0) { 880 return startIndex; 881 } 882 int total = endIndex - sublen + 1; 883 byte c = sub[0]; 884 mainloop: 885 for (int i = startIndex; i < total; i++) { 886 if (array[i] != c) { 887 continue; 888 } 889 int j = 1; 890 int k = i + 1; 891 while (j < sublen) { 892 if (sub[j] != array[k]) { 893 continue mainloop; 894 } 895 j++; k++; 896 } 897 return i; 898 } 899 return -1; 900 } 901 902 905 public static int indexOf(char[] array, char[] sub) { 906 return indexOf(array, sub, 0, array.length); 907 } 908 909 912 public static int indexOf(char[] array, char[] sub, int startIndex) { 913 return indexOf(array, sub, startIndex, array.length); 914 } 915 916 919 public static int indexOf(char[] array, char[] sub, int startIndex, int endIndex) { 920 int sublen = sub.length; 921 if (sublen == 0) { 922 return startIndex; 923 } 924 int total = endIndex - sublen + 1; 925 char c = sub[0]; 926 mainloop: 927 for (int i = startIndex; i < total; i++) { 928 if (array[i] != c) { 929 continue; 930 } 931 int j = 1; 932 int k = i + 1; 933 while (j < sublen) { 934 if (sub[j] != array[k]) { 935 continue mainloop; 936 } 937 j++; k++; 938 } 939 return i; 940 } 941 return -1; 942 } 943 944 947 public static int indexOf(short[] array, short[] sub) { 948 return indexOf(array, sub, 0, array.length); 949 } 950 951 954 public static int indexOf(short[] array, short[] sub, int startIndex) { 955 return indexOf(array, sub, startIndex, array.length); 956 } 957 958 961 public static int indexOf(short[] array, short[] sub, int startIndex, int endIndex) { 962 int sublen = sub.length; 963 if (sublen == 0) { 964 return startIndex; 965 } 966 int total = endIndex - sublen + 1; 967 short c = sub[0]; 968 mainloop: 969 for (int i = startIndex; i < total; i++) { 970 if (array[i] != c) { 971 continue; 972 } 973 int j = 1; 974 int k = i + 1; 975 while (j < sublen) { 976 if (sub[j] != array[k]) { 977 continue mainloop; 978 } 979 j++; k++; 980 } 981 return i; 982 } 983 return -1; 984 } 985 986 989 public static int indexOf(int[] array, int[] sub) { 990 return indexOf(array, sub, 0, array.length); 991 } 992 993 996 public static int indexOf(int[] array, int[] sub, int startIndex) { 997 return indexOf(array, sub, startIndex, array.length); 998 } 999 1000 1003 public static int indexOf(int[] array, int[] sub, int startIndex, int endIndex) { 1004 int sublen = sub.length; 1005 if (sublen == 0) { 1006 return startIndex; 1007 } 1008 int total = endIndex - sublen + 1; 1009 int c = sub[0]; 1010 mainloop: 1011 for (int i = startIndex; i < total; i++) { 1012 if (array[i] != c) { 1013 continue; 1014 } 1015 int j = 1; 1016 int k = i + 1; 1017 while (j < sublen) { 1018 if (sub[j] != array[k]) { 1019 continue mainloop; 1020 } 1021 j++; k++; 1022 } 1023 return i; 1024 } 1025 return -1; 1026 } 1027 1028 1031 public static int indexOf(long[] array, long[] sub) { 1032 return indexOf(array, sub, 0, array.length); 1033 } 1034 1035 1038 public static int indexOf(long[] array, long[] sub, int startIndex) { 1039 return indexOf(array, sub, startIndex, array.length); 1040 } 1041 1042 1045 public static int indexOf(long[] array, long[] sub, int startIndex, int endIndex) { 1046 int sublen = sub.length; 1047 if (sublen == 0) { 1048 return startIndex; 1049 } 1050 int total = endIndex - sublen + 1; 1051 long c = sub[0]; 1052 mainloop: 1053 for (int i = startIndex; i < total; i++) { 1054 if (array[i] != c) { 1055 continue; 1056 } 1057 int j = 1; 1058 int k = i + 1; 1059 while (j < sublen) { 1060 if (sub[j] != array[k]) { 1061 continue mainloop; 1062 } 1063 j++; k++; 1064 } 1065 return i; 1066 } 1067 return -1; 1068 } 1069 1070 1073 public static int indexOf(float[] array, float[] sub) { 1074 return indexOf(array, sub, 0, array.length); 1075 } 1076 1077 1080 public static int indexOf(float[] array, float[] sub, int startIndex) { 1081 return indexOf(array, sub, startIndex, array.length); 1082 } 1083 1084 1087 public static int indexOf(float[] array, float[] sub, int startIndex, int endIndex) { 1088 int sublen = sub.length; 1089 if (sublen == 0) { 1090 return startIndex; 1091 } 1092 int total = endIndex - sublen + 1; 1093 float c = sub[0]; 1094 mainloop: 1095 for (int i = startIndex; i < total; i++) { 1096 if (array[i] != c) { 1097 continue; 1098 } 1099 int j = 1; 1100 int k = i + 1; 1101 while (j < sublen) { 1102 if (sub[j] != array[k]) { 1103 continue mainloop; 1104 } 1105 j++; k++; 1106 } 1107 return i; 1108 } 1109 return -1; 1110 } 1111 1112 1115 public static int indexOf(double[] array, double[] sub) { 1116 return indexOf(array, sub, 0, array.length); 1117 } 1118 1119 1122 public static int indexOf(double[] array, double[] sub, int startIndex) { 1123 return indexOf(array, sub, startIndex, array.length); 1124 } 1125 1126 1129 public static int indexOf(double[] array, double[] sub, int startIndex, int endIndex) { 1130 int sublen = sub.length; 1131 if (sublen == 0) { 1132 return startIndex; 1133 } 1134 int total = endIndex - sublen + 1; 1135 double c = sub[0]; 1136 mainloop: 1137 for (int i = startIndex; i < total; i++) { 1138 if (array[i] != c) { 1139 continue; 1140 } 1141 int j = 1; 1142 int k = i + 1; 1143 while (j < sublen) { 1144 if (sub[j] != array[k]) { 1145 continue mainloop; 1146 } 1147 j++; k++; 1148 } 1149 return i; 1150 } 1151 return -1; 1152 } 1153 1154 1157 public static int indexOf(boolean[] array, boolean[] sub) { 1158 return indexOf(array, sub, 0, array.length); 1159 } 1160 1161 1164 public static int indexOf(boolean[] array, boolean[] sub, int startIndex) { 1165 return indexOf(array, sub, startIndex, array.length); 1166 } 1167 1168 1171 public static int indexOf(boolean[] array, boolean[] sub, int startIndex, int endIndex) { 1172 int sublen = sub.length; 1173 if (sublen == 0) { 1174 return startIndex; 1175 } 1176 int total = endIndex - sublen + 1; 1177 boolean c = sub[0]; 1178 mainloop: 1179 for (int i = startIndex; i < total; i++) { 1180 if (array[i] != c) { 1181 continue; 1182 } 1183 int j = 1; 1184 int k = i + 1; 1185 while (j < sublen) { 1186 if (sub[j] != array[k]) { 1187 continue mainloop; 1188 } 1189 j++; k++; 1190 } 1191 return i; 1192 } 1193 return -1; 1194 } 1195} | Popular Tags |