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