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