001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import com.liferay.portal.kernel.bean.BeanPropertiesUtil;
018    import com.liferay.portal.kernel.json.JSONArray;
019    import com.liferay.portal.kernel.language.LanguageUtil;
020    
021    import java.lang.reflect.Array;
022    
023    import java.text.DateFormat;
024    
025    import java.util.ArrayList;
026    import java.util.Arrays;
027    import java.util.Collection;
028    import java.util.Comparator;
029    import java.util.Date;
030    import java.util.Iterator;
031    import java.util.List;
032    import java.util.Locale;
033    import java.util.Set;
034    import java.util.TreeSet;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    public class ArrayUtil {
040    
041            public static boolean[] append(boolean[]... arrays) {
042                    int length = 0;
043    
044                    for (boolean[] array : arrays) {
045                            length += array.length;
046                    }
047    
048                    boolean[] newArray = new boolean[length];
049    
050                    int previousLength = 0;
051    
052                    for (boolean[] array : arrays) {
053                            System.arraycopy(array, 0, newArray, previousLength, array.length);
054    
055                            previousLength += array.length;
056                    }
057    
058                    return newArray;
059            }
060    
061            public static boolean[] append(boolean[] array, boolean value) {
062                    boolean[] newArray = new boolean[array.length + 1];
063    
064                    System.arraycopy(array, 0, newArray, 0, array.length);
065    
066                    newArray[newArray.length - 1] = value;
067    
068                    return newArray;
069            }
070    
071            public static byte[] append(byte[]... arrays) {
072                    int length = 0;
073    
074                    for (byte[] array : arrays) {
075                            length += array.length;
076                    }
077    
078                    byte[] newArray = new byte[length];
079    
080                    int previousLength = 0;
081    
082                    for (byte[] array : arrays) {
083                            System.arraycopy(array, 0, newArray, previousLength, array.length);
084    
085                            previousLength += array.length;
086                    }
087    
088                    return newArray;
089            }
090    
091            public static byte[] append(byte[] array, byte value) {
092                    byte[] newArray = new byte[array.length + 1];
093    
094                    System.arraycopy(array, 0, newArray, 0, array.length);
095    
096                    newArray[newArray.length - 1] = value;
097    
098                    return newArray;
099            }
100    
101            public static char[] append(char[]... arrays) {
102                    int length = 0;
103    
104                    for (char[] array : arrays) {
105                            length += array.length;
106                    }
107    
108                    char[] newArray = new char[length];
109    
110                    int previousLength = 0;
111    
112                    for (char[] array : arrays) {
113                            System.arraycopy(array, 0, newArray, previousLength, array.length);
114    
115                            previousLength += array.length;
116                    }
117    
118                    return newArray;
119            }
120    
121            public static char[] append(char[] array, char value) {
122                    char[] newArray = new char[array.length + 1];
123    
124                    System.arraycopy(array, 0, newArray, 0, array.length);
125    
126                    newArray[newArray.length - 1] = value;
127    
128                    return newArray;
129            }
130    
131            public static double[] append(double[]... arrays) {
132                    int length = 0;
133    
134                    for (double[] array : arrays) {
135                            length += array.length;
136                    }
137    
138                    double[] newArray = new double[length];
139    
140                    int previousLength = 0;
141    
142                    for (double[] array : arrays) {
143                            System.arraycopy(array, 0, newArray, previousLength, array.length);
144    
145                            previousLength += array.length;
146                    }
147    
148                    return newArray;
149            }
150    
151            public static double[] append(double[] array, double value) {
152                    double[] newArray = new double[array.length + 1];
153    
154                    System.arraycopy(array, 0, newArray, 0, array.length);
155    
156                    newArray[newArray.length - 1] = value;
157    
158                    return newArray;
159            }
160    
161            public static float[] append(float[]... arrays) {
162                    int length = 0;
163    
164                    for (float[] array : arrays) {
165                            length += array.length;
166                    }
167    
168                    float[] newArray = new float[length];
169    
170                    int previousLength = 0;
171    
172                    for (float[] array : arrays) {
173                            System.arraycopy(array, 0, newArray, previousLength, array.length);
174    
175                            previousLength += array.length;
176                    }
177    
178                    return newArray;
179            }
180    
181            public static float[] append(float[] array, float value) {
182                    float[] newArray = new float[array.length + 1];
183    
184                    System.arraycopy(array, 0, newArray, 0, array.length);
185    
186                    newArray[newArray.length - 1] = value;
187    
188                    return newArray;
189            }
190    
191            public static int[] append(int[]... arrays) {
192                    int length = 0;
193    
194                    for (int[] array : arrays) {
195                            length += array.length;
196                    }
197    
198                    int[] newArray = new int[length];
199    
200                    int previousLength = 0;
201    
202                    for (int[] array : arrays) {
203                            System.arraycopy(array, 0, newArray, previousLength, array.length);
204    
205                            previousLength += array.length;
206                    }
207    
208                    return newArray;
209            }
210    
211            public static int[] append(int[] array, int value) {
212                    int[] newArray = new int[array.length + 1];
213    
214                    System.arraycopy(array, 0, newArray, 0, array.length);
215    
216                    newArray[newArray.length - 1] = value;
217    
218                    return newArray;
219            }
220    
221            public static long[] append(long[]... arrays) {
222                    int length = 0;
223    
224                    for (long[] array : arrays) {
225                            length += array.length;
226                    }
227    
228                    long[] newArray = new long[length];
229    
230                    int previousLength = 0;
231    
232                    for (long[] array : arrays) {
233                            System.arraycopy(array, 0, newArray, previousLength, array.length);
234    
235                            previousLength += array.length;
236                    }
237    
238                    return newArray;
239            }
240    
241            public static long[] append(long[] array, long value) {
242                    long[] newArray = new long[array.length + 1];
243    
244                    System.arraycopy(array, 0, newArray, 0, array.length);
245    
246                    newArray[newArray.length - 1] = value;
247    
248                    return newArray;
249            }
250    
251            public static short[] append(short[]... arrays) {
252                    int length = 0;
253    
254                    for (short[] array : arrays) {
255                            length += array.length;
256                    }
257    
258                    short[] newArray = new short[length];
259    
260                    int previousLength = 0;
261    
262                    for (short[] array : arrays) {
263                            System.arraycopy(array, 0, newArray, previousLength, array.length);
264    
265                            previousLength += array.length;
266                    }
267    
268                    return newArray;
269            }
270    
271            public static short[] append(short[] array, short value) {
272                    short[] newArray = new short[array.length + 1];
273    
274                    System.arraycopy(array, 0, newArray, 0, array.length);
275    
276                    newArray[newArray.length - 1] = value;
277    
278                    return newArray;
279            }
280    
281            public static <T> T[] append(T[]... arrays) {
282                    int length = 0;
283    
284                    for (T[] array : arrays) {
285                            length += array.length;
286                    }
287    
288                    Class<?> arraysClass = arrays[0].getClass();
289    
290                    T[] newArray = (T[])Array.newInstance(
291                            arraysClass.getComponentType(), length);
292    
293                    int previousLength = 0;
294    
295                    for (T[] array : arrays) {
296                            System.arraycopy(array, 0, newArray, previousLength, array.length);
297    
298                            previousLength += array.length;
299                    }
300    
301                    return newArray;
302            }
303    
304            public static <T> T[] append(T[] array, T value) {
305                    Class<?> arrayClass = array.getClass();
306    
307                    T[] newArray = (T[])Array.newInstance(
308                            arrayClass.getComponentType(), array.length + 1);
309    
310                    System.arraycopy(array, 0, newArray, 0, array.length);
311    
312                    newArray[array.length] = value;
313    
314                    return newArray;
315            }
316    
317            public static <T> T[] append(T[] array1, T[] array2) {
318                    Class<?> array1Class = array1.getClass();
319    
320                    T[] newArray = (T[])Array.newInstance(
321                            array1Class.getComponentType(), array1.length + array2.length);
322    
323                    System.arraycopy(array1, 0, newArray, 0, array1.length);
324    
325                    System.arraycopy(array2, 0, newArray, array1.length, array2.length);
326    
327                    return newArray;
328            }
329    
330            public static <T> T[][] append(T[][] array1, T[] value) {
331                    Class<?> array1Class = array1.getClass();
332    
333                    T[][] newArray = (T[][])Array.newInstance(
334                            array1Class.getComponentType(), array1.length + 1);
335    
336                    System.arraycopy(array1, 0, newArray, 0, array1.length);
337    
338                    newArray[array1.length] = value;
339    
340                    return newArray;
341            }
342    
343            public static <T> T[][] append(T[][] array1, T[][] array2) {
344                    Class<?> array1Class = array1.getClass();
345    
346                    T[][] newArray = (T[][])Array.newInstance(
347                            array1Class.getComponentType(), array1.length + array2.length);
348    
349                    System.arraycopy(array1, 0, newArray, 0, array1.length);
350                    System.arraycopy(array2, 0, newArray, array1.length, array2.length);
351    
352                    return newArray;
353            }
354    
355            public static boolean[] clone(boolean[] array) {
356                    boolean[] newArray = new boolean[array.length];
357    
358                    System.arraycopy(array, 0, newArray, 0, array.length);
359    
360                    return newArray;
361            }
362    
363            public static boolean[] clone(boolean[] array, int from, int to) {
364                    boolean[] newArray = new boolean[to - from];
365    
366                    System.arraycopy(
367                            array, from, newArray, 0,
368                            Math.min(array.length - from, newArray.length));
369    
370                    return newArray;
371            }
372    
373            public static byte[] clone(byte[] array) {
374                    byte[] newArray = new byte[array.length];
375    
376                    System.arraycopy(array, 0, newArray, 0, array.length);
377    
378                    return newArray;
379            }
380    
381            public static byte[] clone(byte[] array, int from, int to) {
382                    byte[] newArray = new byte[to - from];
383    
384                    System.arraycopy(
385                            array, from, newArray, 0,
386                            Math.min(array.length - from, newArray.length));
387    
388                    return newArray;
389            }
390    
391            public static char[] clone(char[] array) {
392                    char[] newArray = new char[array.length];
393    
394                    System.arraycopy(array, 0, newArray, 0, array.length);
395    
396                    return newArray;
397            }
398    
399            public static char[] clone(char[] array, int from, int to) {
400                    char[] newArray = new char[to - from];
401    
402                    System.arraycopy(
403                            array, from, newArray, 0,
404                            Math.min(array.length - from, newArray.length));
405    
406                    return newArray;
407            }
408    
409            public static double[] clone(double[] array) {
410                    double[] newArray = new double[array.length];
411    
412                    System.arraycopy(array, 0, newArray, 0, array.length);
413    
414                    return newArray;
415            }
416    
417            public static double[] clone(double[] array, int from, int to) {
418                    double[] newArray = new double[to - from];
419    
420                    System.arraycopy(
421                            array, from, newArray, 0,
422                            Math.min(array.length - from, newArray.length));
423    
424                    return newArray;
425            }
426    
427            public static float[] clone(float[] array) {
428                    float[] newArray = new float[array.length];
429    
430                    System.arraycopy(array, 0, newArray, 0, array.length);
431    
432                    return newArray;
433            }
434    
435            public static float[] clone(float[] array, int from, int to) {
436                    float[] newArray = new float[to - from];
437    
438                    System.arraycopy(
439                            array, from, newArray, 0,
440                            Math.min(array.length - from, newArray.length));
441    
442                    return newArray;
443            }
444    
445            public static int[] clone(int[] array) {
446                    int[] newArray = new int[array.length];
447    
448                    System.arraycopy(array, 0, newArray, 0, array.length);
449    
450                    return newArray;
451            }
452    
453            public static int[] clone(int[] array, int from, int to) {
454                    int[] newArray = new int[to - from];
455    
456                    System.arraycopy(
457                            array, from, newArray, 0,
458                            Math.min(array.length - from, newArray.length));
459    
460                    return newArray;
461            }
462    
463            public static long[] clone(long[] array) {
464                    long[] newArray = new long[array.length];
465    
466                    System.arraycopy(array, 0, newArray, 0, array.length);
467    
468                    return newArray;
469            }
470    
471            public static long[] clone(long[] array, int from, int to) {
472                    long[] newArray = new long[to - from];
473    
474                    System.arraycopy(
475                            array, from, newArray, 0,
476                            Math.min(array.length - from, newArray.length));
477    
478                    return newArray;
479            }
480    
481            public static short[] clone(short[] array) {
482                    short[] newArray = new short[array.length];
483    
484                    System.arraycopy(array, 0, newArray, 0, array.length);
485    
486                    return newArray;
487            }
488    
489            public static short[] clone(short[] array, int from, int to) {
490                    short[] newArray = new short[to - from];
491    
492                    System.arraycopy(
493                            array, from, newArray, 0,
494                            Math.min(array.length - from, newArray.length));
495    
496                    return newArray;
497            }
498    
499            public static <T> T[] clone(T[] array) {
500                    Class<?> arrayClass = array.getClass();
501    
502                    T[] newArray = (T[])Array.newInstance(
503                            arrayClass.getComponentType(), array.length);
504    
505                    System.arraycopy(array, 0, newArray, 0, array.length);
506    
507                    return newArray;
508            }
509    
510            public static <T> T[] clone(T[] array, int from, int to) {
511                    Class<?> arrayClass = array.getClass();
512    
513                    T[] newArray = (T[])Array.newInstance(
514                            arrayClass.getComponentType(), to - from);
515    
516                    System.arraycopy(
517                            array, from, newArray, 0,
518                            Math.min(array.length - from, newArray.length));
519    
520                    return newArray;
521            }
522    
523            public static <T> T[][] clone(T[][] array) {
524                    Class<?> arrayClass = array.getClass();
525    
526                    T[][] newArray = (T[][])Array.newInstance(
527                            arrayClass.getComponentType(), array.length);
528    
529                    System.arraycopy(array, 0, newArray, 0, array.length);
530    
531                    return newArray;
532            }
533    
534            public static <T> T[][] clone(T[][] array, int from, int to) {
535                    Class<?> arrayClass = array.getClass();
536    
537                    T[][] newArray = (T[][])Array.newInstance(
538                            arrayClass.getComponentType(), to - from);
539    
540                    System.arraycopy(
541                            array, from, newArray, 0,
542                            Math.min(array.length - from, newArray.length));
543    
544                    return newArray;
545            }
546    
547            public static void combine(
548                    Object[] array1, Object[] array2, Object[] combinedArray) {
549    
550                    System.arraycopy(array1, 0, combinedArray, 0, array1.length);
551    
552                    System.arraycopy(
553                            array2, 0, combinedArray, array1.length, array2.length);
554            }
555    
556            public static boolean contains(boolean[] array, boolean value) {
557                    if (isEmpty(array)) {
558                            return false;
559                    }
560    
561                    for (int i = 0; i < array.length; i++) {
562                            if (value == array[i]) {
563                                    return true;
564                            }
565                    }
566    
567                    return false;
568            }
569    
570            public static boolean contains(byte[] array, byte value) {
571                    if (isEmpty(array)) {
572                            return false;
573                    }
574    
575                    for (int i = 0; i < array.length; i++) {
576                            if (value == array[i]) {
577                                    return true;
578                            }
579                    }
580    
581                    return false;
582            }
583    
584            public static boolean contains(char[] array, char value) {
585                    if (isEmpty(array)) {
586                            return false;
587                    }
588    
589                    for (int i = 0; i < array.length; i++) {
590                            if (value == array[i]) {
591                                    return true;
592                            }
593                    }
594    
595                    return false;
596            }
597    
598            public static boolean contains(double[] array, double value) {
599                    if (isEmpty(array)) {
600                            return false;
601                    }
602    
603                    for (int i = 0; i < array.length; i++) {
604                            if (value == array[i]) {
605                                    return true;
606                            }
607                    }
608    
609                    return false;
610            }
611    
612            public static boolean contains(float[] array, float value) {
613                    if (isEmpty(array)) {
614                            return false;
615                    }
616    
617                    for (int i = 0; i < array.length; i++) {
618                            if (value == array[i]) {
619                                    return true;
620                            }
621                    }
622    
623                    return false;
624            }
625    
626            public static boolean contains(int[] array, int value) {
627                    if (isEmpty(array)) {
628                            return false;
629                    }
630    
631                    for (int i = 0; i < array.length; i++) {
632                            if (value == array[i]) {
633                                    return true;
634                            }
635                    }
636    
637                    return false;
638            }
639    
640            public static boolean contains(long[] array, long value) {
641                    if (isEmpty(array)) {
642                            return false;
643                    }
644    
645                    for (int i = 0; i < array.length; i++) {
646                            if (value == array[i]) {
647                                    return true;
648                            }
649                    }
650    
651                    return false;
652            }
653    
654            public static boolean contains(Object[] array, Object value) {
655                    if (isEmpty(array) || (value == null)) {
656                            return false;
657                    }
658    
659                    for (int i = 0; i < array.length; i++) {
660                            if (value.equals(array[i])) {
661                                    return true;
662                            }
663                    }
664    
665                    return false;
666            }
667    
668            public static boolean contains(short[] array, short value) {
669                    if (isEmpty(array)) {
670                            return false;
671                    }
672    
673                    for (int i = 0; i < array.length; i++) {
674                            if (value == array[i]) {
675                                    return true;
676                            }
677                    }
678    
679                    return false;
680            }
681    
682            public static boolean containsAll(boolean[] array1, boolean[] array2) {
683                    if (isEmpty(array1) || isEmpty(array2)) {
684                            return false;
685                    }
686    
687                    for (int i = 0; i < array2.length; i++) {
688                            if (!contains(array1, array2[i])) {
689                                    return false;
690                            }
691                    }
692    
693                    return true;
694            }
695    
696            public static boolean containsAll(byte[] array1, byte[] array2) {
697                    if (isEmpty(array1) || isEmpty(array2)) {
698                            return false;
699                    }
700    
701                    for (int i = 0; i < array2.length; i++) {
702                            if (!contains(array1, array2[i])) {
703                                    return false;
704                            }
705                    }
706    
707                    return true;
708            }
709    
710            public static boolean containsAll(char[] array1, char[] array2) {
711                    if (isEmpty(array1) || isEmpty(array2)) {
712                            return false;
713                    }
714    
715                    for (int i = 0; i < array2.length; i++) {
716                            if (!contains(array1, array2[i])) {
717                                    return false;
718                            }
719                    }
720    
721                    return true;
722            }
723    
724            public static boolean containsAll(double[] array1, double[] array2) {
725                    if (isEmpty(array1) || isEmpty(array2)) {
726                            return false;
727                    }
728    
729                    for (int i = 0; i < array2.length; i++) {
730                            if (!contains(array1, array2[i])) {
731                                    return false;
732                            }
733                    }
734    
735                    return true;
736            }
737    
738            public static boolean containsAll(float[] array1, float[] array2) {
739                    if (isEmpty(array1) || isEmpty(array2)) {
740                            return false;
741                    }
742    
743                    for (int i = 0; i < array2.length; i++) {
744                            if (!contains(array1, array2[i])) {
745                                    return false;
746                            }
747                    }
748    
749                    return true;
750            }
751    
752            public static boolean containsAll(int[] array1, int[] array2) {
753                    if (isEmpty(array1) || isEmpty(array2)) {
754                            return false;
755                    }
756    
757                    for (int i = 0; i < array2.length; i++) {
758                            if (!contains(array1, array2[i])) {
759                                    return false;
760                            }
761                    }
762    
763                    return true;
764            }
765    
766            public static boolean containsAll(long[] array1, long[] array2) {
767                    if (isEmpty(array1) || isEmpty(array2)) {
768                            return false;
769                    }
770    
771                    for (int i = 0; i < array2.length; i++) {
772                            if (!contains(array1, array2[i])) {
773                                    return false;
774                            }
775                    }
776    
777                    return true;
778            }
779    
780            public static boolean containsAll(Object[] array1, Object[] array2) {
781                    if (isEmpty(array1) || isEmpty(array2)) {
782                            return false;
783                    }
784    
785                    for (int i = 0; i < array2.length; i++) {
786                            if (!contains(array1, array2[i])) {
787                                    return false;
788                            }
789                    }
790    
791                    return true;
792            }
793    
794            public static boolean containsAll(short[] array1, short[] array2) {
795                    if (isEmpty(array1) || isEmpty(array2)) {
796                            return false;
797                    }
798    
799                    for (int i = 0; i < array2.length; i++) {
800                            if (!contains(array1, array2[i])) {
801                                    return false;
802                            }
803                    }
804    
805                    return true;
806            }
807    
808            public static String[] distinct(String[] array) {
809                    return distinct(array, null);
810            }
811    
812            public static String[] distinct(
813                    String[] array, Comparator<String> comparator) {
814    
815                    if (isEmpty(array)) {
816                            return array;
817                    }
818    
819                    Set<String> set = null;
820    
821                    if (comparator == null) {
822                            set = new TreeSet<String>();
823                    }
824                    else {
825                            set = new TreeSet<String>(comparator);
826                    }
827    
828                    for (int i = 0; i < array.length; i++) {
829                            String s = array[i];
830    
831                            if (!set.contains(s)) {
832                                    set.add(s);
833                            }
834                    }
835    
836                    return set.toArray(new String[set.size()]);
837            }
838    
839            public static boolean[] filter(
840                    boolean[] array, PredicateFilter<Boolean> predicateFilter) {
841    
842                    if (isEmpty(array)) {
843                            return array;
844                    }
845    
846                    List<Boolean> filteredList = new ArrayList<Boolean>();
847    
848                    for (boolean b : array) {
849                            if (predicateFilter.filter(b)) {
850                                    filteredList.add(b);
851                            }
852                    }
853    
854                    return toArray(filteredList.toArray(new Boolean[filteredList.size()]));
855            }
856    
857            public static byte[] filter(
858                    byte[] array, PredicateFilter<Byte> predicateFilter) {
859    
860                    if (isEmpty(array)) {
861                            return array;
862                    }
863    
864                    List<Byte> filteredList = new ArrayList<Byte>();
865    
866                    for (byte b : array) {
867                            if (predicateFilter.filter(b)) {
868                                    filteredList.add(b);
869                            }
870                    }
871    
872                    return toArray(filteredList.toArray(new Byte[filteredList.size()]));
873            }
874    
875            public static char[] filter(
876                    char[] array, PredicateFilter<Character> predicateFilter) {
877    
878                    if (isEmpty(array)) {
879                            return array;
880                    }
881    
882                    List<Character> filteredList = new ArrayList<Character>();
883    
884                    for (char c : array) {
885                            if (predicateFilter.filter(c)) {
886                                    filteredList.add(c);
887                            }
888                    }
889    
890                    return toArray(
891                            filteredList.toArray(new Character[filteredList.size()]));
892            }
893    
894            public static double[] filter(
895                    double[] array, PredicateFilter<Double> predicateFilter) {
896    
897                    if (isEmpty(array)) {
898                            return array;
899                    }
900    
901                    List<Double> filteredList = new ArrayList<Double>();
902    
903                    for (double d : array) {
904                            if (predicateFilter.filter(d)) {
905                                    filteredList.add(d);
906                            }
907                    }
908    
909                    return toArray(filteredList.toArray(new Double[filteredList.size()]));
910            }
911    
912            public static float[] filter(
913                    float[] array, PredicateFilter<Float> predicateFilter) {
914    
915                    if (isEmpty(array)) {
916                            return array;
917                    }
918    
919                    List<Float> filteredList = new ArrayList<Float>();
920    
921                    for (float f : array) {
922                            if (predicateFilter.filter(f)) {
923                                    filteredList.add(f);
924                            }
925                    }
926    
927                    return toArray(filteredList.toArray(new Float[filteredList.size()]));
928            }
929    
930            public static int[] filter(
931                    int[] array, PredicateFilter<Integer> predicateFilter) {
932    
933                    if (isEmpty(array)) {
934                            return array;
935                    }
936    
937                    List<Integer> filteredList = new ArrayList<Integer>();
938    
939                    for (int i : array) {
940                            if (predicateFilter.filter(i)) {
941                                    filteredList.add(i);
942                            }
943                    }
944    
945                    return toArray(filteredList.toArray(new Integer[filteredList.size()]));
946            }
947    
948            public static long[] filter(
949                    long[] array, PredicateFilter<Long> predicateFilter) {
950    
951                    if (isEmpty(array)) {
952                            return array;
953                    }
954    
955                    List<Long> filteredList = new ArrayList<Long>();
956    
957                    for (long l : array) {
958                            if (predicateFilter.filter(l)) {
959                                    filteredList.add(l);
960                            }
961                    }
962    
963                    return toArray(filteredList.toArray(new Long[filteredList.size()]));
964            }
965    
966            public static short[] filter(
967                    short[] array, PredicateFilter<Short> predicateFilter) {
968    
969                    if (isEmpty(array)) {
970                            return array;
971                    }
972    
973                    List<Short> filteredList = new ArrayList<Short>();
974    
975                    for (short s : array) {
976                            if (predicateFilter.filter(s)) {
977                                    filteredList.add(s);
978                            }
979                    }
980    
981                    return toArray(filteredList.toArray(new Short[filteredList.size()]));
982            }
983    
984            public static <T> T[] filter(
985                    T[] array, PredicateFilter<T> filterPredicate) {
986    
987                    if (isEmpty(array)) {
988                            return array;
989                    }
990    
991                    List<T> filteredList = new ArrayList<T>();
992    
993                    for (T t : array) {
994                            if (filterPredicate.filter(t)) {
995                                    filteredList.add(t);
996                            }
997                    }
998    
999                    Object[] filteredArray = filteredList.toArray();
1000    
1001                    return (T[])Arrays.copyOf(
1002                            filteredArray, filteredArray.length, array.getClass());
1003            }
1004    
1005            public static int getLength(Object[] array) {
1006                    if (array == null) {
1007                            return 0;
1008                    }
1009                    else {
1010                            return array.length;
1011                    }
1012            }
1013    
1014            public static Object getValue(Object[] array, int pos) {
1015                    if ((array == null) || (array.length <= pos)) {
1016                            return null;
1017                    }
1018                    else {
1019                            return array[pos];
1020                    }
1021            }
1022    
1023            public static boolean isEmpty(boolean[] array) {
1024                    if ((array == null) || (array.length == 0)) {
1025                            return true;
1026                    }
1027    
1028                    return false;
1029            }
1030    
1031            public static boolean isEmpty(byte[] array) {
1032                    if ((array == null) || (array.length == 0)) {
1033                            return true;
1034                    }
1035    
1036                    return false;
1037            }
1038    
1039            public static boolean isEmpty(char[] array) {
1040                    if ((array == null) || (array.length == 0)) {
1041                            return true;
1042                    }
1043    
1044                    return false;
1045            }
1046    
1047            public static boolean isEmpty(double[] array) {
1048                    if ((array == null) || (array.length == 0)) {
1049                            return true;
1050                    }
1051    
1052                    return false;
1053            }
1054    
1055            public static boolean isEmpty(float[] array) {
1056                    if ((array == null) || (array.length == 0)) {
1057                            return true;
1058                    }
1059    
1060                    return false;
1061            }
1062    
1063            public static boolean isEmpty(int[] array) {
1064                    if ((array == null) || (array.length == 0)) {
1065                            return true;
1066                    }
1067    
1068                    return false;
1069            }
1070    
1071            public static boolean isEmpty(long[] array) {
1072                    if ((array == null) || (array.length == 0)) {
1073                            return true;
1074                    }
1075    
1076                    return false;
1077            }
1078    
1079            public static boolean isEmpty(Object[] array) {
1080                    if ((array == null) || (array.length == 0)) {
1081                            return true;
1082                    }
1083    
1084                    return false;
1085            }
1086    
1087            public static boolean isEmpty(short[] array) {
1088                    if ((array == null) || (array.length == 0)) {
1089                            return true;
1090                    }
1091    
1092                    return false;
1093            }
1094    
1095            public static boolean isNotEmpty(boolean[] array) {
1096                    return !isEmpty(array);
1097            }
1098    
1099            public static boolean isNotEmpty(byte[] array) {
1100                    return !isEmpty(array);
1101            }
1102    
1103            public static boolean isNotEmpty(char[] array) {
1104                    return !isEmpty(array);
1105            }
1106    
1107            public static boolean isNotEmpty(double[] array) {
1108                    return !isEmpty(array);
1109            }
1110    
1111            public static boolean isNotEmpty(float[] array) {
1112                    return !isEmpty(array);
1113            }
1114    
1115            public static boolean isNotEmpty(int[] array) {
1116                    return !isEmpty(array);
1117            }
1118    
1119            public static boolean isNotEmpty(long[] array) {
1120                    return !isEmpty(array);
1121            }
1122    
1123            public static boolean isNotEmpty(Object[] array) {
1124                    return !isEmpty(array);
1125            }
1126    
1127            public static boolean isNotEmpty(short[] array) {
1128                    return !isEmpty(array);
1129            }
1130    
1131            public static boolean[] remove(boolean[] array, boolean value) {
1132                    List<Boolean> list = new ArrayList<Boolean>();
1133    
1134                    for (int i = 0; i < array.length; i++) {
1135                            if (value != array[i]) {
1136                                    list.add(new Boolean(array[i]));
1137                            }
1138                    }
1139    
1140                    return toArray(list.toArray(new Boolean[list.size()]));
1141            }
1142    
1143            public static byte[] remove(byte[] array, byte value) {
1144                    List<Byte> list = new ArrayList<Byte>();
1145    
1146                    for (int i = 0; i < array.length; i++) {
1147                            if (value != array[i]) {
1148                                    list.add(new Byte(array[i]));
1149                            }
1150                    }
1151    
1152                    return toArray(list.toArray(new Byte[list.size()]));
1153            }
1154    
1155            public static char[] remove(char[] array, char value) {
1156                    List<Character> list = new ArrayList<Character>();
1157    
1158                    for (int i = 0; i < array.length; i++) {
1159                            if (value != array[i]) {
1160                                    list.add(new Character(array[i]));
1161                            }
1162                    }
1163    
1164                    return toArray(list.toArray(new Character[list.size()]));
1165            }
1166    
1167            public static double[] remove(double[] array, double value) {
1168                    List<Double> list = new ArrayList<Double>();
1169    
1170                    for (int i = 0; i < array.length; i++) {
1171                            if (value != array[i]) {
1172                                    list.add(new Double(array[i]));
1173                            }
1174                    }
1175    
1176                    return toArray(list.toArray(new Double[list.size()]));
1177            }
1178    
1179            public static int[] remove(int[] array, int value) {
1180                    List<Integer> list = new ArrayList<Integer>();
1181    
1182                    for (int i = 0; i < array.length; i++) {
1183                            if (value != array[i]) {
1184                                    list.add(new Integer(array[i]));
1185                            }
1186                    }
1187    
1188                    return toArray(list.toArray(new Integer[list.size()]));
1189            }
1190    
1191            public static long[] remove(long[] array, long value) {
1192                    List<Long> list = new ArrayList<Long>();
1193    
1194                    for (int i = 0; i < array.length; i++) {
1195                            if (value != array[i]) {
1196                                    list.add(new Long(array[i]));
1197                            }
1198                    }
1199    
1200                    return toArray(list.toArray(new Long[list.size()]));
1201            }
1202    
1203            public static short[] remove(short[] array, short value) {
1204                    List<Short> list = new ArrayList<Short>();
1205    
1206                    for (int i = 0; i < array.length; i++) {
1207                            if (value != array[i]) {
1208                                    list.add(new Short(array[i]));
1209                            }
1210                    }
1211    
1212                    return toArray(list.toArray(new Short[list.size()]));
1213            }
1214    
1215            public static String[] remove(String[] array, String value) {
1216                    List<String> list = new ArrayList<String>();
1217    
1218                    for (String s : array) {
1219                            if (!s.equals(value)) {
1220                                    list.add(s);
1221                            }
1222                    }
1223    
1224                    return list.toArray(new String[list.size()]);
1225            }
1226    
1227            public static String[] removeByPrefix(String[] array, String prefix) {
1228                    List<String> list = new ArrayList<String>();
1229    
1230                    for (String s : array) {
1231                            if (!s.startsWith(prefix)) {
1232                                    list.add(s);
1233                            }
1234                    }
1235    
1236                    return list.toArray(new String[list.size()]);
1237            }
1238    
1239            public static void reverse(boolean[] array) {
1240                    for (int left = 0, right = array.length - 1; left < right;
1241                                    left++, right--) {
1242    
1243                            boolean value = array[left];
1244    
1245                            array[left] = array[right];
1246                            array[right] = value;
1247                    }
1248            }
1249    
1250            public static void reverse(char[] array) {
1251                    for (int left = 0, right = array.length - 1; left < right;
1252                                    left++, right--) {
1253    
1254                            char value = array[left];
1255    
1256                            array[left] = array[right];
1257                            array[right] = value;
1258                    }
1259            }
1260    
1261            public static void reverse(double[] array) {
1262                    for (int left = 0, right = array.length - 1; left < right;
1263                                    left++, right--) {
1264    
1265                            double value = array[left];
1266    
1267                            array[left] = array[right];
1268                            array[right] = value;
1269                    }
1270            }
1271    
1272            public static void reverse(int[] array) {
1273                    for (int left = 0, right = array.length - 1; left < right;
1274                                    left++, right--) {
1275    
1276                            int value = array[left];
1277    
1278                            array[left] = array[right];
1279                            array[right] = value;
1280                    }
1281            }
1282    
1283            public static void reverse(long[] array) {
1284                    for (int left = 0, right = array.length - 1; left < right;
1285                                    left++, right--) {
1286    
1287                            long value = array[left];
1288    
1289                            array[left] = array[right];
1290                            array[right] = value;
1291                    }
1292            }
1293    
1294            public static void reverse(short[] array) {
1295                    for (int left = 0, right = array.length - 1; left < right;
1296                                    left++, right--) {
1297    
1298                            short value = array[left];
1299    
1300                            array[left] = array[right];
1301                            array[right] = value;
1302                    }
1303            }
1304    
1305            public static void reverse(String[] array) {
1306                    for (int left = 0, right = array.length - 1; left < right;
1307                                    left++, right--) {
1308    
1309                            String value = array[left];
1310    
1311                            array[left] = array[right];
1312                            array[right] = value;
1313                    }
1314            }
1315    
1316            public static boolean[] subset(boolean[] array, int start, int end) {
1317                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1318                            return array;
1319                    }
1320    
1321                    boolean[] newArray = new boolean[end - start];
1322    
1323                    System.arraycopy(array, start, newArray, 0, end - start);
1324    
1325                    return newArray;
1326            }
1327    
1328            public static byte[] subset(byte[] array, int start, int end) {
1329                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1330                            return array;
1331                    }
1332    
1333                    byte[] newArray = new byte[end - start];
1334    
1335                    System.arraycopy(array, start, newArray, 0, end - start);
1336    
1337                    return newArray;
1338            }
1339    
1340            public static char[] subset(char[] array, int start, int end) {
1341                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1342                            return array;
1343                    }
1344    
1345                    char[] newArray = new char[end - start];
1346    
1347                    System.arraycopy(array, start, newArray, 0, end - start);
1348    
1349                    return newArray;
1350            }
1351    
1352            public static double[] subset(double[] array, int start, int end) {
1353                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1354                            return array;
1355                    }
1356    
1357                    double[] newArray = new double[end - start];
1358    
1359                    System.arraycopy(array, start, newArray, 0, end - start);
1360    
1361                    return newArray;
1362            }
1363    
1364            public static float[] subset(float[] array, int start, int end) {
1365                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1366                            return array;
1367                    }
1368    
1369                    float[] newArray = new float[end - start];
1370    
1371                    System.arraycopy(array, start, newArray, 0, end - start);
1372    
1373                    return newArray;
1374            }
1375    
1376            public static int[] subset(int[] array, int start, int end) {
1377                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1378                            return array;
1379                    }
1380    
1381                    int[] newArray = new int[end - start];
1382    
1383                    System.arraycopy(array, start, newArray, 0, end - start);
1384    
1385                    return newArray;
1386            }
1387    
1388            public static long[] subset(long[] array, int start, int end) {
1389                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1390                            return array;
1391                    }
1392    
1393                    long[] newArray = new long[end - start];
1394    
1395                    System.arraycopy(array, start, newArray, 0, end - start);
1396    
1397                    return newArray;
1398            }
1399    
1400            public static short[] subset(short[] array, int start, int end) {
1401                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1402                            return array;
1403                    }
1404    
1405                    short[] newArray = new short[end - start];
1406    
1407                    System.arraycopy(array, start, newArray, 0, end - start);
1408    
1409                    return newArray;
1410            }
1411    
1412            public static <T> T[] subset(T[] array, int start, int end) {
1413                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1414                            return array;
1415                    }
1416    
1417                    Class<?> arrayClass = array.getClass();
1418    
1419                    T[] newArray = (T[])Array.newInstance(
1420                            arrayClass.getComponentType(), end - start);
1421    
1422                    System.arraycopy(array, start, newArray, 0, end - start);
1423    
1424                    return newArray;
1425            }
1426    
1427            public static Boolean[] toArray(boolean[] array) {
1428                    Boolean[] newArray = new Boolean[array.length];
1429    
1430                    for (int i = 0; i < array.length; i++) {
1431                            newArray[i] = Boolean.valueOf(array[i]);
1432                    }
1433    
1434                    return newArray;
1435            }
1436    
1437            public static boolean[] toArray(Boolean[] array) {
1438                    boolean[] newArray = new boolean[array.length];
1439    
1440                    for (int i = 0; i < array.length; i++) {
1441                            newArray[i] = array[i].booleanValue();
1442                    }
1443    
1444                    return newArray;
1445            }
1446    
1447            public static Byte[] toArray(byte[] array) {
1448                    Byte[] newArray = new Byte[array.length];
1449    
1450                    for (int i = 0; i < array.length; i++) {
1451                            newArray[i] = Byte.valueOf(array[i]);
1452                    }
1453    
1454                    return newArray;
1455            }
1456    
1457            public static byte[] toArray(Byte[] array) {
1458                    byte[] newArray = new byte[array.length];
1459    
1460                    for (int i = 0; i < array.length; i++) {
1461                            newArray[i] = array[i].byteValue();
1462                    }
1463    
1464                    return newArray;
1465            }
1466    
1467            public static Character[] toArray(char[] array) {
1468                    Character[] newArray = new Character[array.length];
1469    
1470                    for (int i = 0; i < array.length; i++) {
1471                            newArray[i] = Character.valueOf(array[i]);
1472                    }
1473    
1474                    return newArray;
1475            }
1476    
1477            public static char[] toArray(Character[] array) {
1478                    char[] newArray = new char[array.length];
1479    
1480                    for (int i = 0; i < array.length; i++) {
1481                            newArray[i] = array[i].charValue();
1482                    }
1483    
1484                    return newArray;
1485            }
1486    
1487            public static Double[] toArray(double[] array) {
1488                    Double[] newArray = new Double[array.length];
1489    
1490                    for (int i = 0; i < array.length; i++) {
1491                            newArray[i] = new Double(array[i]);
1492                    }
1493    
1494                    return newArray;
1495            }
1496    
1497            public static double[] toArray(Double[] array) {
1498                    double[] newArray = new double[array.length];
1499    
1500                    for (int i = 0; i < array.length; i++) {
1501                            newArray[i] = array[i].doubleValue();
1502                    }
1503    
1504                    return newArray;
1505            }
1506    
1507            public static Float[] toArray(float[] array) {
1508                    Float[] newArray = new Float[array.length];
1509    
1510                    for (int i = 0; i < array.length; i++) {
1511                            newArray[i] = new Float(array[i]);
1512                    }
1513    
1514                    return newArray;
1515            }
1516    
1517            public static float[] toArray(Float[] array) {
1518                    float[] newArray = new float[array.length];
1519    
1520                    for (int i = 0; i < array.length; i++) {
1521                            newArray[i] = array[i].floatValue();
1522                    }
1523    
1524                    return newArray;
1525            }
1526    
1527            public static Integer[] toArray(int[] array) {
1528                    Integer[] newArray = new Integer[array.length];
1529    
1530                    for (int i = 0; i < array.length; i++) {
1531                            newArray[i] = new Integer(array[i]);
1532                    }
1533    
1534                    return newArray;
1535            }
1536    
1537            public static int[] toArray(Integer[] array) {
1538                    int[] newArray = new int[array.length];
1539    
1540                    for (int i = 0; i < array.length; i++) {
1541                            newArray[i] = array[i].intValue();
1542                    }
1543    
1544                    return newArray;
1545            }
1546    
1547            public static Long[] toArray(long[] array) {
1548                    Long[] newArray = new Long[array.length];
1549    
1550                    for (int i = 0; i < array.length; i++) {
1551                            newArray[i] = new Long(array[i]);
1552                    }
1553    
1554                    return newArray;
1555            }
1556    
1557            public static long[] toArray(Long[] array) {
1558                    long[] newArray = new long[array.length];
1559    
1560                    for (int i = 0; i < array.length; i++) {
1561                            newArray[i] = array[i].longValue();
1562                    }
1563    
1564                    return newArray;
1565            }
1566    
1567            public static Short[] toArray(short[] array) {
1568                    Short[] newArray = new Short[array.length];
1569    
1570                    for (int i = 0; i < array.length; i++) {
1571                            newArray[i] = new Short(array[i]);
1572                    }
1573    
1574                    return newArray;
1575            }
1576    
1577            public static short[] toArray(Short[] array) {
1578                    short[] newArray = new short[array.length];
1579    
1580                    for (int i = 0; i < array.length; i++) {
1581                            newArray[i] = array[i].shortValue();
1582                    }
1583    
1584                    return newArray;
1585            }
1586    
1587            public static double[] toDoubleArray(Collection<Double> collection) {
1588                    double[] newArray = new double[collection.size()];
1589    
1590                    if (collection instanceof List) {
1591                            List<Double> list = (List<Double>)collection;
1592    
1593                            for (int i = 0; i < list.size(); i++) {
1594                                    Double value = list.get(i);
1595    
1596                                    newArray[i] = value.doubleValue();
1597                            }
1598                    }
1599                    else {
1600                            int i = 0;
1601    
1602                            Iterator<Double> iterator = collection.iterator();
1603    
1604                            while (iterator.hasNext()) {
1605                                    Double value = iterator.next();
1606    
1607                                    newArray[i++] = value.doubleValue();
1608                            }
1609                    }
1610    
1611                    return newArray;
1612            }
1613    
1614            public static float[] toFloatArray(Collection<Float> collection) {
1615                    float[] newArray = new float[collection.size()];
1616    
1617                    if (collection instanceof List) {
1618                            List<Float> list = (List<Float>)collection;
1619    
1620                            for (int i = 0; i < list.size(); i++) {
1621                                    Float value = list.get(i);
1622    
1623                                    newArray[i] = value.floatValue();
1624                            }
1625                    }
1626                    else {
1627                            int i = 0;
1628    
1629                            Iterator<Float> iterator = collection.iterator();
1630    
1631                            while (iterator.hasNext()) {
1632                                    Float value = iterator.next();
1633    
1634                                    newArray[i++] = value.floatValue();
1635                            }
1636                    }
1637    
1638                    return newArray;
1639            }
1640    
1641            public static int[] toIntArray(Collection<Integer> collection) {
1642                    int[] newArray = new int[collection.size()];
1643    
1644                    if (collection instanceof List) {
1645                            List<Integer> list = (List<Integer>)collection;
1646    
1647                            for (int i = 0; i < list.size(); i++) {
1648                                    Integer value = list.get(i);
1649    
1650                                    newArray[i] = value.intValue();
1651                            }
1652                    }
1653                    else {
1654                            int i = 0;
1655    
1656                            Iterator<Integer> iterator = collection.iterator();
1657    
1658                            while (iterator.hasNext()) {
1659                                    Integer value = iterator.next();
1660    
1661                                    newArray[i++] = value.intValue();
1662                            }
1663                    }
1664    
1665                    return newArray;
1666            }
1667    
1668            public static long[] toLongArray(Collection<Long> collection) {
1669                    long[] newArray = new long[collection.size()];
1670    
1671                    if (collection instanceof List) {
1672                            List<Long> list = (List<Long>)collection;
1673    
1674                            for (int i = 0; i < list.size(); i++) {
1675                                    Long value = list.get(i);
1676    
1677                                    newArray[i] = value.longValue();
1678                            }
1679                    }
1680                    else {
1681                            int i = 0;
1682    
1683                            Iterator<Long> iterator = collection.iterator();
1684    
1685                            while (iterator.hasNext()) {
1686                                    Long value = iterator.next();
1687    
1688                                    newArray[i++] = value.longValue();
1689                            }
1690                    }
1691    
1692                    return newArray;
1693            }
1694    
1695            public static Long[] toLongArray(Object[] array) {
1696                    Long[] newArray = new Long[array.length];
1697    
1698                    for (int i = 0; i < array.length; i++) {
1699                            newArray[i] = (Long)array[i];
1700                    }
1701    
1702                    return newArray;
1703            }
1704    
1705            public static short[] toShortArray(Collection<Short> collection) {
1706                    short[] newArray = new short[collection.size()];
1707    
1708                    if (collection instanceof List) {
1709                            List<Short> list = (List<Short>)collection;
1710    
1711                            for (int i = 0; i < list.size(); i++) {
1712                                    Short value = list.get(i);
1713    
1714                                    newArray[i] = value.shortValue();
1715                            }
1716                    }
1717                    else {
1718                            int i = 0;
1719    
1720                            Iterator<Short> iterator = collection.iterator();
1721    
1722                            while (iterator.hasNext()) {
1723                                    Short value = iterator.next();
1724    
1725                                    newArray[i++] = value.shortValue();
1726                            }
1727                    }
1728    
1729                    return newArray;
1730            }
1731    
1732            /**
1733             * @see ListUtil#toString(List, String)
1734             */
1735            public static String toString(Object[] array, String param) {
1736                    return toString(array, param, StringPool.COMMA);
1737            }
1738    
1739            /**
1740             * @see ListUtil#toString(List, String, String)
1741             */
1742            public static String toString(
1743                    Object[] array, String param, String delimiter) {
1744    
1745                    return toString(array, param, delimiter, null);
1746            }
1747    
1748            public static String toString(
1749                    Object[] array, String param, String delimiter, Locale locale) {
1750    
1751                    if (isEmpty(array)) {
1752                            return StringPool.BLANK;
1753                    }
1754    
1755                    StringBundler sb = new StringBundler(2 * array.length - 1);
1756    
1757                    for (int i = 0; i < array.length; i++) {
1758                            Object bean = array[i];
1759    
1760                            Object value = BeanPropertiesUtil.getObject(bean, param);
1761    
1762                            if (value != null) {
1763                                    if (locale != null) {
1764                                            sb.append(LanguageUtil.get(locale, value.toString()));
1765                                    }
1766                                    else {
1767                                            sb.append(value);
1768                                    }
1769                            }
1770    
1771                            if ((i + 1) != array.length) {
1772                                    sb.append(delimiter);
1773                            }
1774                    }
1775    
1776                    return sb.toString();
1777            }
1778    
1779            /**
1780             * @see ListUtil#toString(List, Accessor)
1781             */
1782            public static <T, V> String toString(T[] list, Accessor<T, V> accessor) {
1783                    return toString(list, accessor, StringPool.COMMA);
1784            }
1785    
1786            /**
1787             * @see ListUtil#toString(List, Accessor, String)
1788             */
1789            public static <T, V> String toString(
1790                    T[] list, Accessor<T, V> accessor, String delimiter) {
1791    
1792                    return toString(list, accessor, delimiter, null);
1793            }
1794    
1795            public static <T, V> String toString(
1796                    T[] list, Accessor<T, V> accessor, String delimiter, Locale locale) {
1797    
1798                    if (isEmpty(list)) {
1799                            return StringPool.BLANK;
1800                    }
1801    
1802                    StringBundler sb = new StringBundler(2 * list.length - 1);
1803    
1804                    for (int i = 0; i < list.length; i++) {
1805                            T bean = list[i];
1806    
1807                            V value = accessor.get(bean);
1808    
1809                            if (value != null) {
1810                                    if (locale != null) {
1811                                            sb.append(LanguageUtil.get(locale, value.toString()));
1812                                    }
1813                                    else {
1814                                            sb.append(value);
1815                                    }
1816                            }
1817    
1818                            if ((i + 1) != list.length) {
1819                                    sb.append(delimiter);
1820                            }
1821                    }
1822    
1823                    return sb.toString();
1824            }
1825    
1826            public static String[] toStringArray(boolean[] array) {
1827                    String[] newArray = new String[array.length];
1828    
1829                    for (int i = 0; i < array.length; i++) {
1830                            newArray[i] = String.valueOf(array[i]);
1831                    }
1832    
1833                    return newArray;
1834            }
1835    
1836            public static String[] toStringArray(byte[] array) {
1837                    String[] newArray = new String[array.length];
1838    
1839                    for (int i = 0; i < array.length; i++) {
1840                            newArray[i] = String.valueOf(array[i]);
1841                    }
1842    
1843                    return newArray;
1844            }
1845    
1846            public static String[] toStringArray(char[] array) {
1847                    String[] newArray = new String[array.length];
1848    
1849                    for (int i = 0; i < array.length; i++) {
1850                            newArray[i] = String.valueOf(array[i]);
1851                    }
1852    
1853                    return newArray;
1854            }
1855    
1856            public static String[] toStringArray(Date[] array, DateFormat dateFormat) {
1857                    String[] newArray = new String[array.length];
1858    
1859                    for (int i = 0; i < array.length; i++) {
1860                            newArray[i] = dateFormat.format(array[i]);
1861                    }
1862    
1863                    return newArray;
1864            }
1865    
1866            public static String[] toStringArray(double[] array) {
1867                    String[] newArray = new String[array.length];
1868    
1869                    for (int i = 0; i < array.length; i++) {
1870                            newArray[i] = String.valueOf(array[i]);
1871                    }
1872    
1873                    return newArray;
1874            }
1875    
1876            public static String[] toStringArray(float[] array) {
1877                    String[] newArray = new String[array.length];
1878    
1879                    for (int i = 0; i < array.length; i++) {
1880                            newArray[i] = String.valueOf(array[i]);
1881                    }
1882    
1883                    return newArray;
1884            }
1885    
1886            public static String[] toStringArray(int[] array) {
1887                    String[] newArray = new String[array.length];
1888    
1889                    for (int i = 0; i < array.length; i++) {
1890                            newArray[i] = String.valueOf(array[i]);
1891                    }
1892    
1893                    return newArray;
1894            }
1895    
1896            public static String[] toStringArray(JSONArray array) {
1897                    String[] newArray = new String[array.length()];
1898    
1899                    for (int i = 0; i < array.length(); i++) {
1900                            newArray[i] = array.getString(i);
1901                    }
1902    
1903                    return newArray;
1904            }
1905    
1906            public static String[] toStringArray(long[] array) {
1907                    String[] newArray = new String[array.length];
1908    
1909                    for (int i = 0; i < array.length; i++) {
1910                            newArray[i] = String.valueOf(array[i]);
1911                    }
1912    
1913                    return newArray;
1914            }
1915    
1916            public static String[] toStringArray(Object[] array) {
1917                    String[] newArray = new String[array.length];
1918    
1919                    for (int i = 0; i < array.length; i++) {
1920                            newArray[i] = String.valueOf(array[i]);
1921                    }
1922    
1923                    return newArray;
1924            }
1925    
1926            public static String[] toStringArray(short[] array) {
1927                    String[] newArray = new String[array.length];
1928    
1929                    for (int i = 0; i < array.length; i++) {
1930                            newArray[i] = String.valueOf(array[i]);
1931                    }
1932    
1933                    return newArray;
1934            }
1935    
1936            public static byte[] unique(byte[] array) {
1937                    List<Byte> list = new UniqueList<Byte>();
1938    
1939                    for (int i = 0; i < array.length; i++) {
1940                            list.add(array[i]);
1941                    }
1942    
1943                    return toArray(list.toArray(new Byte[list.size()]));
1944            }
1945    
1946            public static double[] unique(double[] array) {
1947                    List<Double> list = new UniqueList<Double>();
1948    
1949                    for (int i = 0; i < array.length; i++) {
1950                            list.add(array[i]);
1951                    }
1952    
1953                    return toArray(list.toArray(new Double[list.size()]));
1954            }
1955    
1956            public static float[] unique(float[] array) {
1957                    List<Float> list = new UniqueList<Float>();
1958    
1959                    for (int i = 0; i < array.length; i++) {
1960                            list.add(array[i]);
1961                    }
1962    
1963                    return toArray(list.toArray(new Float[list.size()]));
1964            }
1965    
1966            public static int[] unique(int[] array) {
1967                    List<Integer> list = new UniqueList<Integer>();
1968    
1969                    for (int i = 0; i < array.length; i++) {
1970                            list.add(array[i]);
1971                    }
1972    
1973                    return toArray(list.toArray(new Integer[list.size()]));
1974            }
1975    
1976            public static long[] unique(long[] array) {
1977                    List<Long> list = new UniqueList<Long>();
1978    
1979                    for (int i = 0; i < array.length; i++) {
1980                            list.add(array[i]);
1981                    }
1982    
1983                    return toArray(list.toArray(new Long[list.size()]));
1984            }
1985    
1986            public static short[] unique(short[] array) {
1987                    List<Short> list = new UniqueList<Short>();
1988    
1989                    for (int i = 0; i < array.length; i++) {
1990                            list.add(array[i]);
1991                    }
1992    
1993                    return toArray(list.toArray(new Short[list.size()]));
1994            }
1995    
1996    }