001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.type.collection.array; 020 021import icy.type.DataType; 022 023/** 024 * @author Stephane 025 */ 026public class Array2DUtil 027{ 028 /** 029 * Return the total number of element of the specified array 030 */ 031 public static int getTotalLength(byte[][] array) 032 { 033 int result = 0; 034 035 if (array != null) 036 { 037 final int len = array.length; 038 039 for (int i = 0; i < len; i++) 040 result += Array1DUtil.getTotalLength(array[i]); 041 } 042 043 return result; 044 } 045 046 /** 047 * Return the total number of element of the specified array 048 */ 049 public static int getTotalLength(short[][] array) 050 { 051 int result = 0; 052 053 if (array != null) 054 { 055 final int len = array.length; 056 057 for (int i = 0; i < len; i++) 058 result += Array1DUtil.getTotalLength(array[i]); 059 } 060 061 return result; 062 } 063 064 /** 065 * Return the total number of element of the specified array 066 */ 067 public static int getTotalLength(int[][] array) 068 { 069 int result = 0; 070 071 if (array != null) 072 { 073 final int len = array.length; 074 075 for (int i = 0; i < len; i++) 076 result += Array1DUtil.getTotalLength(array[i]); 077 } 078 079 return result; 080 } 081 082 /** 083 * Return the total number of element of the specified array 084 */ 085 public static int getTotalLength(long[][] array) 086 { 087 int result = 0; 088 089 if (array != null) 090 { 091 final int len = array.length; 092 093 for (int i = 0; i < len; i++) 094 result += Array1DUtil.getTotalLength(array[i]); 095 } 096 097 return result; 098 } 099 100 /** 101 * Return the total number of element of the specified array 102 */ 103 public static int getTotalLength(float[][] array) 104 { 105 int result = 0; 106 107 if (array != null) 108 { 109 final int len = array.length; 110 111 for (int i = 0; i < len; i++) 112 result += Array1DUtil.getTotalLength(array[i]); 113 114 } 115 116 return result; 117 } 118 119 /** 120 * Return the total number of element of the specified array 121 */ 122 public static int getTotalLength(double[][] array) 123 { 124 int result = 0; 125 126 if (array != null) 127 { 128 final int len = array.length; 129 130 for (int i = 0; i < len; i++) 131 result += Array1DUtil.getTotalLength(array[i]); 132 } 133 134 return result; 135 } 136 137 /** 138 * @deprecated 139 * use {@link #getTotalLength(byte[][])} instead 140 */ 141 @Deprecated 142 public static int getTotalLenght(byte[][] array) 143 { 144 return getTotalLength(array); 145 } 146 147 /** 148 * @deprecated 149 * use {@link #getTotalLength(short[][])} instead 150 */ 151 @Deprecated 152 public static int getTotalLenght(short[][] array) 153 { 154 return getTotalLength(array); 155 } 156 157 /** 158 * @deprecated 159 * use {@link #getTotalLength(int[][])} instead 160 */ 161 @Deprecated 162 public static int getTotalLenght(int[][] array) 163 { 164 return getTotalLength(array); 165 } 166 167 /** 168 * @deprecated 169 * use {@link #getTotalLength(float[][])} instead 170 */ 171 @Deprecated 172 public static int getTotalLenght(float[][] array) 173 { 174 return getTotalLength(array); 175 } 176 177 /** 178 * @deprecated 179 * use {@link #getTotalLength(double[][])} instead 180 */ 181 @Deprecated 182 public static int getTotalLenght(double[][] array) 183 { 184 return getTotalLength(array); 185 } 186 187 /** 188 * Create a new 2D array with specified data type and length 189 */ 190 public static Object[] createArray(DataType dataType, int len) 191 { 192 switch (dataType.getJavaType()) 193 { 194 case BYTE: 195 return new byte[len][]; 196 case SHORT: 197 return new short[len][]; 198 case INT: 199 return new int[len][]; 200 case LONG: 201 return new long[len][]; 202 case FLOAT: 203 return new float[len][]; 204 case DOUBLE: 205 return new double[len][]; 206 default: 207 return null; 208 } 209 } 210 211 /** 212 * @deprecated 213 */ 214 @Deprecated 215 public static Object[] createArray(int dataType, int len) 216 { 217 return createArray(DataType.getDataType(dataType), len); 218 } 219 220 /** 221 * Allocate the specified 2D array if it's defined to null with the specified len 222 */ 223 public static byte[][] allocIfNull(byte[][] out, int len) 224 { 225 if (out == null) 226 return new byte[len][]; 227 228 return out; 229 } 230 231 /** 232 * Allocate the specified 2D array if it's defined to null with the specified len 233 */ 234 public static short[][] allocIfNull(short[][] out, int len) 235 { 236 if (out == null) 237 return new short[len][]; 238 239 return out; 240 } 241 242 /** 243 * Allocate the specified 2D array if it's defined to null with the specified len 244 */ 245 public static int[][] allocIfNull(int[][] out, int len) 246 { 247 if (out == null) 248 return new int[len][]; 249 250 return out; 251 } 252 253 /** 254 * Allocate the specified 2D array if it's defined to null with the specified len 255 */ 256 public static long[][] allocIfNull(long[][] out, int len) 257 { 258 if (out == null) 259 return new long[len][]; 260 261 return out; 262 } 263 264 /** 265 * Allocate the specified 2D array if it's defined to null with the specified len 266 */ 267 public static float[][] allocIfNull(float[][] out, int len) 268 { 269 if (out == null) 270 return new float[len][]; 271 272 return out; 273 } 274 275 /** 276 * Allocate the specified 2D array if it's defined to null with the specified len 277 */ 278 public static double[][] allocIfNull(double[][] out, int len) 279 { 280 if (out == null) 281 return new double[len][]; 282 283 return out; 284 } 285 286 /** 287 * Return true is the specified arrays are equals 288 */ 289 public static boolean arrayByteCompare(byte[][] array1, byte[][] array2) 290 { 291 final int len = array1.length; 292 293 if (len != array2.length) 294 return false; 295 296 for (int i = 0; i < len; i++) 297 if (!Array1DUtil.arrayByteCompare(array1[i], array2[i])) 298 return false; 299 300 return true; 301 } 302 303 /** 304 * Return true is the specified arrays are equals 305 */ 306 public static boolean arrayShortCompare(short[][] array1, short[][] array2) 307 { 308 final int len = array1.length; 309 310 if (len != array2.length) 311 return false; 312 313 for (int i = 0; i < len; i++) 314 if (!Array1DUtil.arrayShortCompare(array1[i], array2[i])) 315 return false; 316 317 return true; 318 } 319 320 /** 321 * Return true is the specified arrays are equals 322 */ 323 public static boolean arrayIntCompare(int[][] array1, int[][] array2) 324 { 325 final int len = array1.length; 326 327 if (len != array2.length) 328 return false; 329 330 for (int i = 0; i < len; i++) 331 if (!Array1DUtil.arrayIntCompare(array1[i], array2[i])) 332 return false; 333 334 return true; 335 } 336 337 /** 338 * Return true is the specified arrays are equals 339 */ 340 public static boolean arrayLongCompare(long[][] array1, long[][] array2) 341 { 342 final int len = array1.length; 343 344 if (len != array2.length) 345 return false; 346 347 for (int i = 0; i < len; i++) 348 if (!Array1DUtil.arrayLongCompare(array1[i], array2[i])) 349 return false; 350 351 return true; 352 } 353 354 /** 355 * Return true is the specified arrays are equals 356 */ 357 public static boolean arrayFloatCompare(float[][] array1, float[][] array2) 358 { 359 final int len = array1.length; 360 361 if (len != array2.length) 362 return false; 363 364 for (int i = 0; i < len; i++) 365 if (!Array1DUtil.arrayFloatCompare(array1[i], array2[i])) 366 return false; 367 368 return true; 369 } 370 371 /** 372 * Return true is the specified arrays are equals 373 */ 374 public static boolean arrayDoubleCompare(double[][] array1, double[][] array2) 375 { 376 final int len = array1.length; 377 378 if (len != array2.length) 379 return false; 380 381 for (int i = 0; i < len; i++) 382 if (!Array1DUtil.arrayDoubleCompare(array1[i], array2[i])) 383 return false; 384 385 return true; 386 } 387 388 /** 389 * Return the multi dimension 'in' array as a single dimension byte array. 390 */ 391 public static byte[] toByteArray1D(byte[][] in) 392 { 393 return toByteArray1D(in, null, 0); 394 } 395 396 /** 397 * Return the multi dimension 'in' array as a single dimension short array. 398 */ 399 public static short[] toShortArray1D(short[][] in) 400 { 401 return toShortArray1D(in, null, 0); 402 } 403 404 /** 405 * @deprecated Use {@link #toIntArray1D(int[][])} instead 406 */ 407 @Deprecated 408 public static int[] toIntArray(int[][] in) 409 { 410 return toIntArray1D(in, null, 0); 411 } 412 413 /** 414 * Return the multi dimension 'in' array as a single dimension int array. 415 */ 416 public static int[] toIntArray1D(int[][] in) 417 { 418 return toIntArray1D(in, null, 0); 419 } 420 421 /** 422 * Return the multi dimension 'in' array as a single dimension float array. 423 */ 424 public static float[] toFloatArray1D(float[][] in) 425 { 426 return toFloatArray1D(in, null, 0); 427 } 428 429 /** 430 * Return the multi dimension 'in' array as a single dimension double array. 431 */ 432 public static double[] toDoubleArray1D(double[][] in) 433 { 434 return toDoubleArray1D(in, null, 0); 435 } 436 437 /** 438 * Return the 2 dimensions 'in' array as a single dimension array.<br> 439 * The resulting array is returned in 'out' and from the specified if any.<br> 440 * If (out == null) a new array is allocated. 441 */ 442 public static byte[] toByteArray1D(byte[][] in, byte[] out, int offset) 443 { 444 final byte[] result = Array1DUtil.allocIfNull(out, offset + getTotalLength(in)); 445 446 if (in != null) 447 { 448 final int len = in.length; 449 450 int off = offset; 451 for (int i = 0; i < len; i++) 452 { 453 final byte[] s_in = in[i]; 454 455 if (s_in != null) 456 { 457 Array1DUtil.toByteArray1D(s_in, result, off); 458 off += s_in.length; 459 } 460 } 461 } 462 463 return result; 464 } 465 466 /** 467 * Return the 2 dimensions 'in' array as a single dimension array.<br> 468 * The resulting array is returned in 'out' and from the specified if any.<br> 469 * If (out == null) a new array is allocated. 470 */ 471 public static short[] toShortArray1D(short[][] in, short[] out, int offset) 472 { 473 final short[] result = Array1DUtil.allocIfNull(out, offset + getTotalLength(in)); 474 475 if (in != null) 476 { 477 final int len = in.length; 478 479 int off = offset; 480 for (int i = 0; i < len; i++) 481 { 482 final short[] s_in = in[i]; 483 484 if (s_in != null) 485 { 486 Array1DUtil.toShortArray1D(s_in, result, off); 487 off += s_in.length; 488 } 489 } 490 } 491 492 return result; 493 } 494 495 /** 496 * Return the 2 dimensions 'in' array as a single dimension array.<br> 497 * The resulting array is returned in 'out' and from the specified if any.<br> 498 * If (out == null) a new array is allocated. 499 */ 500 public static int[] toIntArray1D(int[][] in, int[] out, int offset) 501 { 502 final int[] result = Array1DUtil.allocIfNull(out, offset + getTotalLength(in)); 503 504 if (in != null) 505 { 506 final int len = in.length; 507 508 int off = offset; 509 for (int i = 0; i < len; i++) 510 { 511 final int[] s_in = in[i]; 512 513 if (s_in != null) 514 { 515 Array1DUtil.toIntArray1D(s_in, result, off); 516 off += s_in.length; 517 } 518 } 519 } 520 521 return result; 522 } 523 524 /** 525 * Return the 2 dimensions 'in' array as a single dimension array.<br> 526 * The resulting array is returned in 'out' and from the specified if any.<br> 527 * If (out == null) a new array is allocated. 528 */ 529 public static long[] toLongArray1D(long[][] in, long[] out, int offset) 530 { 531 final long[] result = Array1DUtil.allocIfNull(out, offset + getTotalLength(in)); 532 533 if (in != null) 534 { 535 final int len = in.length; 536 537 int off = offset; 538 for (int i = 0; i < len; i++) 539 { 540 final long[] s_in = in[i]; 541 542 if (s_in != null) 543 { 544 Array1DUtil.toLongArray1D(s_in, result, off); 545 off += s_in.length; 546 } 547 } 548 } 549 550 return result; 551 } 552 553 /** 554 * Return the 2 dimensions 'in' array as a single dimension array.<br> 555 * The resulting array is returned in 'out' and from the specified if any.<br> 556 * If (out == null) a new array is allocated. 557 */ 558 public static float[] toFloatArray1D(float[][] in, float[] out, int offset) 559 { 560 final float[] result = Array1DUtil.allocIfNull(out, offset + getTotalLength(in)); 561 562 if (in != null) 563 { 564 final int len = in.length; 565 566 int off = offset; 567 for (int i = 0; i < len; i++) 568 { 569 final float[] s_in = in[i]; 570 571 if (s_in != null) 572 { 573 Array1DUtil.toFloatArray1D(s_in, result, off); 574 off += s_in.length; 575 } 576 } 577 } 578 579 return result; 580 } 581 582 /** 583 * Return the 2 dimensions 'in' array as a single dimension array.<br> 584 * The resulting array is returned in 'out' and from the specified if any.<br> 585 * If (out == null) a new array is allocated. 586 */ 587 public static double[] toDoubleArray1D(double[][] in, double[] out, int offset) 588 { 589 final double[] result = Array1DUtil.allocIfNull(out, offset + getTotalLength(in)); 590 591 if (in != null) 592 { 593 final int len = in.length; 594 595 int off = offset; 596 for (int i = 0; i < len; i++) 597 { 598 final double[] s_in = in[i]; 599 600 if (s_in != null) 601 { 602 Array1DUtil.toDoubleArray1D(s_in, result, off); 603 off += s_in.length; 604 } 605 } 606 } 607 608 return result; 609 } 610 611 /** 612 * Convert and return the 'in' 2D array in 'out' 2D array type. 613 * 614 * @param in 615 * input array 616 * @param inOffset 617 * position where we start read data from 618 * @param out 619 * output array which is used to receive result (and so define wanted type) 620 * @param outOffset 621 * position where we start to write data to 622 * @param length 623 * number of value to convert (-1 means we will use the maximum possible length) 624 * @param signed 625 * if input data are integer type then we assume them as signed data 626 */ 627 public static Object arrayToArray(Object in, int inOffset, Object out, int outOffset, int length, boolean signed) 628 { 629 switch (ArrayUtil.getDataType(in)) 630 { 631 case BYTE: 632 return byteArrayToArray((byte[][]) in, inOffset, out, outOffset, length, signed); 633 case SHORT: 634 return shortArrayToArray((short[][]) in, inOffset, out, outOffset, length, signed); 635 case INT: 636 return intArrayToArray((int[][]) in, inOffset, out, outOffset, length, signed); 637 case LONG: 638 return longArrayToArray((long[][]) in, inOffset, out, outOffset, length, signed); 639 case FLOAT: 640 return floatArrayToArray((float[][]) in, inOffset, out, outOffset, length); 641 case DOUBLE: 642 return doubleArrayToArray((double[][]) in, inOffset, out, outOffset, length); 643 default: 644 return out; 645 } 646 } 647 648 /** 649 * Convert and return the 'in' 2D array in 'out' 2D array type. 650 * 651 * @param in 652 * input array 653 * @param out 654 * output array which is used to receive result (and so define wanted type) 655 * @param signed 656 * if input data are integer type then we assume them as signed data 657 */ 658 public static Object arrayToArray(Object in, Object out, boolean signed) 659 { 660 return arrayToArray(in, 0, out, 0, -1, signed); 661 } 662 663 /** 664 * Convert and return the 'in' double array in 'out' array type.<br> 665 * 666 * @param in 667 * input array 668 * @param inOffset 669 * position where we start read data from 670 * @param out 671 * output array which is used to receive result (and so define wanted type) 672 * @param outOffset 673 * position where we start to write data to 674 * @param length 675 * number of value to convert (-1 means we will use the maximum possible length) 676 */ 677 public static Object doubleArrayToArray(double[][] in, int inOffset, Object out, int outOffset, int length) 678 { 679 switch (ArrayUtil.getDataType(out)) 680 { 681 case BYTE: 682 return doubleArrayToByteArray(in, inOffset, (byte[][]) out, outOffset, length); 683 case SHORT: 684 return doubleArrayToShortArray(in, inOffset, (short[][]) out, outOffset, length); 685 case INT: 686 return doubleArrayToIntArray(in, inOffset, (int[][]) out, outOffset, length); 687 case LONG: 688 return doubleArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length); 689 case FLOAT: 690 return doubleArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length); 691 case DOUBLE: 692 return doubleArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length); 693 default: 694 return out; 695 } 696 } 697 698 /** 699 * Convert and return the 'in' double array in 'out' array type.<br> 700 * 701 * @param in 702 * input array 703 * @param out 704 * output array which is used to receive result (and so define wanted type) 705 */ 706 public static Object doubleArrayToArray(double[][] in, Object out) 707 { 708 return doubleArrayToArray(in, 0, out, 0, -1); 709 } 710 711 /** 712 * Convert and return the 'in' float array in 'out' array type.<br> 713 * 714 * @param in 715 * input array 716 * @param inOffset 717 * position where we start read data from 718 * @param out 719 * output array which is used to receive result (and so define wanted type) 720 * @param outOffset 721 * position where we start to write data to 722 * @param length 723 * number of value to convert (-1 means we will use the maximum possible length) 724 */ 725 public static Object floatArrayToArray(float[][] in, int inOffset, Object out, int outOffset, int length) 726 { 727 switch (ArrayUtil.getDataType(out)) 728 { 729 case BYTE: 730 return floatArrayToByteArray(in, inOffset, (byte[][]) out, outOffset, length); 731 case SHORT: 732 return floatArrayToShortArray(in, inOffset, (short[][]) out, outOffset, length); 733 case INT: 734 return floatArrayToIntArray(in, inOffset, (int[][]) out, outOffset, length); 735 case LONG: 736 return floatArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length); 737 case FLOAT: 738 return floatArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length); 739 case DOUBLE: 740 return floatArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length); 741 default: 742 return out; 743 } 744 } 745 746 /** 747 * Convert and return the 'in' float array in 'out' array type.<br> 748 * 749 * @param in 750 * input array 751 * @param out 752 * output array which is used to receive result (and so define wanted type) 753 */ 754 public static Object floatArrayToArray(float[][] in, Object out) 755 { 756 return floatArrayToArray(in, 0, out, 0, -1); 757 } 758 759 /** 760 * Convert and return the 'in' long array in 'out' array type.<br> 761 * 762 * @param in 763 * input array 764 * @param inOffset 765 * position where we start read data from 766 * @param out 767 * output array which is used to receive result (and so define wanted type) 768 * @param outOffset 769 * position where we start to write data to 770 * @param length 771 * number of value to convert (-1 means we will use the maximum possible length) 772 * @param signed 773 * assume input data as signed data 774 */ 775 public static Object longArrayToArray(long[][] in, int inOffset, Object out, int outOffset, int length, 776 boolean signed) 777 { 778 switch (ArrayUtil.getDataType(out)) 779 { 780 case BYTE: 781 return longArrayToByteArray(in, inOffset, (byte[][]) out, outOffset, length); 782 case SHORT: 783 return longArrayToShortArray(in, inOffset, (short[][]) out, outOffset, length); 784 case INT: 785 return longArrayToIntArray(in, inOffset, (int[][]) out, outOffset, length); 786 case LONG: 787 return longArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length); 788 case FLOAT: 789 return longArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length, signed); 790 case DOUBLE: 791 return longArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length, signed); 792 default: 793 return out; 794 } 795 } 796 797 /** 798 * Convert and return the 'in' long array in 'out' array type.<br> 799 * 800 * @param in 801 * input array 802 * @param out 803 * output array which is used to receive result (and so define wanted type) 804 * @param signed 805 * assume input data as signed data 806 */ 807 public static Object longArrayToArray(long[][] in, Object out, boolean signed) 808 { 809 return longArrayToArray(in, 0, out, 0, -1, signed); 810 } 811 812 /** 813 * Convert and return the 'in' integer array in 'out' array type.<br> 814 * 815 * @param in 816 * input array 817 * @param inOffset 818 * position where we start read data from 819 * @param out 820 * output array which is used to receive result (and so define wanted type) 821 * @param outOffset 822 * position where we start to write data to 823 * @param length 824 * number of value to convert (-1 means we will use the maximum possible length) 825 * @param signed 826 * assume input data as signed data 827 */ 828 public static Object intArrayToArray(int[][] in, int inOffset, Object out, int outOffset, int length, 829 boolean signed) 830 { 831 switch (ArrayUtil.getDataType(out)) 832 { 833 case BYTE: 834 return intArrayToByteArray(in, inOffset, (byte[][]) out, outOffset, length); 835 case SHORT: 836 return intArrayToShortArray(in, inOffset, (short[][]) out, outOffset, length); 837 case INT: 838 return intArrayToIntArray(in, inOffset, (int[][]) out, outOffset, length); 839 case LONG: 840 return intArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length, signed); 841 case FLOAT: 842 return intArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length, signed); 843 case DOUBLE: 844 return intArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length, signed); 845 default: 846 return out; 847 } 848 } 849 850 /** 851 * Convert and return the 'in' integer array in 'out' array type.<br> 852 * 853 * @param in 854 * input array 855 * @param out 856 * output array which is used to receive result (and so define wanted type) 857 * @param signed 858 * assume input data as signed data 859 */ 860 public static Object intArrayToArray(int[][] in, Object out, boolean signed) 861 { 862 return intArrayToArray(in, 0, out, 0, -1, signed); 863 } 864 865 /** 866 * Convert and return the 'in' short array in 'out' array type.<br> 867 * 868 * @param in 869 * input array 870 * @param inOffset 871 * position where we start read data from 872 * @param out 873 * output array which is used to receive result (and so define wanted type) 874 * @param outOffset 875 * position where we start to write data to 876 * @param length 877 * number of value to convert (-1 means we will use the maximum possible length) 878 * @param signed 879 * assume input data as signed data 880 */ 881 public static Object shortArrayToArray(short[][] in, int inOffset, Object out, int outOffset, int length, 882 boolean signed) 883 { 884 switch (ArrayUtil.getDataType(out)) 885 { 886 case BYTE: 887 return shortArrayToByteArray(in, inOffset, (byte[][]) out, outOffset, length); 888 case SHORT: 889 return shortArrayToShortArray(in, inOffset, (short[][]) out, outOffset, length); 890 case INT: 891 return shortArrayToIntArray(in, inOffset, (int[][]) out, outOffset, length, signed); 892 case LONG: 893 return shortArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length, signed); 894 case FLOAT: 895 return shortArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length, signed); 896 case DOUBLE: 897 return shortArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length, signed); 898 default: 899 return out; 900 } 901 } 902 903 /** 904 * Convert and return the 'in' short array in 'out' array type.<br> 905 * 906 * @param in 907 * input array 908 * @param out 909 * output array which is used to receive result (and so define wanted type) 910 * @param signed 911 * assume input data as signed data 912 */ 913 public static Object shortArrayToArray(short[][] in, Object out, boolean signed) 914 { 915 return shortArrayToArray(in, 0, out, 0, -1, signed); 916 } 917 918 /** 919 * Convert and return the 'in' byte array in 'out' array type.<br> 920 * 921 * @param in 922 * input array 923 * @param inOffset 924 * position where we start read data from 925 * @param out 926 * output array which is used to receive result (and so define wanted type) 927 * @param outOffset 928 * position where we start to write data to 929 * @param length 930 * number of value to convert (-1 means we will use the maximum possible length) 931 * @param signed 932 * assume input data as signed data 933 */ 934 public static Object byteArrayToArray(byte[][] in, int inOffset, Object out, int outOffset, int length, 935 boolean signed) 936 { 937 switch (ArrayUtil.getDataType(out)) 938 { 939 case BYTE: 940 return byteArrayToByteArray(in, inOffset, (byte[][]) out, outOffset, length); 941 case SHORT: 942 return byteArrayToShortArray(in, inOffset, (short[][]) out, outOffset, length, signed); 943 case INT: 944 return byteArrayToIntArray(in, inOffset, (int[][]) out, outOffset, length, signed); 945 case LONG: 946 return byteArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length, signed); 947 case FLOAT: 948 return byteArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length, signed); 949 case DOUBLE: 950 return byteArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length, signed); 951 default: 952 return out; 953 } 954 } 955 956 /** 957 * Convert and return the 'in' byte array in 'out' array type.<br> 958 * 959 * @param in 960 * input array 961 * @param out 962 * output array which is used to receive result (and so define wanted type) 963 * @param signed 964 * assume input data as signed data 965 */ 966 public static Object byteArrayToArray(byte[][] in, Object out, boolean signed) 967 { 968 return byteArrayToArray(in, 0, out, 0, -1, signed); 969 } 970 971 /** 972 * Convert and return the 'in' array in 'out' double array.<br> 973 * 974 * @param in 975 * input array 976 * @param inOffset 977 * position where we start read data from 978 * @param out 979 * output array which is used to receive result (and so define wanted type) 980 * @param outOffset 981 * position where we start to write data to 982 * @param length 983 * number of value to convert (-1 means we will use the maximum possible length) 984 * @param signed 985 * assume input data as signed data 986 */ 987 public static double[][] arrayToDoubleArray(Object in, int inOffset, double[][] out, int outOffset, int length, 988 boolean signed) 989 { 990 switch (ArrayUtil.getDataType(in)) 991 { 992 case BYTE: 993 return byteArrayToDoubleArray((byte[][]) in, inOffset, out, outOffset, length, signed); 994 case SHORT: 995 return shortArrayToDoubleArray((short[][]) in, inOffset, out, outOffset, length, signed); 996 case INT: 997 return intArrayToDoubleArray((int[][]) in, inOffset, out, outOffset, length, signed); 998 case LONG: 999 return longArrayToDoubleArray((long[][]) in, inOffset, out, outOffset, length, signed); 1000 case FLOAT: 1001 return floatArrayToDoubleArray((float[][]) in, inOffset, out, outOffset, length); 1002 case DOUBLE: 1003 return doubleArrayToDoubleArray((double[][]) in, inOffset, out, outOffset, length); 1004 default: 1005 return out; 1006 } 1007 } 1008 1009 /** 1010 * Convert and return the 'in' array in 'out' double array.<br> 1011 * 1012 * @param in 1013 * input array 1014 * @param out 1015 * output array which is used to receive result (and so define wanted type) 1016 * @param signed 1017 * assume input data as signed data 1018 */ 1019 public static double[][] arrayToDoubleArray(Object in, double[][] out, boolean signed) 1020 { 1021 return arrayToDoubleArray(in, 0, out, 0, -1, signed); 1022 } 1023 1024 /** 1025 * Convert and return the 'in' array as a double array.<br> 1026 * 1027 * @param in 1028 * input array 1029 * @param signed 1030 * assume input data as signed data 1031 */ 1032 public static double[][] arrayToDoubleArray(Object in, boolean signed) 1033 { 1034 return arrayToDoubleArray(in, 0, null, 0, -1, signed); 1035 } 1036 1037 /** 1038 * Convert and return the 'in' array in 'out' float array.<br> 1039 * 1040 * @param in 1041 * input array 1042 * @param inOffset 1043 * position where we start read data from 1044 * @param out 1045 * output array which is used to receive result (and so define wanted type) 1046 * @param outOffset 1047 * position where we start to write data to 1048 * @param length 1049 * number of value to convert (-1 means we will use the maximum possible length) 1050 * @param signed 1051 * assume input data as signed data 1052 */ 1053 public static float[][] arrayToFloatArray(Object in, int inOffset, float[][] out, int outOffset, int length, 1054 boolean signed) 1055 { 1056 switch (ArrayUtil.getDataType(in)) 1057 { 1058 case BYTE: 1059 return byteArrayToFloatArray((byte[][]) in, inOffset, out, outOffset, length, signed); 1060 case SHORT: 1061 return shortArrayToFloatArray((short[][]) in, inOffset, out, outOffset, length, signed); 1062 case INT: 1063 return intArrayToFloatArray((int[][]) in, inOffset, out, outOffset, length, signed); 1064 case LONG: 1065 return longArrayToFloatArray((long[][]) in, inOffset, out, outOffset, length, signed); 1066 case FLOAT: 1067 return floatArrayToFloatArray((float[][]) in, inOffset, out, outOffset, length); 1068 case DOUBLE: 1069 return doubleArrayToFloatArray((double[][]) in, inOffset, out, outOffset, length); 1070 default: 1071 return out; 1072 } 1073 } 1074 1075 /** 1076 * Convert and return the 'in' array in 'out' float array.<br> 1077 * 1078 * @param in 1079 * input array 1080 * @param out 1081 * output array which is used to receive result (and so define wanted type) 1082 * @param signed 1083 * assume input data as signed data 1084 */ 1085 public static float[][] arrayToFloatArray(Object in, float[][] out, boolean signed) 1086 { 1087 return arrayToFloatArray(in, 0, out, 0, -1, signed); 1088 } 1089 1090 /** 1091 * Convert and return the 'in' array as a float array.<br> 1092 * 1093 * @param in 1094 * input array 1095 * @param signed 1096 * assume input data as signed data 1097 */ 1098 public static float[][] arrayToFloatArray(Object in, boolean signed) 1099 { 1100 return arrayToFloatArray(in, 0, null, 0, -1, signed); 1101 } 1102 1103 /** 1104 * Convert and return the 'in' array in 'out' int array.<br> 1105 * 1106 * @param in 1107 * input array 1108 * @param inOffset 1109 * position where we start read data from 1110 * @param out 1111 * output array which is used to receive result (and so define wanted type) 1112 * @param outOffset 1113 * position where we start to write data to 1114 * @param length 1115 * number of value to convert (-1 means we will use the maximum possible length) 1116 * @param signed 1117 * assume input data as signed data 1118 */ 1119 public static int[][] arrayToIntArray(Object in, int inOffset, int[][] out, int outOffset, int length, 1120 boolean signed) 1121 { 1122 switch (ArrayUtil.getDataType(in)) 1123 { 1124 case BYTE: 1125 return byteArrayToIntArray((byte[][]) in, inOffset, out, outOffset, length, signed); 1126 case SHORT: 1127 return shortArrayToIntArray((short[][]) in, inOffset, out, outOffset, length, signed); 1128 case INT: 1129 return intArrayToIntArray((int[][]) in, inOffset, out, outOffset, length); 1130 case LONG: 1131 return longArrayToIntArray((long[][]) in, inOffset, out, outOffset, length); 1132 case FLOAT: 1133 return floatArrayToIntArray((float[][]) in, inOffset, out, outOffset, length); 1134 case DOUBLE: 1135 return doubleArrayToIntArray((double[][]) in, inOffset, out, outOffset, length); 1136 default: 1137 return out; 1138 } 1139 } 1140 1141 /** 1142 * Convert and return the 'in' array in 'out' int array.<br> 1143 * 1144 * @param in 1145 * input array 1146 * @param out 1147 * output array which is used to receive result (and so define wanted type) 1148 * @param signed 1149 * assume input data as signed data 1150 */ 1151 public static int[][] arrayToIntArray(Object in, int[][] out, boolean signed) 1152 { 1153 return arrayToIntArray(in, 0, out, 0, -1, signed); 1154 } 1155 1156 /** 1157 * Convert and return the 'in' array as a int array.<br> 1158 * 1159 * @param in 1160 * input array 1161 * @param signed 1162 * assume input data as signed data 1163 */ 1164 public static int[][] arrayToIntArray(Object in, boolean signed) 1165 { 1166 return arrayToIntArray(in, 0, null, 0, -1, signed); 1167 } 1168 1169 /** 1170 * Convert and return the 'in' array in 'out' short array.<br> 1171 * 1172 * @param in 1173 * input array 1174 * @param inOffset 1175 * position where we start read data from 1176 * @param out 1177 * output array which is used to receive result (and so define wanted type) 1178 * @param outOffset 1179 * position where we start to write data to 1180 * @param length 1181 * number of value to convert (-1 means we will use the maximum possible length) 1182 * @param signed 1183 * assume input data as signed data 1184 */ 1185 public static short[][] arrayToShortArray(Object in, int inOffset, short[][] out, int outOffset, int length, 1186 boolean signed) 1187 { 1188 switch (ArrayUtil.getDataType(in)) 1189 { 1190 case BYTE: 1191 return byteArrayToShortArray((byte[][]) in, inOffset, out, outOffset, length, signed); 1192 case SHORT: 1193 return shortArrayToShortArray((short[][]) in, inOffset, out, outOffset, length); 1194 case INT: 1195 return intArrayToShortArray((int[][]) in, inOffset, out, outOffset, length); 1196 case LONG: 1197 return longArrayToShortArray((long[][]) in, inOffset, out, outOffset, length); 1198 case FLOAT: 1199 return floatArrayToShortArray((float[][]) in, inOffset, out, outOffset, length); 1200 case DOUBLE: 1201 return doubleArrayToShortArray((double[][]) in, inOffset, out, outOffset, length); 1202 default: 1203 return out; 1204 } 1205 } 1206 1207 /** 1208 * Convert and return the 'in' array in 'out' short array.<br> 1209 * 1210 * @param in 1211 * input array 1212 * @param out 1213 * output array which is used to receive result (and so define wanted type) 1214 * @param signed 1215 * assume input data as signed data 1216 */ 1217 public static short[][] arrayToShortArray(Object in, short[][] out, boolean signed) 1218 { 1219 return arrayToShortArray(in, 0, out, 0, -1, signed); 1220 } 1221 1222 /** 1223 * Convert and return the 'in' array as a short array.<br> 1224 * 1225 * @param in 1226 * input array 1227 * @param signed 1228 * assume input data as signed data 1229 */ 1230 public static short[][] arrayToShortArray(Object in, boolean signed) 1231 { 1232 return arrayToShortArray(in, 0, null, 0, -1, signed); 1233 } 1234 1235 /** 1236 * Convert and return the 'in' array in 'out' byte array.<br> 1237 * 1238 * @param in 1239 * input array 1240 * @param inOffset 1241 * position where we start read data from 1242 * @param out 1243 * output array which is used to receive result (and so define wanted type) 1244 * @param outOffset 1245 * position where we start to write data to 1246 * @param length 1247 * number of value to convert (-1 means we will use the maximum possible length) 1248 */ 1249 public static byte[][] arrayToByteArray(Object in, int inOffset, byte[][] out, int outOffset, int length) 1250 { 1251 switch (ArrayUtil.getDataType(in)) 1252 { 1253 case BYTE: 1254 return byteArrayToByteArray((byte[][]) in, inOffset, out, outOffset, length); 1255 case SHORT: 1256 return shortArrayToByteArray((short[][]) in, inOffset, out, outOffset, length); 1257 case INT: 1258 return intArrayToByteArray((int[][]) in, inOffset, out, outOffset, length); 1259 case LONG: 1260 return longArrayToByteArray((long[][]) in, inOffset, out, outOffset, length); 1261 case FLOAT: 1262 return floatArrayToByteArray((float[][]) in, inOffset, out, outOffset, length); 1263 case DOUBLE: 1264 return doubleArrayToByteArray((double[][]) in, inOffset, out, outOffset, length); 1265 default: 1266 return out; 1267 } 1268 } 1269 1270 /** 1271 * Convert and return the 'in' array in 'out' byte array.<br> 1272 * 1273 * @param in 1274 * input array 1275 * @param out 1276 * output array which is used to receive result (and so define wanted type) 1277 */ 1278 public static byte[][] arrayToByteArray(Object in, byte[][] out) 1279 { 1280 return arrayToByteArray(in, 0, out, 0, -1); 1281 } 1282 1283 /** 1284 * Convert and return the 'in' array as a byte array.<br> 1285 * 1286 * @param in 1287 * input array 1288 */ 1289 public static byte[][] arrayToByteArray(Object in) 1290 { 1291 return arrayToByteArray(in, 0, null, 0, -1); 1292 } 1293 1294 // 1295 // 1296 // 1297 // 1298 // 1299 // 1300 // 1301 // 1302 // 1303 // 1304 // 1305 // 1306 // 1307 1308 public static double[][] doubleArrayToDoubleArray(double[][] in, int inOffset, double[][] out, int outOffset, 1309 int length) 1310 { 1311 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1312 final double[][] result = allocIfNull(out, outOffset + len); 1313 1314 for (int i = 0; i < len; i++) 1315 result[i + outOffset] = Array1DUtil.doubleArrayToDoubleArray(in[i + inOffset], 0, result[i + outOffset], 0, 1316 -1); 1317 1318 return result; 1319 } 1320 1321 public static float[][] doubleArrayToFloatArray(double[][] in, int inOffset, float[][] out, int outOffset, 1322 int length) 1323 { 1324 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1325 final float[][] result = allocIfNull(out, outOffset + len); 1326 1327 for (int i = 0; i < len; i++) 1328 result[i + outOffset] = Array1DUtil.doubleArrayToFloatArray(in[i + inOffset], 0, result[i + outOffset], 0, 1329 -1); 1330 1331 return result; 1332 } 1333 1334 public static long[][] doubleArrayToLongArray(double[][] in, int inOffset, long[][] out, int outOffset, int length) 1335 { 1336 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1337 final long[][] result = allocIfNull(out, outOffset + len); 1338 1339 for (int i = 0; i < len; i++) 1340 result[i + outOffset] = Array1DUtil.doubleArrayToLongArray(in[i + inOffset], 0, result[i + outOffset], 0, 1341 -1); 1342 1343 return result; 1344 } 1345 1346 public static int[][] doubleArrayToIntArray(double[][] in, int inOffset, int[][] out, int outOffset, int length) 1347 { 1348 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1349 final int[][] result = allocIfNull(out, outOffset + len); 1350 1351 for (int i = 0; i < len; i++) 1352 result[i + outOffset] = Array1DUtil.doubleArrayToIntArray(in[i + inOffset], 0, result[i + outOffset], 0, 1353 -1); 1354 1355 return result; 1356 } 1357 1358 public static short[][] doubleArrayToShortArray(double[][] in, int inOffset, short[][] out, int outOffset, 1359 int length) 1360 { 1361 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1362 final short[][] result = allocIfNull(out, outOffset + len); 1363 1364 for (int i = 0; i < len; i++) 1365 result[i + outOffset] = Array1DUtil.doubleArrayToShortArray(in[i + inOffset], 0, result[i + outOffset], 0, 1366 -1); 1367 1368 return result; 1369 } 1370 1371 public static byte[][] doubleArrayToByteArray(double[][] in, int inOffset, byte[][] out, int outOffset, int length) 1372 { 1373 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1374 final byte[][] result = allocIfNull(out, outOffset + len); 1375 1376 for (int i = 0; i < len; i++) 1377 result[i + outOffset] = Array1DUtil.doubleArrayToByteArray(in[i + inOffset], 0, result[i + outOffset], 0, 1378 -1); 1379 1380 return result; 1381 } 1382 1383 public static double[][] floatArrayToDoubleArray(float[][] in, int inOffset, double[][] out, int outOffset, 1384 int length) 1385 { 1386 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1387 final double[][] result = allocIfNull(out, outOffset + len); 1388 1389 for (int i = 0; i < len; i++) 1390 result[i + outOffset] = Array1DUtil.floatArrayToDoubleArray(in[i + inOffset], 0, result[i + outOffset], 0, 1391 -1); 1392 1393 return result; 1394 } 1395 1396 public static float[][] floatArrayToFloatArray(float[][] in, int inOffset, float[][] out, int outOffset, int length) 1397 { 1398 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1399 final float[][] result = allocIfNull(out, outOffset + len); 1400 1401 for (int i = 0; i < len; i++) 1402 result[i + outOffset] = Array1DUtil.floatArrayToFloatArray(in[i + inOffset], 0, result[i + outOffset], 0, 1403 -1); 1404 1405 return result; 1406 } 1407 1408 public static long[][] floatArrayToLongArray(float[][] in, int inOffset, long[][] out, int outOffset, int length) 1409 { 1410 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1411 final long[][] result = allocIfNull(out, outOffset + len); 1412 1413 for (int i = 0; i < len; i++) 1414 result[i + outOffset] = Array1DUtil.floatArrayToLongArray(in[i + inOffset], 0, result[i + outOffset], 0, 1415 -1); 1416 1417 return result; 1418 } 1419 1420 public static int[][] floatArrayToIntArray(float[][] in, int inOffset, int[][] out, int outOffset, int length) 1421 { 1422 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1423 final int[][] result = allocIfNull(out, outOffset + len); 1424 1425 for (int i = 0; i < len; i++) 1426 result[i + outOffset] = Array1DUtil.floatArrayToIntArray(in[i + inOffset], 0, result[i + outOffset], 0, -1); 1427 1428 return result; 1429 } 1430 1431 public static short[][] floatArrayToShortArray(float[][] in, int inOffset, short[][] out, int outOffset, int length) 1432 { 1433 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1434 final short[][] result = allocIfNull(out, outOffset + len); 1435 1436 for (int i = 0; i < len; i++) 1437 result[i + outOffset] = Array1DUtil.floatArrayToShortArray(in[i + inOffset], 0, result[i + outOffset], 0, 1438 -1); 1439 1440 return result; 1441 } 1442 1443 public static byte[][] floatArrayToByteArray(float[][] in, int inOffset, byte[][] out, int outOffset, int length) 1444 { 1445 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1446 final byte[][] result = allocIfNull(out, outOffset + len); 1447 1448 for (int i = 0; i < len; i++) 1449 result[i + outOffset] = Array1DUtil.floatArrayToByteArray(in[i + inOffset], 0, result[i + outOffset], 0, 1450 -1); 1451 1452 return result; 1453 } 1454 1455 public static double[][] longArrayToDoubleArray(long[][] in, int inOffset, double[][] out, int outOffset, 1456 int length, boolean signed) 1457 { 1458 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1459 final double[][] result = allocIfNull(out, outOffset + len); 1460 1461 for (int i = 0; i < len; i++) 1462 result[i + outOffset] = Array1DUtil.longArrayToDoubleArray(in[i + inOffset], 0, result[i + outOffset], 0, 1463 -1, signed); 1464 1465 return result; 1466 } 1467 1468 public static float[][] longArrayToFloatArray(long[][] in, int inOffset, float[][] out, int outOffset, int length, 1469 boolean signed) 1470 { 1471 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1472 final float[][] result = allocIfNull(out, outOffset + len); 1473 1474 for (int i = 0; i < len; i++) 1475 result[i + outOffset] = Array1DUtil.longArrayToFloatArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1476 signed); 1477 1478 return result; 1479 } 1480 1481 public static long[][] longArrayToLongArray(long[][] in, int inOffset, long[][] out, int outOffset, int length) 1482 { 1483 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1484 final long[][] result = allocIfNull(out, outOffset + len); 1485 1486 for (int i = 0; i < len; i++) 1487 result[i + outOffset] = Array1DUtil.longArrayToLongArray(in[i + inOffset], 0, result[i + outOffset], 0, -1); 1488 1489 return result; 1490 } 1491 1492 public static int[][] longArrayToIntArray(long[][] in, int inOffset, int[][] out, int outOffset, int length) 1493 { 1494 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1495 final int[][] result = allocIfNull(out, outOffset + len); 1496 1497 for (int i = 0; i < len; i++) 1498 result[i + outOffset] = Array1DUtil.longArrayToIntArray(in[i + inOffset], 0, result[i + outOffset], 0, -1); 1499 1500 return result; 1501 } 1502 1503 public static short[][] longArrayToShortArray(long[][] in, int inOffset, short[][] out, int outOffset, int length) 1504 { 1505 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1506 final short[][] result = allocIfNull(out, outOffset + len); 1507 1508 for (int i = 0; i < len; i++) 1509 result[i + outOffset] = Array1DUtil.longArrayToShortArray(in[i + inOffset], 0, result[i + outOffset], 0, 1510 -1); 1511 1512 return result; 1513 } 1514 1515 public static byte[][] longArrayToByteArray(long[][] in, int inOffset, byte[][] out, int outOffset, int length) 1516 { 1517 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1518 final byte[][] result = allocIfNull(out, outOffset + len); 1519 1520 for (int i = 0; i < len; i++) 1521 result[i + outOffset] = Array1DUtil.longArrayToByteArray(in[i + inOffset], 0, result[i + outOffset], 0, -1); 1522 1523 return result; 1524 } 1525 1526 public static double[][] intArrayToDoubleArray(int[][] in, int inOffset, double[][] out, int outOffset, int length, 1527 boolean signed) 1528 { 1529 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1530 final double[][] result = allocIfNull(out, outOffset + len); 1531 1532 for (int i = 0; i < len; i++) 1533 result[i + outOffset] = Array1DUtil.intArrayToDoubleArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1534 signed); 1535 1536 return result; 1537 } 1538 1539 public static float[][] intArrayToFloatArray(int[][] in, int inOffset, float[][] out, int outOffset, int length, 1540 boolean signed) 1541 { 1542 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1543 final float[][] result = allocIfNull(out, outOffset + len); 1544 1545 for (int i = 0; i < len; i++) 1546 result[i + outOffset] = Array1DUtil.intArrayToFloatArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1547 signed); 1548 1549 return result; 1550 } 1551 1552 public static long[][] intArrayToLongArray(int[][] in, int inOffset, long[][] out, int outOffset, int length, 1553 boolean signed) 1554 { 1555 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1556 final long[][] result = allocIfNull(out, outOffset + len); 1557 1558 for (int i = 0; i < len; i++) 1559 result[i + outOffset] = Array1DUtil.intArrayToLongArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1560 signed); 1561 1562 return result; 1563 } 1564 1565 public static int[][] intArrayToIntArray(int[][] in, int inOffset, int[][] out, int outOffset, int length) 1566 { 1567 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1568 final int[][] result = allocIfNull(out, outOffset + len); 1569 1570 for (int i = 0; i < len; i++) 1571 result[i + outOffset] = Array1DUtil.intArrayToIntArray(in[i + inOffset], 0, result[i + outOffset], 0, -1); 1572 1573 return result; 1574 } 1575 1576 public static short[][] intArrayToShortArray(int[][] in, int inOffset, short[][] out, int outOffset, int length) 1577 { 1578 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1579 final short[][] result = allocIfNull(out, outOffset + len); 1580 1581 for (int i = 0; i < len; i++) 1582 result[i + outOffset] = Array1DUtil.intArrayToShortArray(in[i + inOffset], 0, result[i + outOffset], 0, -1); 1583 1584 return result; 1585 } 1586 1587 public static byte[][] intArrayToByteArray(int[][] in, int inOffset, byte[][] out, int outOffset, int length) 1588 { 1589 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1590 final byte[][] result = allocIfNull(out, outOffset + len); 1591 1592 for (int i = 0; i < len; i++) 1593 result[i + outOffset] = Array1DUtil.intArrayToByteArray(in[i + inOffset], 0, result[i + outOffset], 0, -1); 1594 1595 return result; 1596 } 1597 1598 public static double[][] shortArrayToDoubleArray(short[][] in, int inOffset, double[][] out, int outOffset, 1599 int length, boolean signed) 1600 { 1601 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1602 final double[][] result = allocIfNull(out, outOffset + len); 1603 1604 for (int i = 0; i < len; i++) 1605 result[i + outOffset] = Array1DUtil.shortArrayToDoubleArray(in[i + inOffset], 0, result[i + outOffset], 0, 1606 -1, signed); 1607 1608 return result; 1609 } 1610 1611 public static float[][] shortArrayToFloatArray(short[][] in, int inOffset, float[][] out, int outOffset, int length, 1612 boolean signed) 1613 { 1614 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1615 final float[][] result = allocIfNull(out, outOffset + len); 1616 1617 for (int i = 0; i < len; i++) 1618 result[i + outOffset] = Array1DUtil.shortArrayToFloatArray(in[i + inOffset], 0, result[i + outOffset], 0, 1619 -1, signed); 1620 1621 return result; 1622 } 1623 1624 public static long[][] shortArrayToLongArray(short[][] in, int inOffset, long[][] out, int outOffset, int length, 1625 boolean signed) 1626 { 1627 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1628 final long[][] result = allocIfNull(out, outOffset + len); 1629 1630 for (int i = 0; i < len; i++) 1631 result[i + outOffset] = Array1DUtil.shortArrayToLongArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1632 signed); 1633 1634 return result; 1635 } 1636 1637 public static int[][] shortArrayToIntArray(short[][] in, int inOffset, int[][] out, int outOffset, int length, 1638 boolean signed) 1639 { 1640 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1641 final int[][] result = allocIfNull(out, outOffset + len); 1642 1643 for (int i = 0; i < len; i++) 1644 result[i + outOffset] = Array1DUtil.shortArrayToIntArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1645 signed); 1646 1647 return result; 1648 } 1649 1650 public static short[][] shortArrayToShortArray(short[][] in, int inOffset, short[][] out, int outOffset, int length) 1651 { 1652 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1653 final short[][] result = allocIfNull(out, outOffset + len); 1654 1655 for (int i = 0; i < len; i++) 1656 result[i + outOffset] = Array1DUtil.shortArrayToShortArray(in[i + inOffset], 0, result[i + outOffset], 0, 1657 -1); 1658 1659 return result; 1660 } 1661 1662 public static byte[][] shortArrayToByteArray(short[][] in, int inOffset, byte[][] out, int outOffset, int length) 1663 { 1664 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1665 final byte[][] result = allocIfNull(out, outOffset + len); 1666 1667 for (int i = 0; i < len; i++) 1668 result[i + outOffset] = Array1DUtil.shortArrayToByteArray(in[i + inOffset], 0, result[i + outOffset], 0, 1669 -1); 1670 1671 return result; 1672 } 1673 1674 public static double[][] byteArrayToDoubleArray(byte[][] in, int inOffset, double[][] out, int outOffset, 1675 int length, boolean signed) 1676 { 1677 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1678 final double[][] result = allocIfNull(out, outOffset + len); 1679 1680 for (int i = 0; i < len; i++) 1681 result[i + outOffset] = Array1DUtil.byteArrayToDoubleArray(in[i + inOffset], 0, result[i + outOffset], 0, 1682 -1, signed); 1683 1684 return result; 1685 } 1686 1687 public static float[][] byteArrayToFloatArray(byte[][] in, int inOffset, float[][] out, int outOffset, int length, 1688 boolean signed) 1689 { 1690 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1691 final float[][] result = allocIfNull(out, outOffset + len); 1692 1693 for (int i = 0; i < len; i++) 1694 result[i + outOffset] = Array1DUtil.byteArrayToFloatArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1695 signed); 1696 1697 return result; 1698 } 1699 1700 public static long[][] byteArrayToLongArray(byte[][] in, int inOffset, long[][] out, int outOffset, int length, 1701 boolean signed) 1702 { 1703 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1704 final long[][] result = allocIfNull(out, outOffset + len); 1705 1706 for (int i = 0; i < len; i++) 1707 result[i + outOffset] = Array1DUtil.byteArrayToLongArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1708 signed); 1709 1710 return result; 1711 } 1712 1713 public static int[][] byteArrayToIntArray(byte[][] in, int inOffset, int[][] out, int outOffset, int length, 1714 boolean signed) 1715 { 1716 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1717 final int[][] result = allocIfNull(out, outOffset + len); 1718 1719 for (int i = 0; i < len; i++) 1720 result[i + outOffset] = Array1DUtil.byteArrayToIntArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1721 signed); 1722 1723 return result; 1724 } 1725 1726 public static short[][] byteArrayToShortArray(byte[][] in, int inOffset, short[][] out, int outOffset, int length, 1727 boolean signed) 1728 { 1729 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1730 final short[][] result = allocIfNull(out, outOffset + len); 1731 1732 for (int i = 0; i < len; i++) 1733 result[i + outOffset] = Array1DUtil.byteArrayToShortArray(in[i + inOffset], 0, result[i + outOffset], 0, -1, 1734 signed); 1735 1736 return result; 1737 } 1738 1739 public static byte[][] byteArrayToByteArray(byte[][] in, int inOffset, byte[][] out, int outOffset, int length) 1740 { 1741 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 1742 final byte[][] result = allocIfNull(out, outOffset + len); 1743 1744 for (int i = 0; i < len; i++) 1745 result[i + outOffset] = Array1DUtil.byteArrayToByteArray(in[i + inOffset], 0, result[i + outOffset], 0, -1); 1746 1747 return result; 1748 } 1749 1750 public static float[][] doubleArrayToFloatArray(double[][] array) 1751 { 1752 return doubleArrayToFloatArray(array, 0, null, 0, array.length); 1753 } 1754 1755 public static int[][] doubleArrayToIntArray(double[][] array) 1756 { 1757 return doubleArrayToIntArray(array, 0, null, 0, array.length); 1758 } 1759 1760 public static short[][] doubleArrayToShortArray(double[][] array) 1761 { 1762 return doubleArrayToShortArray(array, 0, null, 0, array.length); 1763 } 1764 1765 public static byte[][] doubleArrayToByteArray(double[][] array) 1766 { 1767 return doubleArrayToByteArray(array, 0, null, 0, array.length); 1768 } 1769 1770 public static double[][] floatArrayToDoubleArray(float[][] array) 1771 { 1772 return floatArrayToDoubleArray(array, 0, null, 0, array.length); 1773 } 1774 1775 public static int[][] floatArrayToIntArray(float[][] array) 1776 { 1777 return floatArrayToIntArray(array, 0, null, 0, array.length); 1778 } 1779 1780 public static short[][] floatArrayToShortArray(float[][] array) 1781 { 1782 return floatArrayToShortArray(array, 0, null, 0, array.length); 1783 } 1784 1785 public static byte[][] floatArrayToByteArray(float[][] array) 1786 { 1787 return floatArrayToByteArray(array, 0, null, 0, array.length); 1788 } 1789 1790 public static double[][] intArrayToDoubleArray(int[][] array, boolean signed) 1791 { 1792 return intArrayToDoubleArray(array, 0, null, 0, array.length, signed); 1793 } 1794 1795 public static float[][] intArrayToFloatArray(int[][] array, boolean signed) 1796 { 1797 return intArrayToFloatArray(array, 0, null, 0, array.length, signed); 1798 } 1799 1800 public static short[][] intArrayToShortArray(int[][] array) 1801 { 1802 return intArrayToShortArray(array, 0, null, 0, array.length); 1803 } 1804 1805 public static byte[][] intArrayToByteArray(int[][] array) 1806 { 1807 return intArrayToByteArray(array, 0, null, 0, array.length); 1808 } 1809 1810 public static double[][] shortArrayToDoubleArray(short[][] array, boolean signed) 1811 { 1812 return shortArrayToDoubleArray(array, 0, null, 0, array.length, signed); 1813 } 1814 1815 public static float[][] shortArrayToFloatArray(short[][] array, boolean signed) 1816 { 1817 return shortArrayToFloatArray(array, 0, null, 0, array.length, signed); 1818 } 1819 1820 public static int[][] shortArrayToIntArray(short[][] array, boolean signed) 1821 { 1822 return shortArrayToIntArray(array, 0, null, 0, array.length, signed); 1823 } 1824 1825 public static byte[][] shortArrayToByteArray(short[][] array) 1826 { 1827 return shortArrayToByteArray(array, 0, null, 0, array.length); 1828 } 1829 1830 public static double[][] byteArrayToDoubleArray(byte[][] array, boolean signed) 1831 { 1832 return byteArrayToDoubleArray(array, 0, null, 0, array.length, signed); 1833 } 1834 1835 public static float[][] byteArrayToFloatArray(byte[][] array, boolean signed) 1836 { 1837 return byteArrayToFloatArray(array, 0, null, 0, array.length, signed); 1838 } 1839 1840 public static int[][] byteArrayToIntArray(byte[][] array, boolean signed) 1841 { 1842 return byteArrayToIntArray(array, 0, null, 0, array.length, signed); 1843 } 1844 1845 public static short[][] byteArrayToShortArray(byte[][] array, boolean signed) 1846 { 1847 return byteArrayToShortArray(array, 0, null, 0, array.length, signed); 1848 } 1849 1850 // 1851 // 1852 // 1853 // 1854 // 1855 // 1856 // 1857 // 1858 1859 public static Object doubleArrayToSafeArray(double[][] in, int inOffset, Object out, int outOffset, int length, 1860 boolean signed) 1861 { 1862 switch (ArrayUtil.getDataType(out)) 1863 { 1864 case BYTE: 1865 return doubleArrayToSafeByteArray(in, inOffset, (byte[][]) out, outOffset, length, signed); 1866 1867 case SHORT: 1868 return doubleArrayToSafeShortArray(in, inOffset, (short[][]) out, outOffset, length, signed); 1869 1870 case INT: 1871 return doubleArrayToSafeIntArray(in, inOffset, (int[][]) out, outOffset, length, signed); 1872 1873 case LONG: 1874 return doubleArrayToSafeLongArray(in, inOffset, (long[][]) out, outOffset, length, signed); 1875 1876 case FLOAT: 1877 return doubleArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length); 1878 1879 case DOUBLE: 1880 return doubleArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length); 1881 1882 default: 1883 return out; 1884 } 1885 } 1886 1887 public static Object doubleArrayToSafeArray(double[][] in, Object out, boolean signed) 1888 { 1889 return doubleArrayToSafeArray(in, 0, out, 0, -1, signed); 1890 } 1891 1892 public static Object floatArrayToSafeArray(float[][] in, int inOffset, Object out, int outOffset, int length, 1893 boolean signed) 1894 { 1895 switch (ArrayUtil.getDataType(out)) 1896 { 1897 case BYTE: 1898 return floatArrayToSafeByteArray(in, inOffset, (byte[][]) out, outOffset, length, signed); 1899 case SHORT: 1900 return floatArrayToSafeShortArray(in, inOffset, (short[][]) out, outOffset, length, signed); 1901 case INT: 1902 return floatArrayToSafeIntArray(in, inOffset, (int[][]) out, outOffset, length, signed); 1903 case LONG: 1904 return floatArrayToSafeLongArray(in, inOffset, (long[][]) out, outOffset, length, signed); 1905 case FLOAT: 1906 return floatArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length); 1907 case DOUBLE: 1908 return floatArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length); 1909 default: 1910 return out; 1911 } 1912 } 1913 1914 public static Object floatArrayToSafeArray(float[][] in, Object out, boolean signed) 1915 { 1916 return floatArrayToSafeArray(in, 0, out, 0, -1, signed); 1917 } 1918 1919 public static Object longArrayToSafeArray(long[][] in, int inOffset, Object out, int outOffset, int length, 1920 boolean srcSigned, boolean dstSigned) 1921 { 1922 switch (ArrayUtil.getDataType(out)) 1923 { 1924 case BYTE: 1925 return longArrayToSafeByteArray(in, inOffset, (byte[][]) out, outOffset, length, srcSigned, dstSigned); 1926 case SHORT: 1927 return longArrayToSafeShortArray(in, inOffset, (short[][]) out, outOffset, length, srcSigned, 1928 dstSigned); 1929 case INT: 1930 return longArrayToSafeIntArray(in, inOffset, (int[][]) out, outOffset, length, srcSigned, dstSigned); 1931 case LONG: 1932 return longArrayToSafeLongArray(in, inOffset, (long[][]) out, outOffset, length, srcSigned, dstSigned); 1933 case FLOAT: 1934 return longArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length, srcSigned); 1935 case DOUBLE: 1936 return longArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length, srcSigned); 1937 default: 1938 return out; 1939 } 1940 } 1941 1942 public static Object longArrayToSafeArray(long[][] in, Object out, boolean srcSigned, boolean dstSigned) 1943 { 1944 return longArrayToSafeArray(in, 0, out, 0, -1, srcSigned, dstSigned); 1945 } 1946 1947 /** 1948 * @deprecated Use {@link #longArrayToSafeArray(long[][], int, Object, int, int, boolean, boolean)} instead. 1949 */ 1950 @Deprecated 1951 public static Object longArrayToSafeArray(long[][] in, int inOffset, Object out, int outOffset, int length, 1952 boolean signed) 1953 { 1954 return longArrayToSafeArray(in, inOffset, out, outOffset, length, signed, signed); 1955 } 1956 1957 /** 1958 * @deprecated Use {@link #longArrayToSafeArray(long[][], Object, boolean, boolean)} instead. 1959 */ 1960 @Deprecated 1961 public static Object longArrayToSafeArray(long[][] in, Object out, boolean signed) 1962 { 1963 return longArrayToSafeArray(in, 0, out, 0, -1, signed); 1964 } 1965 1966 public static Object intArrayToSafeArray(int[][] in, int inOffset, Object out, int outOffset, int length, 1967 boolean srcSigned, boolean dstSigned) 1968 { 1969 switch (ArrayUtil.getDataType(out)) 1970 { 1971 case BYTE: 1972 return intArrayToSafeByteArray(in, inOffset, (byte[][]) out, outOffset, length, srcSigned, dstSigned); 1973 case SHORT: 1974 return intArrayToSafeShortArray(in, inOffset, (short[][]) out, outOffset, length, srcSigned, dstSigned); 1975 case INT: 1976 return intArrayToSafeIntArray(in, inOffset, (int[][]) out, outOffset, length, srcSigned, dstSigned); 1977 case LONG: 1978 return intArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length, srcSigned); 1979 case FLOAT: 1980 return intArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length, srcSigned); 1981 case DOUBLE: 1982 return intArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length, srcSigned); 1983 default: 1984 return out; 1985 } 1986 } 1987 1988 public static Object intArrayToSafeArray(int[][] in, Object out, boolean srcSigned, boolean dstSigned) 1989 { 1990 return intArrayToSafeArray(in, 0, out, 0, -1, srcSigned, dstSigned); 1991 } 1992 1993 /** 1994 * @deprecated Use {@link #intArrayToSafeArray(int[][], int, Object, int, int, boolean, boolean)} instead. 1995 */ 1996 @Deprecated 1997 public static Object intArrayToSafeArray(int[][] in, int inOffset, Object out, int outOffset, int length, 1998 boolean signed) 1999 { 2000 return intArrayToSafeArray(in, inOffset, out, outOffset, length, signed, signed); 2001 } 2002 2003 /** 2004 * @deprecated Use {@link #intArrayToSafeArray(int[][], Object, boolean, boolean)} instead. 2005 */ 2006 @Deprecated 2007 public static Object intArrayToSafeArray(int[][] in, Object out, boolean signed) 2008 { 2009 return intArrayToSafeArray(in, 0, out, 0, -1, signed); 2010 } 2011 2012 public static Object shortArrayToSafeArray(short[][] in, int inOffset, Object out, int outOffset, int length, 2013 boolean srcSigned, boolean dstSigned) 2014 { 2015 switch (ArrayUtil.getDataType(out)) 2016 { 2017 case BYTE: 2018 return shortArrayToSafeByteArray(in, inOffset, (byte[][]) out, outOffset, length, srcSigned, dstSigned); 2019 case SHORT: 2020 return shortArrayToSafeShortArray(in, inOffset, (short[][]) out, outOffset, length, srcSigned, 2021 dstSigned); 2022 case INT: 2023 return shortArrayToIntArray(in, inOffset, (int[][]) out, outOffset, length, srcSigned); 2024 case LONG: 2025 return shortArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length, srcSigned); 2026 case FLOAT: 2027 return shortArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length, srcSigned); 2028 case DOUBLE: 2029 return shortArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length, srcSigned); 2030 default: 2031 return out; 2032 } 2033 } 2034 2035 public static Object shortArrayToSafeArray(short[][] in, Object out, boolean srcSigned, boolean dstSigned) 2036 { 2037 return shortArrayToSafeArray(in, 0, out, 0, -1, srcSigned, dstSigned); 2038 } 2039 2040 /** 2041 * @deprecated Use {@link #shortArrayToSafeArray(short[][], int, Object, int, int, boolean, boolean)} instead. 2042 */ 2043 @Deprecated 2044 public static Object shortArrayToSafeArray(short[][] in, int inOffset, Object out, int outOffset, int length, 2045 boolean signed) 2046 { 2047 return shortArrayToSafeArray(in, inOffset, out, outOffset, length, signed, signed); 2048 } 2049 2050 /** 2051 * @deprecated Use {@link #shortArrayToSafeArray(short[][], Object, boolean, boolean)} instead. 2052 */ 2053 @Deprecated 2054 public static Object shortArrayToSafeArray(short[][] in, Object out, boolean signed) 2055 { 2056 return shortArrayToSafeArray(in, 0, out, 0, -1, signed); 2057 } 2058 2059 public static Object byteArrayToSafeArray(byte[][] in, int inOffset, Object out, int outOffset, int length, 2060 boolean srcSigned, boolean dstSigned) 2061 { 2062 switch (ArrayUtil.getDataType(out)) 2063 { 2064 case BYTE: 2065 return byteArrayToSafeByteArray(in, inOffset, (byte[][]) out, outOffset, length, srcSigned, dstSigned); 2066 case SHORT: 2067 return byteArrayToShortArray(in, inOffset, (short[][]) out, outOffset, length, srcSigned); 2068 case INT: 2069 return byteArrayToIntArray(in, inOffset, (int[][]) out, outOffset, length, srcSigned); 2070 case LONG: 2071 return byteArrayToLongArray(in, inOffset, (long[][]) out, outOffset, length, srcSigned); 2072 case FLOAT: 2073 return byteArrayToFloatArray(in, inOffset, (float[][]) out, outOffset, length, srcSigned); 2074 case DOUBLE: 2075 return byteArrayToDoubleArray(in, inOffset, (double[][]) out, outOffset, length, srcSigned); 2076 default: 2077 return out; 2078 } 2079 } 2080 2081 public static Object byteArrayToSafeArray(byte[][] in, Object out, boolean srcSigned, boolean dstSigned) 2082 { 2083 return byteArrayToSafeArray(in, 0, out, 0, -1, srcSigned, dstSigned); 2084 } 2085 2086 public static long[][] arrayToSafeLongArray(Object in, int inOffset, long[][] out, int outOffset, int length, 2087 boolean srcSigned, boolean dstSigned) 2088 { 2089 switch (ArrayUtil.getDataType(in)) 2090 { 2091 case BYTE: 2092 return byteArrayToLongArray((byte[][]) in, inOffset, out, outOffset, length, srcSigned); 2093 case SHORT: 2094 return shortArrayToLongArray((short[][]) in, inOffset, out, outOffset, length, srcSigned); 2095 case INT: 2096 return intArrayToLongArray((int[][]) in, inOffset, out, outOffset, length, srcSigned); 2097 case LONG: 2098 return longArrayToSafeLongArray((long[][]) in, inOffset, out, outOffset, length, srcSigned, dstSigned); 2099 case FLOAT: 2100 return floatArrayToSafeLongArray((float[][]) in, inOffset, out, outOffset, length, dstSigned); 2101 case DOUBLE: 2102 return doubleArrayToSafeLongArray((double[][]) in, inOffset, out, outOffset, length, dstSigned); 2103 default: 2104 return out; 2105 2106 } 2107 } 2108 2109 public static long[][] arrayToSafeLongArray(Object in, long[][] out, boolean srcSigned, boolean dstSigned) 2110 { 2111 return arrayToSafeLongArray(in, 0, out, 0, -1, srcSigned, dstSigned); 2112 } 2113 2114 /** 2115 * @deprecated Use {@link #arrayToSafeLongArray(Object, int, long[][], int, int, boolean, boolean)} instead 2116 */ 2117 @Deprecated 2118 public static long[][] arrayToSafeLongArray(Object in, int inOffset, long[][] out, int outOffset, int length, 2119 boolean signed) 2120 { 2121 return arrayToSafeLongArray(in, inOffset, out, outOffset, length, signed, signed); 2122 } 2123 2124 /** 2125 * @deprecated Use {@link #arrayToSafeLongArray(Object, long[][], boolean, boolean)} instead 2126 */ 2127 @Deprecated 2128 public static long[][] arrayToSafeLongArray(Object in, long[][] out, boolean signed) 2129 { 2130 return arrayToSafeLongArray(in, 0, out, 0, -1, signed, signed); 2131 } 2132 2133 public static int[][] arrayToSafeIntArray(Object in, int inOffset, int[][] out, int outOffset, int length, 2134 boolean srcSigned, boolean dstSigned) 2135 { 2136 switch (ArrayUtil.getDataType(in)) 2137 { 2138 case BYTE: 2139 return byteArrayToIntArray((byte[][]) in, inOffset, out, outOffset, length, srcSigned); 2140 case SHORT: 2141 return shortArrayToIntArray((short[][]) in, inOffset, out, outOffset, length, srcSigned); 2142 case INT: 2143 return intArrayToSafeIntArray((int[][]) in, inOffset, out, outOffset, length, srcSigned, dstSigned); 2144 case LONG: 2145 return longArrayToSafeIntArray((long[][]) in, inOffset, out, outOffset, length, srcSigned, dstSigned); 2146 case FLOAT: 2147 return floatArrayToSafeIntArray((float[][]) in, inOffset, out, outOffset, length, dstSigned); 2148 case DOUBLE: 2149 return doubleArrayToSafeIntArray((double[][]) in, inOffset, out, outOffset, length, dstSigned); 2150 default: 2151 return out; 2152 } 2153 } 2154 2155 public static int[][] arrayToSafeIntArray(Object in, int[][] out, boolean srcSigned, boolean dstSigned) 2156 { 2157 return arrayToSafeIntArray(in, 0, out, 0, -1, srcSigned, dstSigned); 2158 } 2159 2160 /** 2161 * @deprecated Use {@link #arrayToSafeIntArray(Object, int, int[][], int, int, boolean, boolean)} instead 2162 */ 2163 @Deprecated 2164 public static int[][] arrayToSafeIntArray(Object in, int inOffset, int[][] out, int outOffset, int length, 2165 boolean signed) 2166 { 2167 return arrayToSafeIntArray(in, inOffset, out, outOffset, length, signed, signed); 2168 } 2169 2170 /** 2171 * @deprecated Use {@link #arrayToSafeIntArray(Object, int[][], boolean, boolean)} instead 2172 */ 2173 @Deprecated 2174 public static int[][] arrayToSafeIntArray(Object in, int[][] out, boolean signed) 2175 { 2176 return arrayToSafeIntArray(in, 0, out, 0, -1, signed, signed); 2177 } 2178 2179 public static short[][] arrayToSafeShortArray(Object in, int inOffset, short[][] out, int outOffset, int length, 2180 boolean srcSigned, boolean dstSigned) 2181 { 2182 switch (ArrayUtil.getDataType(in)) 2183 { 2184 case BYTE: 2185 return byteArrayToShortArray((byte[][]) in, inOffset, out, outOffset, length, srcSigned); 2186 case SHORT: 2187 return shortArrayToSafeShortArray((short[][]) in, inOffset, out, outOffset, length, srcSigned, 2188 dstSigned); 2189 case INT: 2190 return intArrayToSafeShortArray((int[][]) in, inOffset, out, outOffset, length, srcSigned, dstSigned); 2191 case LONG: 2192 return longArrayToSafeShortArray((long[][]) in, inOffset, out, outOffset, length, srcSigned, dstSigned); 2193 case FLOAT: 2194 return floatArrayToSafeShortArray((float[][]) in, inOffset, out, outOffset, length, dstSigned); 2195 case DOUBLE: 2196 return doubleArrayToSafeShortArray((double[][]) in, inOffset, out, outOffset, length, dstSigned); 2197 default: 2198 return out; 2199 } 2200 } 2201 2202 public static short[][] arrayToSafeShortArray(Object in, short[][] out, boolean srcSigned, boolean dstSigned) 2203 { 2204 return arrayToSafeShortArray(in, 0, out, 0, -1, srcSigned, dstSigned); 2205 } 2206 2207 /** 2208 * @deprecated Use {@link #arrayToSafeShortArray(Object, int, short[][], int, int, boolean, boolean)} instead 2209 */ 2210 @Deprecated 2211 public static short[][] arrayToSafeShortArray(Object in, int inOffset, short[][] out, int outOffset, int length, 2212 boolean signed) 2213 { 2214 return arrayToSafeShortArray(in, inOffset, out, outOffset, length, signed, signed); 2215 } 2216 2217 /** 2218 * @deprecated Use {@link #arrayToSafeShortArray(Object, short[][], boolean, boolean)} instead 2219 */ 2220 @Deprecated 2221 public static short[][] arrayToSafeShortArray(Object in, short[][] out, boolean signed) 2222 { 2223 return arrayToSafeShortArray(in, 0, out, 0, -1, signed, signed); 2224 } 2225 2226 public static byte[][] arrayToSafeByteArray(Object in, int inOffset, byte[][] out, int outOffset, int length, 2227 boolean srcSigned, boolean dstSigned) 2228 { 2229 switch (ArrayUtil.getDataType(in)) 2230 { 2231 case BYTE: 2232 return byteArrayToSafeByteArray((byte[][]) in, inOffset, out, outOffset, length, srcSigned, dstSigned); 2233 case SHORT: 2234 return shortArrayToSafeByteArray((short[][]) in, inOffset, out, outOffset, length, srcSigned, 2235 dstSigned); 2236 case INT: 2237 return intArrayToSafeByteArray((int[][]) in, inOffset, out, outOffset, length, srcSigned, dstSigned); 2238 case LONG: 2239 return longArrayToSafeByteArray((long[][]) in, inOffset, out, outOffset, length, srcSigned, dstSigned); 2240 case FLOAT: 2241 return floatArrayToSafeByteArray((float[][]) in, inOffset, out, outOffset, length, dstSigned); 2242 case DOUBLE: 2243 return doubleArrayToSafeByteArray((double[][]) in, inOffset, out, outOffset, length, dstSigned); 2244 default: 2245 return out; 2246 } 2247 } 2248 2249 public static byte[][] arrayToSafeByteArray(Object in, byte[][] out, boolean srcSigned, boolean dstSigned) 2250 { 2251 return arrayToSafeByteArray(in, 0, out, 0, -1, srcSigned, dstSigned); 2252 } 2253 2254 /** 2255 * @deprecated Use {@link #arrayToSafeByteArray(Object, int, byte[][], int, int, boolean, boolean)} instead 2256 */ 2257 @Deprecated 2258 public static byte[][] arrayToSafeByteArray(Object in, int inOffset, byte[][] out, int outOffset, int length, 2259 boolean signed) 2260 { 2261 return arrayToSafeByteArray(in, inOffset, out, outOffset, length, signed, signed); 2262 } 2263 2264 /** 2265 * @deprecated Use {@link #arrayToSafeByteArray(Object, byte[][], boolean, boolean)} instead 2266 */ 2267 @Deprecated 2268 public static byte[][] arrayToSafeByteArray(Object in, byte[][] out, boolean signed) 2269 { 2270 return arrayToSafeByteArray(in, 0, out, 0, -1, signed, signed); 2271 } 2272 2273 // 2274 // 2275 // 2276 // 2277 // 2278 // 2279 // 2280 // 2281 2282 public static long[][] doubleArrayToSafeLongArray(double[][] in, int inOffset, long[][] out, int outOffset, 2283 int length, boolean signed) 2284 { 2285 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2286 final long[][] outArray = allocIfNull(out, outOffset + len); 2287 2288 for (int i = 0; i < len; i++) 2289 outArray[i + outOffset] = Array1DUtil.doubleArrayToSafeLongArray(in[i + inOffset], 0, 2290 outArray[i + outOffset], 0, -1, signed); 2291 2292 return outArray; 2293 } 2294 2295 public static int[][] doubleArrayToSafeIntArray(double[][] in, int inOffset, int[][] out, int outOffset, int length, 2296 boolean signed) 2297 { 2298 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2299 final int[][] outArray = allocIfNull(out, outOffset + len); 2300 2301 for (int i = 0; i < len; i++) 2302 outArray[i + outOffset] = Array1DUtil.doubleArrayToSafeIntArray(in[i + inOffset], 0, 2303 outArray[i + outOffset], 0, -1, signed); 2304 2305 return outArray; 2306 } 2307 2308 public static short[][] doubleArrayToSafeShortArray(double[][] in, int inOffset, short[][] out, int outOffset, 2309 int length, boolean signed) 2310 { 2311 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2312 final short[][] outArray = allocIfNull(out, outOffset + len); 2313 2314 for (int i = 0; i < len; i++) 2315 outArray[i + outOffset] = Array1DUtil.doubleArrayToSafeShortArray(in[i + inOffset], 0, 2316 outArray[i + outOffset], 0, -1, signed); 2317 2318 return outArray; 2319 } 2320 2321 public static byte[][] doubleArrayToSafeByteArray(double[][] in, int inOffset, byte[][] out, int outOffset, 2322 int length, boolean signed) 2323 { 2324 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2325 final byte[][] outArray = allocIfNull(out, outOffset + len); 2326 2327 for (int i = 0; i < len; i++) 2328 outArray[i + outOffset] = Array1DUtil.doubleArrayToSafeByteArray(in[i + inOffset], 0, 2329 outArray[i + outOffset], 0, -1, signed); 2330 2331 return outArray; 2332 } 2333 2334 public static long[][] floatArrayToSafeLongArray(float[][] in, int inOffset, long[][] out, int outOffset, 2335 int length, boolean signed) 2336 { 2337 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2338 final long[][] outArray = allocIfNull(out, outOffset + len); 2339 2340 for (int i = 0; i < len; i++) 2341 outArray[i + outOffset] = Array1DUtil.floatArrayToSafeLongArray(in[i + inOffset], 0, 2342 outArray[i + outOffset], 0, -1, signed); 2343 2344 return outArray; 2345 } 2346 2347 public static int[][] floatArrayToSafeIntArray(float[][] in, int inOffset, int[][] out, int outOffset, int length, 2348 boolean signed) 2349 { 2350 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2351 final int[][] outArray = allocIfNull(out, outOffset + len); 2352 2353 for (int i = 0; i < len; i++) 2354 outArray[i + outOffset] = Array1DUtil.floatArrayToSafeIntArray(in[i + inOffset], 0, outArray[i + outOffset], 2355 0, -1, signed); 2356 2357 return outArray; 2358 } 2359 2360 public static short[][] floatArrayToSafeShortArray(float[][] in, int inOffset, short[][] out, int outOffset, 2361 int length, boolean signed) 2362 { 2363 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2364 final short[][] outArray = allocIfNull(out, outOffset + len); 2365 2366 for (int i = 0; i < len; i++) 2367 outArray[i + outOffset] = Array1DUtil.floatArrayToSafeShortArray(in[i + inOffset], 0, 2368 outArray[i + outOffset], 0, -1, signed); 2369 2370 return outArray; 2371 } 2372 2373 public static byte[][] floatArrayToSafeByteArray(float[][] in, int inOffset, byte[][] out, int outOffset, 2374 int length, boolean signed) 2375 { 2376 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2377 final byte[][] outArray = allocIfNull(out, outOffset + len); 2378 2379 for (int i = 0; i < len; i++) 2380 outArray[i + outOffset] = Array1DUtil.floatArrayToSafeByteArray(in[i + inOffset], 0, 2381 outArray[i + outOffset], 0, -1, signed); 2382 2383 return outArray; 2384 } 2385 2386 public static long[][] longArrayToSafeLongArray(long[][] in, int inOffset, long[][] out, int outOffset, int length, 2387 boolean srcSigned, boolean dstSigned) 2388 { 2389 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2390 final long[][] outArray = allocIfNull(out, outOffset + len); 2391 2392 for (int i = 0; i < len; i++) 2393 outArray[i + outOffset] = Array1DUtil.longArrayToSafeLongArray(in[i + inOffset], 0, outArray[i + outOffset], 2394 0, -1, srcSigned, dstSigned); 2395 2396 return outArray; 2397 } 2398 2399 public static int[][] longArrayToSafeIntArray(long[][] in, int inOffset, int[][] out, int outOffset, int length, 2400 boolean srcSigned, boolean dstSigned) 2401 { 2402 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2403 final int[][] outArray = allocIfNull(out, outOffset + len); 2404 2405 for (int i = 0; i < len; i++) 2406 outArray[i + outOffset] = Array1DUtil.longArrayToSafeIntArray(in[i + inOffset], 0, outArray[i + outOffset], 2407 0, -1, srcSigned, dstSigned); 2408 2409 return outArray; 2410 } 2411 2412 public static short[][] longArrayToSafeShortArray(long[][] in, int inOffset, short[][] out, int outOffset, 2413 int length, boolean srcSigned, boolean dstSigned) 2414 { 2415 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2416 final short[][] outArray = allocIfNull(out, outOffset + len); 2417 2418 for (int i = 0; i < len; i++) 2419 outArray[i + outOffset] = Array1DUtil.longArrayToSafeShortArray(in[i + inOffset], 0, 2420 outArray[i + outOffset], 0, -1, srcSigned, dstSigned); 2421 2422 return outArray; 2423 } 2424 2425 public static byte[][] longArrayToSafeByteArray(long[][] in, int inOffset, byte[][] out, int outOffset, int length, 2426 boolean srcSigned, boolean dstSigned) 2427 { 2428 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2429 final byte[][] outArray = allocIfNull(out, outOffset + len); 2430 2431 for (int i = 0; i < len; i++) 2432 outArray[i + outOffset] = Array1DUtil.longArrayToSafeByteArray(in[i + inOffset], 0, outArray[i + outOffset], 2433 0, -1, srcSigned, dstSigned); 2434 2435 return outArray; 2436 } 2437 2438 /** 2439 * @deprecated Use {@link #longArrayToSafeIntArray(long[][], int, int[][], int, int, boolean, boolean)} instead 2440 */ 2441 @Deprecated 2442 public static int[][] longArrayToSafeIntArray(long[][] in, int inOffset, int[][] out, int outOffset, int length, 2443 boolean signed) 2444 { 2445 return longArrayToSafeIntArray(in, inOffset, out, outOffset, length, signed, signed); 2446 } 2447 2448 /** 2449 * @deprecated Use {@link #longArrayToSafeShortArray(long[][], int, short[][], int, int, boolean, boolean)} instead 2450 */ 2451 @Deprecated 2452 public static short[][] longArrayToSafeShortArray(long[][] in, int inOffset, short[][] out, int outOffset, 2453 int length, boolean signed) 2454 { 2455 return longArrayToSafeShortArray(in, inOffset, out, outOffset, length, signed, signed); 2456 2457 } 2458 2459 /** 2460 * @deprecated Use {@link #longArrayToSafeByteArray(long[][], int, byte[][], int, int, boolean, boolean)} instead 2461 */ 2462 @Deprecated 2463 public static byte[][] longArrayToSafeByteArray(long[][] in, int inOffset, byte[][] out, int outOffset, int length, 2464 boolean signed) 2465 { 2466 return longArrayToSafeByteArray(in, inOffset, out, outOffset, length, signed, signed); 2467 } 2468 2469 public static int[][] intArrayToSafeIntArray(int[][] in, int inOffset, int[][] out, int outOffset, int length, 2470 boolean srcSigned, boolean dstSigned) 2471 { 2472 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2473 final int[][] outArray = allocIfNull(out, outOffset + len); 2474 2475 for (int i = 0; i < len; i++) 2476 outArray[i + outOffset] = Array1DUtil.intArrayToSafeIntArray(in[i + inOffset], 0, outArray[i + outOffset], 2477 0, -1, srcSigned, dstSigned); 2478 2479 return outArray; 2480 } 2481 2482 public static short[][] intArrayToSafeShortArray(int[][] in, int inOffset, short[][] out, int outOffset, int length, 2483 boolean srcSigned, boolean dstSigned) 2484 { 2485 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2486 final short[][] outArray = allocIfNull(out, outOffset + len); 2487 2488 for (int i = 0; i < len; i++) 2489 outArray[i + outOffset] = Array1DUtil.intArrayToSafeShortArray(in[i + inOffset], 0, outArray[i + outOffset], 2490 0, -1, srcSigned, dstSigned); 2491 2492 return outArray; 2493 } 2494 2495 public static byte[][] intArrayToSafeByteArray(int[][] in, int inOffset, byte[][] out, int outOffset, int length, 2496 boolean srcSigned, boolean dstSigned) 2497 { 2498 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2499 final byte[][] outArray = allocIfNull(out, outOffset + len); 2500 2501 for (int i = 0; i < len; i++) 2502 outArray[i + outOffset] = Array1DUtil.intArrayToSafeByteArray(in[i + inOffset], 0, outArray[i + outOffset], 2503 0, -1, srcSigned, dstSigned); 2504 2505 return outArray; 2506 } 2507 2508 /** 2509 * @deprecated Use {@link #intArrayToSafeShortArray(int[][], int, short[][], int, int, boolean, boolean)} instead 2510 */ 2511 @Deprecated 2512 public static short[][] intArrayToSafeShortArray(int[][] in, int inOffset, short[][] out, int outOffset, int length, 2513 boolean signed) 2514 { 2515 return intArrayToSafeShortArray(in, inOffset, out, outOffset, length, signed, signed); 2516 } 2517 2518 /** 2519 * @deprecated Use {@link #intArrayToSafeByteArray(int[][], int, byte[][], int, int, boolean, boolean)} instead 2520 */ 2521 @Deprecated 2522 public static byte[][] intArrayToSafeByteArray(int[][] in, int inOffset, byte[][] out, int outOffset, int length, 2523 boolean signed) 2524 { 2525 return intArrayToSafeByteArray(in, inOffset, out, outOffset, length, signed, signed); 2526 } 2527 2528 public static short[][] shortArrayToSafeShortArray(short[][] in, int inOffset, short[][] out, int outOffset, 2529 int length, boolean srcSigned, boolean dstSigned) 2530 { 2531 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2532 final short[][] outArray = allocIfNull(out, outOffset + len); 2533 2534 for (int i = 0; i < len; i++) 2535 outArray[i + outOffset] = Array1DUtil.shortArrayToSafeShortArray(in[i + inOffset], 0, 2536 outArray[i + outOffset], 0, -1, srcSigned, dstSigned); 2537 2538 return outArray; 2539 } 2540 2541 public static byte[][] shortArrayToSafeByteArray(short[][] in, int inOffset, byte[][] out, int outOffset, 2542 int length, boolean srcSigned, boolean dstSigned) 2543 { 2544 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2545 final byte[][] outArray = allocIfNull(out, outOffset + len); 2546 2547 for (int i = 0; i < len; i++) 2548 outArray[i + outOffset] = Array1DUtil.shortArrayToSafeByteArray(in[i + inOffset], 0, 2549 outArray[i + outOffset], 0, -1, srcSigned, dstSigned); 2550 2551 return outArray; 2552 } 2553 2554 /** 2555 * @deprecated Use {@link #shortArrayToSafeByteArray(short[][], int, byte[][], int, int, boolean, boolean)} instead 2556 */ 2557 @Deprecated 2558 public static byte[][] shortArrayToSafeByteArray(short[][] in, int inOffset, byte[][] out, int outOffset, 2559 int length, boolean signed) 2560 { 2561 return shortArrayToSafeByteArray(in, inOffset, out, outOffset, length, signed, signed); 2562 } 2563 2564 public static byte[][] byteArrayToSafeByteArray(byte[][] in, int inOffset, byte[][] out, int outOffset, int length, 2565 boolean srcSigned, boolean dstSigned) 2566 { 2567 final int len = ArrayUtil.getCopyLength(in, inOffset, out, outOffset, length); 2568 final byte[][] outArray = allocIfNull(out, outOffset + len); 2569 2570 for (int i = 0; i < len; i++) 2571 outArray[i + outOffset] = Array1DUtil.byteArrayToSafeByteArray(in[i + inOffset], 0, outArray[i + outOffset], 2572 0, -1, srcSigned, dstSigned); 2573 2574 return outArray; 2575 } 2576 2577 // 2578 // 2579 // 2580 // 2581 // 2582 // 2583 // 2584 2585 public static int[][] doubleArrayToSafeIntArray(double[][] array, boolean signed) 2586 { 2587 return doubleArrayToSafeIntArray(array, 0, null, 0, array.length, signed); 2588 } 2589 2590 public static short[][] doubleArrayToSafeShortArray(double[][] array, boolean signed) 2591 { 2592 return doubleArrayToSafeShortArray(array, 0, null, 0, array.length, signed); 2593 } 2594 2595 public static byte[][] doubleArrayToSafeByteArray(double[][] array, boolean signed) 2596 { 2597 return doubleArrayToSafeByteArray(array, 0, null, 0, array.length, signed); 2598 } 2599 2600 public static int[][] floatArrayToSafeIntArray(float[][] array, boolean signed) 2601 { 2602 return floatArrayToSafeIntArray(array, 0, null, 0, array.length, signed); 2603 } 2604 2605 public static short[][] floatArrayToSafeShortArray(float[][] array, boolean signed) 2606 { 2607 return floatArrayToSafeShortArray(array, 0, null, 0, array.length, signed); 2608 } 2609 2610 public static byte[][] floatArrayToSafeByteArray(float[][] array, boolean signed) 2611 { 2612 return floatArrayToSafeByteArray(array, 0, null, 0, array.length, signed); 2613 } 2614 2615 public static short[][] intArrayToSafeShortArray(int[][] array, boolean signed) 2616 { 2617 return intArrayToSafeShortArray(array, 0, null, 0, array.length, signed, signed); 2618 } 2619 2620 public static byte[][] intArrayToSafeByteArray(int[][] array, boolean signed) 2621 { 2622 return intArrayToSafeByteArray(array, 0, null, 0, array.length, signed, signed); 2623 } 2624 2625 public static byte[][] shortArrayToSafeByteArray(short[][] array, boolean signed) 2626 { 2627 return shortArrayToSafeByteArray(array, 0, null, 0, array.length, signed, signed); 2628 } 2629 2630}