001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 contains(
683                    String[] array, String value, boolean ignoreCase) {
684    
685                    if (isEmpty(array)) {
686                            return false;
687                    }
688    
689                    for (int i = 0; i < array.length; i++) {
690                            if (ignoreCase) {
691                                    if (StringUtil.equalsIgnoreCase(array[i], value )) {
692                                            return true;
693                                    }
694                            }
695                            else {
696                                    if (array[i].equals(value)) {
697                                            return true;
698                                    }
699                            }
700                    }
701    
702                    return false;
703            }
704    
705            public static boolean containsAll(boolean[] array1, boolean[] array2) {
706                    if (isEmpty(array1) || isEmpty(array2)) {
707                            return false;
708                    }
709    
710                    for (int i = 0; i < array2.length; i++) {
711                            if (!contains(array1, array2[i])) {
712                                    return false;
713                            }
714                    }
715    
716                    return true;
717            }
718    
719            public static boolean containsAll(byte[] array1, byte[] array2) {
720                    if (isEmpty(array1) || isEmpty(array2)) {
721                            return false;
722                    }
723    
724                    for (int i = 0; i < array2.length; i++) {
725                            if (!contains(array1, array2[i])) {
726                                    return false;
727                            }
728                    }
729    
730                    return true;
731            }
732    
733            public static boolean containsAll(char[] array1, char[] array2) {
734                    if (isEmpty(array1) || isEmpty(array2)) {
735                            return false;
736                    }
737    
738                    for (int i = 0; i < array2.length; i++) {
739                            if (!contains(array1, array2[i])) {
740                                    return false;
741                            }
742                    }
743    
744                    return true;
745            }
746    
747            public static boolean containsAll(double[] array1, double[] array2) {
748                    if (isEmpty(array1) || isEmpty(array2)) {
749                            return false;
750                    }
751    
752                    for (int i = 0; i < array2.length; i++) {
753                            if (!contains(array1, array2[i])) {
754                                    return false;
755                            }
756                    }
757    
758                    return true;
759            }
760    
761            public static boolean containsAll(float[] array1, float[] array2) {
762                    if (isEmpty(array1) || isEmpty(array2)) {
763                            return false;
764                    }
765    
766                    for (int i = 0; i < array2.length; i++) {
767                            if (!contains(array1, array2[i])) {
768                                    return false;
769                            }
770                    }
771    
772                    return true;
773            }
774    
775            public static boolean containsAll(int[] array1, int[] array2) {
776                    if (isEmpty(array1) || isEmpty(array2)) {
777                            return false;
778                    }
779    
780                    for (int i = 0; i < array2.length; i++) {
781                            if (!contains(array1, array2[i])) {
782                                    return false;
783                            }
784                    }
785    
786                    return true;
787            }
788    
789            public static boolean containsAll(long[] array1, long[] array2) {
790                    if (isEmpty(array1) || isEmpty(array2)) {
791                            return false;
792                    }
793    
794                    for (int i = 0; i < array2.length; i++) {
795                            if (!contains(array1, array2[i])) {
796                                    return false;
797                            }
798                    }
799    
800                    return true;
801            }
802    
803            public static boolean containsAll(Object[] array1, Object[] array2) {
804                    if (isEmpty(array1) || isEmpty(array2)) {
805                            return false;
806                    }
807    
808                    for (int i = 0; i < array2.length; i++) {
809                            if (!contains(array1, array2[i])) {
810                                    return false;
811                            }
812                    }
813    
814                    return true;
815            }
816    
817            public static boolean containsAll(short[] array1, short[] array2) {
818                    if (isEmpty(array1) || isEmpty(array2)) {
819                            return false;
820                    }
821    
822                    for (int i = 0; i < array2.length; i++) {
823                            if (!contains(array1, array2[i])) {
824                                    return false;
825                            }
826                    }
827    
828                    return true;
829            }
830    
831            public static String[] distinct(String[] array) {
832                    return distinct(array, null);
833            }
834    
835            public static String[] distinct(
836                    String[] array, Comparator<String> comparator) {
837    
838                    if (isEmpty(array)) {
839                            return array;
840                    }
841    
842                    Set<String> set = null;
843    
844                    if (comparator == null) {
845                            set = new TreeSet<String>();
846                    }
847                    else {
848                            set = new TreeSet<String>(comparator);
849                    }
850    
851                    for (int i = 0; i < array.length; i++) {
852                            String s = array[i];
853    
854                            if (!set.contains(s)) {
855                                    set.add(s);
856                            }
857                    }
858    
859                    return set.toArray(new String[set.size()]);
860            }
861    
862            public static boolean[] filter(
863                    boolean[] array, PredicateFilter<Boolean> predicateFilter) {
864    
865                    if (isEmpty(array)) {
866                            return array;
867                    }
868    
869                    List<Boolean> filteredList = new ArrayList<Boolean>();
870    
871                    for (boolean b : array) {
872                            if (predicateFilter.filter(b)) {
873                                    filteredList.add(b);
874                            }
875                    }
876    
877                    return toArray(filteredList.toArray(new Boolean[filteredList.size()]));
878            }
879    
880            public static byte[] filter(
881                    byte[] array, PredicateFilter<Byte> predicateFilter) {
882    
883                    if (isEmpty(array)) {
884                            return array;
885                    }
886    
887                    List<Byte> filteredList = new ArrayList<Byte>();
888    
889                    for (byte b : array) {
890                            if (predicateFilter.filter(b)) {
891                                    filteredList.add(b);
892                            }
893                    }
894    
895                    return toArray(filteredList.toArray(new Byte[filteredList.size()]));
896            }
897    
898            public static char[] filter(
899                    char[] array, PredicateFilter<Character> predicateFilter) {
900    
901                    if (isEmpty(array)) {
902                            return array;
903                    }
904    
905                    List<Character> filteredList = new ArrayList<Character>();
906    
907                    for (char c : array) {
908                            if (predicateFilter.filter(c)) {
909                                    filteredList.add(c);
910                            }
911                    }
912    
913                    return toArray(
914                            filteredList.toArray(new Character[filteredList.size()]));
915            }
916    
917            public static double[] filter(
918                    double[] array, PredicateFilter<Double> predicateFilter) {
919    
920                    if (isEmpty(array)) {
921                            return array;
922                    }
923    
924                    List<Double> filteredList = new ArrayList<Double>();
925    
926                    for (double d : array) {
927                            if (predicateFilter.filter(d)) {
928                                    filteredList.add(d);
929                            }
930                    }
931    
932                    return toArray(filteredList.toArray(new Double[filteredList.size()]));
933            }
934    
935            public static float[] filter(
936                    float[] array, PredicateFilter<Float> predicateFilter) {
937    
938                    if (isEmpty(array)) {
939                            return array;
940                    }
941    
942                    List<Float> filteredList = new ArrayList<Float>();
943    
944                    for (float f : array) {
945                            if (predicateFilter.filter(f)) {
946                                    filteredList.add(f);
947                            }
948                    }
949    
950                    return toArray(filteredList.toArray(new Float[filteredList.size()]));
951            }
952    
953            public static int[] filter(
954                    int[] array, PredicateFilter<Integer> predicateFilter) {
955    
956                    if (isEmpty(array)) {
957                            return array;
958                    }
959    
960                    List<Integer> filteredList = new ArrayList<Integer>();
961    
962                    for (int i : array) {
963                            if (predicateFilter.filter(i)) {
964                                    filteredList.add(i);
965                            }
966                    }
967    
968                    return toArray(filteredList.toArray(new Integer[filteredList.size()]));
969            }
970    
971            public static long[] filter(
972                    long[] array, PredicateFilter<Long> predicateFilter) {
973    
974                    if (isEmpty(array)) {
975                            return array;
976                    }
977    
978                    List<Long> filteredList = new ArrayList<Long>();
979    
980                    for (long l : array) {
981                            if (predicateFilter.filter(l)) {
982                                    filteredList.add(l);
983                            }
984                    }
985    
986                    return toArray(filteredList.toArray(new Long[filteredList.size()]));
987            }
988    
989            public static short[] filter(
990                    short[] array, PredicateFilter<Short> predicateFilter) {
991    
992                    if (isEmpty(array)) {
993                            return array;
994                    }
995    
996                    List<Short> filteredList = new ArrayList<Short>();
997    
998                    for (short s : array) {
999                            if (predicateFilter.filter(s)) {
1000                                    filteredList.add(s);
1001                            }
1002                    }
1003    
1004                    return toArray(filteredList.toArray(new Short[filteredList.size()]));
1005            }
1006    
1007            public static <T> T[] filter(
1008                    T[] array, PredicateFilter<T> filterPredicate) {
1009    
1010                    if (isEmpty(array)) {
1011                            return array;
1012                    }
1013    
1014                    List<T> filteredList = new ArrayList<T>();
1015    
1016                    for (T t : array) {
1017                            if (filterPredicate.filter(t)) {
1018                                    filteredList.add(t);
1019                            }
1020                    }
1021    
1022                    Object[] filteredArray = filteredList.toArray();
1023    
1024                    return (T[])Arrays.copyOf(
1025                            filteredArray, filteredArray.length, array.getClass());
1026            }
1027    
1028            public static int getLength(Object[] array) {
1029                    if (array == null) {
1030                            return 0;
1031                    }
1032                    else {
1033                            return array.length;
1034                    }
1035            }
1036    
1037            public static Object getValue(Object[] array, int pos) {
1038                    if ((array == null) || (array.length <= pos)) {
1039                            return null;
1040                    }
1041                    else {
1042                            return array[pos];
1043                    }
1044            }
1045    
1046            public static boolean isEmpty(boolean[] array) {
1047                    if ((array == null) || (array.length == 0)) {
1048                            return true;
1049                    }
1050    
1051                    return false;
1052            }
1053    
1054            public static boolean isEmpty(byte[] array) {
1055                    if ((array == null) || (array.length == 0)) {
1056                            return true;
1057                    }
1058    
1059                    return false;
1060            }
1061    
1062            public static boolean isEmpty(char[] array) {
1063                    if ((array == null) || (array.length == 0)) {
1064                            return true;
1065                    }
1066    
1067                    return false;
1068            }
1069    
1070            public static boolean isEmpty(double[] array) {
1071                    if ((array == null) || (array.length == 0)) {
1072                            return true;
1073                    }
1074    
1075                    return false;
1076            }
1077    
1078            public static boolean isEmpty(float[] array) {
1079                    if ((array == null) || (array.length == 0)) {
1080                            return true;
1081                    }
1082    
1083                    return false;
1084            }
1085    
1086            public static boolean isEmpty(int[] array) {
1087                    if ((array == null) || (array.length == 0)) {
1088                            return true;
1089                    }
1090    
1091                    return false;
1092            }
1093    
1094            public static boolean isEmpty(long[] array) {
1095                    if ((array == null) || (array.length == 0)) {
1096                            return true;
1097                    }
1098    
1099                    return false;
1100            }
1101    
1102            public static boolean isEmpty(Object[] array) {
1103                    if ((array == null) || (array.length == 0)) {
1104                            return true;
1105                    }
1106    
1107                    return false;
1108            }
1109    
1110            public static boolean isEmpty(short[] array) {
1111                    if ((array == null) || (array.length == 0)) {
1112                            return true;
1113                    }
1114    
1115                    return false;
1116            }
1117    
1118            public static boolean isNotEmpty(boolean[] array) {
1119                    return !isEmpty(array);
1120            }
1121    
1122            public static boolean isNotEmpty(byte[] array) {
1123                    return !isEmpty(array);
1124            }
1125    
1126            public static boolean isNotEmpty(char[] array) {
1127                    return !isEmpty(array);
1128            }
1129    
1130            public static boolean isNotEmpty(double[] array) {
1131                    return !isEmpty(array);
1132            }
1133    
1134            public static boolean isNotEmpty(float[] array) {
1135                    return !isEmpty(array);
1136            }
1137    
1138            public static boolean isNotEmpty(int[] array) {
1139                    return !isEmpty(array);
1140            }
1141    
1142            public static boolean isNotEmpty(long[] array) {
1143                    return !isEmpty(array);
1144            }
1145    
1146            public static boolean isNotEmpty(Object[] array) {
1147                    return !isEmpty(array);
1148            }
1149    
1150            public static boolean isNotEmpty(short[] array) {
1151                    return !isEmpty(array);
1152            }
1153    
1154            public static boolean[] remove(boolean[] array, boolean value) {
1155                    List<Boolean> list = new ArrayList<Boolean>();
1156    
1157                    for (int i = 0; i < array.length; i++) {
1158                            if (value != array[i]) {
1159                                    list.add(new Boolean(array[i]));
1160                            }
1161                    }
1162    
1163                    return toArray(list.toArray(new Boolean[list.size()]));
1164            }
1165    
1166            public static byte[] remove(byte[] array, byte value) {
1167                    List<Byte> list = new ArrayList<Byte>();
1168    
1169                    for (int i = 0; i < array.length; i++) {
1170                            if (value != array[i]) {
1171                                    list.add(new Byte(array[i]));
1172                            }
1173                    }
1174    
1175                    return toArray(list.toArray(new Byte[list.size()]));
1176            }
1177    
1178            public static char[] remove(char[] array, char value) {
1179                    List<Character> list = new ArrayList<Character>();
1180    
1181                    for (int i = 0; i < array.length; i++) {
1182                            if (value != array[i]) {
1183                                    list.add(new Character(array[i]));
1184                            }
1185                    }
1186    
1187                    return toArray(list.toArray(new Character[list.size()]));
1188            }
1189    
1190            public static double[] remove(double[] array, double value) {
1191                    List<Double> list = new ArrayList<Double>();
1192    
1193                    for (int i = 0; i < array.length; i++) {
1194                            if (value != array[i]) {
1195                                    list.add(new Double(array[i]));
1196                            }
1197                    }
1198    
1199                    return toArray(list.toArray(new Double[list.size()]));
1200            }
1201    
1202            public static float[] remove(float[] array, float value) {
1203                    List<Float> list = new ArrayList<Float>();
1204    
1205                    for (int i = 0; i < array.length; i++) {
1206                            if (value != array[i]) {
1207                                    list.add(new Float(array[i]));
1208                            }
1209                    }
1210    
1211                    return toArray(list.toArray(new Float[list.size()]));
1212            }
1213    
1214            public static int[] remove(int[] array, int value) {
1215                    List<Integer> list = new ArrayList<Integer>();
1216    
1217                    for (int i = 0; i < array.length; i++) {
1218                            if (value != array[i]) {
1219                                    list.add(new Integer(array[i]));
1220                            }
1221                    }
1222    
1223                    return toArray(list.toArray(new Integer[list.size()]));
1224            }
1225    
1226            public static long[] remove(long[] array, long value) {
1227                    List<Long> list = new ArrayList<Long>();
1228    
1229                    for (int i = 0; i < array.length; i++) {
1230                            if (value != array[i]) {
1231                                    list.add(new Long(array[i]));
1232                            }
1233                    }
1234    
1235                    return toArray(list.toArray(new Long[list.size()]));
1236            }
1237    
1238            public static short[] remove(short[] array, short value) {
1239                    List<Short> list = new ArrayList<Short>();
1240    
1241                    for (int i = 0; i < array.length; i++) {
1242                            if (value != array[i]) {
1243                                    list.add(new Short(array[i]));
1244                            }
1245                    }
1246    
1247                    return toArray(list.toArray(new Short[list.size()]));
1248            }
1249    
1250            public static String[] remove(String[] array, String value) {
1251                    List<String> list = new ArrayList<String>();
1252    
1253                    for (String s : array) {
1254                            if (!s.equals(value)) {
1255                                    list.add(s);
1256                            }
1257                    }
1258    
1259                    return list.toArray(new String[list.size()]);
1260            }
1261    
1262            public static String[] removeByPrefix(String[] array, String prefix) {
1263                    List<String> list = new ArrayList<String>();
1264    
1265                    for (String s : array) {
1266                            if (!s.startsWith(prefix)) {
1267                                    list.add(s);
1268                            }
1269                    }
1270    
1271                    return list.toArray(new String[list.size()]);
1272            }
1273    
1274            public static void reverse(boolean[] array) {
1275                    for (int left = 0, right = array.length - 1; left < right;
1276                                    left++, right--) {
1277    
1278                            boolean value = array[left];
1279    
1280                            array[left] = array[right];
1281                            array[right] = value;
1282                    }
1283            }
1284    
1285            public static void reverse(char[] array) {
1286                    for (int left = 0, right = array.length - 1; left < right;
1287                                    left++, right--) {
1288    
1289                            char value = array[left];
1290    
1291                            array[left] = array[right];
1292                            array[right] = value;
1293                    }
1294            }
1295    
1296            public static void reverse(double[] array) {
1297                    for (int left = 0, right = array.length - 1; left < right;
1298                                    left++, right--) {
1299    
1300                            double value = array[left];
1301    
1302                            array[left] = array[right];
1303                            array[right] = value;
1304                    }
1305            }
1306    
1307            public static void reverse(int[] array) {
1308                    for (int left = 0, right = array.length - 1; left < right;
1309                                    left++, right--) {
1310    
1311                            int value = array[left];
1312    
1313                            array[left] = array[right];
1314                            array[right] = value;
1315                    }
1316            }
1317    
1318            public static void reverse(long[] array) {
1319                    for (int left = 0, right = array.length - 1; left < right;
1320                                    left++, right--) {
1321    
1322                            long value = array[left];
1323    
1324                            array[left] = array[right];
1325                            array[right] = value;
1326                    }
1327            }
1328    
1329            public static void reverse(short[] array) {
1330                    for (int left = 0, right = array.length - 1; left < right;
1331                                    left++, right--) {
1332    
1333                            short value = array[left];
1334    
1335                            array[left] = array[right];
1336                            array[right] = value;
1337                    }
1338            }
1339    
1340            public static void reverse(String[] array) {
1341                    for (int left = 0, right = array.length - 1; left < right;
1342                                    left++, right--) {
1343    
1344                            String value = array[left];
1345    
1346                            array[left] = array[right];
1347                            array[right] = value;
1348                    }
1349            }
1350    
1351            public static boolean[] subset(boolean[] array, int start, int end) {
1352                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1353                            return array;
1354                    }
1355    
1356                    boolean[] newArray = new boolean[end - start];
1357    
1358                    System.arraycopy(array, start, newArray, 0, end - start);
1359    
1360                    return newArray;
1361            }
1362    
1363            public static byte[] subset(byte[] array, int start, int end) {
1364                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1365                            return array;
1366                    }
1367    
1368                    byte[] newArray = new byte[end - start];
1369    
1370                    System.arraycopy(array, start, newArray, 0, end - start);
1371    
1372                    return newArray;
1373            }
1374    
1375            public static char[] subset(char[] array, int start, int end) {
1376                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1377                            return array;
1378                    }
1379    
1380                    char[] newArray = new char[end - start];
1381    
1382                    System.arraycopy(array, start, newArray, 0, end - start);
1383    
1384                    return newArray;
1385            }
1386    
1387            public static double[] subset(double[] array, int start, int end) {
1388                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1389                            return array;
1390                    }
1391    
1392                    double[] newArray = new double[end - start];
1393    
1394                    System.arraycopy(array, start, newArray, 0, end - start);
1395    
1396                    return newArray;
1397            }
1398    
1399            public static float[] subset(float[] array, int start, int end) {
1400                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1401                            return array;
1402                    }
1403    
1404                    float[] newArray = new float[end - start];
1405    
1406                    System.arraycopy(array, start, newArray, 0, end - start);
1407    
1408                    return newArray;
1409            }
1410    
1411            public static int[] subset(int[] array, int start, int end) {
1412                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1413                            return array;
1414                    }
1415    
1416                    int[] newArray = new int[end - start];
1417    
1418                    System.arraycopy(array, start, newArray, 0, end - start);
1419    
1420                    return newArray;
1421            }
1422    
1423            public static long[] subset(long[] array, int start, int end) {
1424                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1425                            return array;
1426                    }
1427    
1428                    long[] newArray = new long[end - start];
1429    
1430                    System.arraycopy(array, start, newArray, 0, end - start);
1431    
1432                    return newArray;
1433            }
1434    
1435            public static short[] subset(short[] array, int start, int end) {
1436                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1437                            return array;
1438                    }
1439    
1440                    short[] newArray = new short[end - start];
1441    
1442                    System.arraycopy(array, start, newArray, 0, end - start);
1443    
1444                    return newArray;
1445            }
1446    
1447            public static <T> T[] subset(T[] array, int start, int end) {
1448                    if ((start < 0) || (end < 0) || ((end - start) < 0)) {
1449                            return array;
1450                    }
1451    
1452                    Class<?> arrayClass = array.getClass();
1453    
1454                    T[] newArray = (T[])Array.newInstance(
1455                            arrayClass.getComponentType(), end - start);
1456    
1457                    System.arraycopy(array, start, newArray, 0, end - start);
1458    
1459                    return newArray;
1460            }
1461    
1462            public static Boolean[] toArray(boolean[] array) {
1463                    Boolean[] newArray = new Boolean[array.length];
1464    
1465                    for (int i = 0; i < array.length; i++) {
1466                            newArray[i] = Boolean.valueOf(array[i]);
1467                    }
1468    
1469                    return newArray;
1470            }
1471    
1472            public static boolean[] toArray(Boolean[] array) {
1473                    boolean[] newArray = new boolean[array.length];
1474    
1475                    for (int i = 0; i < array.length; i++) {
1476                            newArray[i] = array[i].booleanValue();
1477                    }
1478    
1479                    return newArray;
1480            }
1481    
1482            public static Byte[] toArray(byte[] array) {
1483                    Byte[] newArray = new Byte[array.length];
1484    
1485                    for (int i = 0; i < array.length; i++) {
1486                            newArray[i] = Byte.valueOf(array[i]);
1487                    }
1488    
1489                    return newArray;
1490            }
1491    
1492            public static byte[] toArray(Byte[] array) {
1493                    byte[] newArray = new byte[array.length];
1494    
1495                    for (int i = 0; i < array.length; i++) {
1496                            newArray[i] = array[i].byteValue();
1497                    }
1498    
1499                    return newArray;
1500            }
1501    
1502            public static Character[] toArray(char[] array) {
1503                    Character[] newArray = new Character[array.length];
1504    
1505                    for (int i = 0; i < array.length; i++) {
1506                            newArray[i] = Character.valueOf(array[i]);
1507                    }
1508    
1509                    return newArray;
1510            }
1511    
1512            public static char[] toArray(Character[] array) {
1513                    char[] newArray = new char[array.length];
1514    
1515                    for (int i = 0; i < array.length; i++) {
1516                            newArray[i] = array[i].charValue();
1517                    }
1518    
1519                    return newArray;
1520            }
1521    
1522            public static Double[] toArray(double[] array) {
1523                    Double[] newArray = new Double[array.length];
1524    
1525                    for (int i = 0; i < array.length; i++) {
1526                            newArray[i] = new Double(array[i]);
1527                    }
1528    
1529                    return newArray;
1530            }
1531    
1532            public static double[] toArray(Double[] array) {
1533                    double[] newArray = new double[array.length];
1534    
1535                    for (int i = 0; i < array.length; i++) {
1536                            newArray[i] = array[i].doubleValue();
1537                    }
1538    
1539                    return newArray;
1540            }
1541    
1542            public static Float[] toArray(float[] array) {
1543                    Float[] newArray = new Float[array.length];
1544    
1545                    for (int i = 0; i < array.length; i++) {
1546                            newArray[i] = new Float(array[i]);
1547                    }
1548    
1549                    return newArray;
1550            }
1551    
1552            public static float[] toArray(Float[] array) {
1553                    float[] newArray = new float[array.length];
1554    
1555                    for (int i = 0; i < array.length; i++) {
1556                            newArray[i] = array[i].floatValue();
1557                    }
1558    
1559                    return newArray;
1560            }
1561    
1562            public static Integer[] toArray(int[] array) {
1563                    Integer[] newArray = new Integer[array.length];
1564    
1565                    for (int i = 0; i < array.length; i++) {
1566                            newArray[i] = new Integer(array[i]);
1567                    }
1568    
1569                    return newArray;
1570            }
1571    
1572            public static int[] toArray(Integer[] array) {
1573                    int[] newArray = new int[array.length];
1574    
1575                    for (int i = 0; i < array.length; i++) {
1576                            newArray[i] = array[i].intValue();
1577                    }
1578    
1579                    return newArray;
1580            }
1581    
1582            public static Long[] toArray(long[] array) {
1583                    Long[] newArray = new Long[array.length];
1584    
1585                    for (int i = 0; i < array.length; i++) {
1586                            newArray[i] = new Long(array[i]);
1587                    }
1588    
1589                    return newArray;
1590            }
1591    
1592            public static long[] toArray(Long[] array) {
1593                    long[] newArray = new long[array.length];
1594    
1595                    for (int i = 0; i < array.length; i++) {
1596                            newArray[i] = array[i].longValue();
1597                    }
1598    
1599                    return newArray;
1600            }
1601    
1602            public static Short[] toArray(short[] array) {
1603                    Short[] newArray = new Short[array.length];
1604    
1605                    for (int i = 0; i < array.length; i++) {
1606                            newArray[i] = new Short(array[i]);
1607                    }
1608    
1609                    return newArray;
1610            }
1611    
1612            public static short[] toArray(Short[] array) {
1613                    short[] newArray = new short[array.length];
1614    
1615                    for (int i = 0; i < array.length; i++) {
1616                            newArray[i] = array[i].shortValue();
1617                    }
1618    
1619                    return newArray;
1620            }
1621    
1622            public static double[] toDoubleArray(Collection<Double> collection) {
1623                    double[] newArray = new double[collection.size()];
1624    
1625                    if (collection instanceof List) {
1626                            List<Double> list = (List<Double>)collection;
1627    
1628                            for (int i = 0; i < list.size(); i++) {
1629                                    Double value = list.get(i);
1630    
1631                                    newArray[i] = value.doubleValue();
1632                            }
1633                    }
1634                    else {
1635                            int i = 0;
1636    
1637                            Iterator<Double> iterator = collection.iterator();
1638    
1639                            while (iterator.hasNext()) {
1640                                    Double value = iterator.next();
1641    
1642                                    newArray[i++] = value.doubleValue();
1643                            }
1644                    }
1645    
1646                    return newArray;
1647            }
1648    
1649            public static float[] toFloatArray(Collection<Float> collection) {
1650                    float[] newArray = new float[collection.size()];
1651    
1652                    if (collection instanceof List) {
1653                            List<Float> list = (List<Float>)collection;
1654    
1655                            for (int i = 0; i < list.size(); i++) {
1656                                    Float value = list.get(i);
1657    
1658                                    newArray[i] = value.floatValue();
1659                            }
1660                    }
1661                    else {
1662                            int i = 0;
1663    
1664                            Iterator<Float> iterator = collection.iterator();
1665    
1666                            while (iterator.hasNext()) {
1667                                    Float value = iterator.next();
1668    
1669                                    newArray[i++] = value.floatValue();
1670                            }
1671                    }
1672    
1673                    return newArray;
1674            }
1675    
1676            public static int[] toIntArray(Collection<Integer> collection) {
1677                    int[] newArray = new int[collection.size()];
1678    
1679                    if (collection instanceof List) {
1680                            List<Integer> list = (List<Integer>)collection;
1681    
1682                            for (int i = 0; i < list.size(); i++) {
1683                                    Integer value = list.get(i);
1684    
1685                                    newArray[i] = value.intValue();
1686                            }
1687                    }
1688                    else {
1689                            int i = 0;
1690    
1691                            Iterator<Integer> iterator = collection.iterator();
1692    
1693                            while (iterator.hasNext()) {
1694                                    Integer value = iterator.next();
1695    
1696                                    newArray[i++] = value.intValue();
1697                            }
1698                    }
1699    
1700                    return newArray;
1701            }
1702    
1703            public static long[] toLongArray(Collection<Long> collection) {
1704                    long[] newArray = new long[collection.size()];
1705    
1706                    if (collection instanceof List) {
1707                            List<Long> list = (List<Long>)collection;
1708    
1709                            for (int i = 0; i < list.size(); i++) {
1710                                    Long value = list.get(i);
1711    
1712                                    newArray[i] = value.longValue();
1713                            }
1714                    }
1715                    else {
1716                            int i = 0;
1717    
1718                            Iterator<Long> iterator = collection.iterator();
1719    
1720                            while (iterator.hasNext()) {
1721                                    Long value = iterator.next();
1722    
1723                                    newArray[i++] = value.longValue();
1724                            }
1725                    }
1726    
1727                    return newArray;
1728            }
1729    
1730            public static Long[] toLongArray(Object[] array) {
1731                    Long[] newArray = new Long[array.length];
1732    
1733                    for (int i = 0; i < array.length; i++) {
1734                            newArray[i] = (Long)array[i];
1735                    }
1736    
1737                    return newArray;
1738            }
1739    
1740            public static short[] toShortArray(Collection<Short> collection) {
1741                    short[] newArray = new short[collection.size()];
1742    
1743                    if (collection instanceof List) {
1744                            List<Short> list = (List<Short>)collection;
1745    
1746                            for (int i = 0; i < list.size(); i++) {
1747                                    Short value = list.get(i);
1748    
1749                                    newArray[i] = value.shortValue();
1750                            }
1751                    }
1752                    else {
1753                            int i = 0;
1754    
1755                            Iterator<Short> iterator = collection.iterator();
1756    
1757                            while (iterator.hasNext()) {
1758                                    Short value = iterator.next();
1759    
1760                                    newArray[i++] = value.shortValue();
1761                            }
1762                    }
1763    
1764                    return newArray;
1765            }
1766    
1767            /**
1768             * @see ListUtil#toString(List, String)
1769             */
1770            public static String toString(Object[] array, String param) {
1771                    return toString(array, param, StringPool.COMMA);
1772            }
1773    
1774            /**
1775             * @see ListUtil#toString(List, String, String)
1776             */
1777            public static String toString(
1778                    Object[] array, String param, String delimiter) {
1779    
1780                    return toString(array, param, delimiter, null);
1781            }
1782    
1783            public static String toString(
1784                    Object[] array, String param, String delimiter, Locale locale) {
1785    
1786                    if (isEmpty(array)) {
1787                            return StringPool.BLANK;
1788                    }
1789    
1790                    StringBundler sb = new StringBundler(2 * array.length - 1);
1791    
1792                    for (int i = 0; i < array.length; i++) {
1793                            Object bean = array[i];
1794    
1795                            Object value = BeanPropertiesUtil.getObject(bean, param);
1796    
1797                            if (value != null) {
1798                                    if (locale != null) {
1799                                            sb.append(LanguageUtil.get(locale, value.toString()));
1800                                    }
1801                                    else {
1802                                            sb.append(value);
1803                                    }
1804                            }
1805    
1806                            if ((i + 1) != array.length) {
1807                                    sb.append(delimiter);
1808                            }
1809                    }
1810    
1811                    return sb.toString();
1812            }
1813    
1814            /**
1815             * @see ListUtil#toString(List, Accessor)
1816             */
1817            public static <T, V> String toString(T[] list, Accessor<T, V> accessor) {
1818                    return toString(list, accessor, StringPool.COMMA);
1819            }
1820    
1821            /**
1822             * @see ListUtil#toString(List, Accessor, String)
1823             */
1824            public static <T, V> String toString(
1825                    T[] list, Accessor<T, V> accessor, String delimiter) {
1826    
1827                    return toString(list, accessor, delimiter, null);
1828            }
1829    
1830            public static <T, V> String toString(
1831                    T[] list, Accessor<T, V> accessor, String delimiter, Locale locale) {
1832    
1833                    if (isEmpty(list)) {
1834                            return StringPool.BLANK;
1835                    }
1836    
1837                    StringBundler sb = new StringBundler(2 * list.length - 1);
1838    
1839                    for (int i = 0; i < list.length; i++) {
1840                            T bean = list[i];
1841    
1842                            V value = accessor.get(bean);
1843    
1844                            if (value != null) {
1845                                    if (locale != null) {
1846                                            sb.append(LanguageUtil.get(locale, value.toString()));
1847                                    }
1848                                    else {
1849                                            sb.append(value);
1850                                    }
1851                            }
1852    
1853                            if ((i + 1) != list.length) {
1854                                    sb.append(delimiter);
1855                            }
1856                    }
1857    
1858                    return sb.toString();
1859            }
1860    
1861            public static String[] toStringArray(boolean[] array) {
1862                    String[] newArray = new String[array.length];
1863    
1864                    for (int i = 0; i < array.length; i++) {
1865                            newArray[i] = String.valueOf(array[i]);
1866                    }
1867    
1868                    return newArray;
1869            }
1870    
1871            public static String[] toStringArray(byte[] array) {
1872                    String[] newArray = new String[array.length];
1873    
1874                    for (int i = 0; i < array.length; i++) {
1875                            newArray[i] = String.valueOf(array[i]);
1876                    }
1877    
1878                    return newArray;
1879            }
1880    
1881            public static String[] toStringArray(char[] array) {
1882                    String[] newArray = new String[array.length];
1883    
1884                    for (int i = 0; i < array.length; i++) {
1885                            newArray[i] = String.valueOf(array[i]);
1886                    }
1887    
1888                    return newArray;
1889            }
1890    
1891            public static String[] toStringArray(Date[] array, DateFormat dateFormat) {
1892                    String[] newArray = new String[array.length];
1893    
1894                    for (int i = 0; i < array.length; i++) {
1895                            newArray[i] = dateFormat.format(array[i]);
1896                    }
1897    
1898                    return newArray;
1899            }
1900    
1901            public static String[] toStringArray(double[] array) {
1902                    String[] newArray = new String[array.length];
1903    
1904                    for (int i = 0; i < array.length; i++) {
1905                            newArray[i] = String.valueOf(array[i]);
1906                    }
1907    
1908                    return newArray;
1909            }
1910    
1911            public static String[] toStringArray(float[] array) {
1912                    String[] newArray = new String[array.length];
1913    
1914                    for (int i = 0; i < array.length; i++) {
1915                            newArray[i] = String.valueOf(array[i]);
1916                    }
1917    
1918                    return newArray;
1919            }
1920    
1921            public static String[] toStringArray(int[] array) {
1922                    String[] newArray = new String[array.length];
1923    
1924                    for (int i = 0; i < array.length; i++) {
1925                            newArray[i] = String.valueOf(array[i]);
1926                    }
1927    
1928                    return newArray;
1929            }
1930    
1931            public static String[] toStringArray(JSONArray array) {
1932                    String[] newArray = new String[array.length()];
1933    
1934                    for (int i = 0; i < array.length(); i++) {
1935                            newArray[i] = array.getString(i);
1936                    }
1937    
1938                    return newArray;
1939            }
1940    
1941            public static String[] toStringArray(long[] array) {
1942                    String[] newArray = new String[array.length];
1943    
1944                    for (int i = 0; i < array.length; i++) {
1945                            newArray[i] = String.valueOf(array[i]);
1946                    }
1947    
1948                    return newArray;
1949            }
1950    
1951            public static String[] toStringArray(Object[] array) {
1952                    String[] newArray = new String[array.length];
1953    
1954                    for (int i = 0; i < array.length; i++) {
1955                            newArray[i] = String.valueOf(array[i]);
1956                    }
1957    
1958                    return newArray;
1959            }
1960    
1961            public static String[] toStringArray(short[] array) {
1962                    String[] newArray = new String[array.length];
1963    
1964                    for (int i = 0; i < array.length; i++) {
1965                            newArray[i] = String.valueOf(array[i]);
1966                    }
1967    
1968                    return newArray;
1969            }
1970    
1971            public static byte[] unique(byte[] array) {
1972                    List<Byte> list = new UniqueList<Byte>();
1973    
1974                    for (int i = 0; i < array.length; i++) {
1975                            list.add(array[i]);
1976                    }
1977    
1978                    return toArray(list.toArray(new Byte[list.size()]));
1979            }
1980    
1981            public static double[] unique(double[] array) {
1982                    List<Double> list = new UniqueList<Double>();
1983    
1984                    for (int i = 0; i < array.length; i++) {
1985                            list.add(array[i]);
1986                    }
1987    
1988                    return toArray(list.toArray(new Double[list.size()]));
1989            }
1990    
1991            public static float[] unique(float[] array) {
1992                    List<Float> list = new UniqueList<Float>();
1993    
1994                    for (int i = 0; i < array.length; i++) {
1995                            list.add(array[i]);
1996                    }
1997    
1998                    return toArray(list.toArray(new Float[list.size()]));
1999            }
2000    
2001            public static int[] unique(int[] array) {
2002                    List<Integer> list = new UniqueList<Integer>();
2003    
2004                    for (int i = 0; i < array.length; i++) {
2005                            list.add(array[i]);
2006                    }
2007    
2008                    return toArray(list.toArray(new Integer[list.size()]));
2009            }
2010    
2011            public static long[] unique(long[] array) {
2012                    List<Long> list = new UniqueList<Long>();
2013    
2014                    for (int i = 0; i < array.length; i++) {
2015                            list.add(array[i]);
2016                    }
2017    
2018                    return toArray(list.toArray(new Long[list.size()]));
2019            }
2020    
2021            public static short[] unique(short[] array) {
2022                    List<Short> list = new UniqueList<Short>();
2023    
2024                    for (int i = 0; i < array.length; i++) {
2025                            list.add(array[i]);
2026                    }
2027    
2028                    return toArray(list.toArray(new Short[list.size()]));
2029            }
2030    
2031    }