Source Code Cross Referenced for Arrays.java in  » Database-ORM » openjpa » org » apache » openjpa » lib » util » concurrent » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » openjpa » org.apache.openjpa.lib.util.concurrent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.    
018:         */
019:        /*
020:         * Written by Dawid Kurzyniec, based on code written by Doug Lea with assistance
021:         * from members of JCP JSR-166 Expert Group. Released to the public domain,
022:         * as explained at http://creativecommons.org/licenses/publicdomain.
023:         */
024:        package org.apache.openjpa.lib.util.concurrent;
025:
026:        import java.lang.reflect.Array;
027:        import java.util.ArrayList;
028:        import java.util.Comparator;
029:        import java.util.List;
030:
031:        class Arrays {
032:
033:            private Arrays() {
034:            }
035:
036:            public static void sort(long[] a) {
037:                java.util.Arrays.sort(a);
038:            }
039:
040:            public static void sort(long[] a, int fromIndex, int toIndex) {
041:                java.util.Arrays.sort(a, fromIndex, toIndex);
042:            }
043:
044:            public static void sort(int[] a) {
045:                java.util.Arrays.sort(a);
046:            }
047:
048:            public static void sort(int[] a, int fromIndex, int toIndex) {
049:                java.util.Arrays.sort(a, fromIndex, toIndex);
050:            }
051:
052:            public static void sort(short[] a) {
053:                java.util.Arrays.sort(a);
054:            }
055:
056:            public static void sort(short[] a, int fromIndex, int toIndex) {
057:                java.util.Arrays.sort(a, fromIndex, toIndex);
058:            }
059:
060:            public static void sort(char[] a) {
061:                java.util.Arrays.sort(a);
062:            }
063:
064:            public static void sort(char[] a, int fromIndex, int toIndex) {
065:                java.util.Arrays.sort(a, fromIndex, toIndex);
066:            }
067:
068:            public static void sort(byte[] a) {
069:                java.util.Arrays.sort(a);
070:            }
071:
072:            public static void sort(byte[] a, int fromIndex, int toIndex) {
073:                java.util.Arrays.sort(a, fromIndex, toIndex);
074:            }
075:
076:            public static void sort(double[] a) {
077:                java.util.Arrays.sort(a);
078:            }
079:
080:            public static void sort(double[] a, int fromIndex, int toIndex) {
081:                java.util.Arrays.sort(a, fromIndex, toIndex);
082:            }
083:
084:            public static void sort(float[] a) {
085:                java.util.Arrays.sort(a);
086:            }
087:
088:            public static void sort(float[] a, int fromIndex, int toIndex) {
089:                java.util.Arrays.sort(a, fromIndex, toIndex);
090:            }
091:
092:            public static void sort(Object[] a) {
093:                java.util.Arrays.sort(a);
094:            }
095:
096:            public static void sort(Object[] a, int fromIndex, int toIndex) {
097:                java.util.Arrays.sort(a, fromIndex, toIndex);
098:            }
099:
100:            public static void sort(Object[] a, Comparator c) {
101:                java.util.Arrays.sort(a, c);
102:            }
103:
104:            public static void sort(Object[] a, int fromIndex, int toIndex,
105:                    Comparator c) {
106:                java.util.Arrays.sort(a, fromIndex, toIndex, c);
107:            }
108:
109:            // Searching
110:
111:            public static int binarySearch(long[] a, long key) {
112:                return java.util.Arrays.binarySearch(a, key);
113:            }
114:
115:            public static int binarySearch(int[] a, int key) {
116:                return java.util.Arrays.binarySearch(a, key);
117:            }
118:
119:            public static int binarySearch(short[] a, short key) {
120:                return java.util.Arrays.binarySearch(a, key);
121:            }
122:
123:            public static int binarySearch(char[] a, char key) {
124:                return java.util.Arrays.binarySearch(a, key);
125:            }
126:
127:            public static int binarySearch(byte[] a, byte key) {
128:                return java.util.Arrays.binarySearch(a, key);
129:            }
130:
131:            public static int binarySearch(double[] a, double key) {
132:                return java.util.Arrays.binarySearch(a, key);
133:            }
134:
135:            public static int binarySearch(float[] a, float key) {
136:                return java.util.Arrays.binarySearch(a, key);
137:            }
138:
139:            public static int binarySearch(Object[] a, Object key) {
140:                return java.util.Arrays.binarySearch(a, key);
141:            }
142:
143:            public static int binarySearch(Object[] a, Object key, Comparator c) {
144:                return java.util.Arrays.binarySearch(a, key, c);
145:            }
146:
147:            // Equality Testing
148:
149:            public static boolean equals(long[] a, long[] a2) {
150:                return java.util.Arrays.equals(a, a2);
151:            }
152:
153:            public static boolean equals(int[] a, int[] a2) {
154:                return java.util.Arrays.equals(a, a2);
155:            }
156:
157:            public static boolean equals(short[] a, short a2[]) {
158:                return java.util.Arrays.equals(a, a2);
159:            }
160:
161:            public static boolean equals(char[] a, char[] a2) {
162:                return java.util.Arrays.equals(a, a2);
163:            }
164:
165:            public static boolean equals(byte[] a, byte[] a2) {
166:                return java.util.Arrays.equals(a, a2);
167:            }
168:
169:            public static boolean equals(boolean[] a, boolean[] a2) {
170:                return java.util.Arrays.equals(a, a2);
171:            }
172:
173:            public static boolean equals(double[] a, double[] a2) {
174:                return java.util.Arrays.equals(a, a2);
175:            }
176:
177:            public static boolean equals(float[] a, float[] a2) {
178:                return java.util.Arrays.equals(a, a2);
179:            }
180:
181:            public static boolean equals(Object[] a, Object[] a2) {
182:                return java.util.Arrays.equals(a, a2);
183:            }
184:
185:            // Filling
186:
187:            public static void fill(long[] a, long val) {
188:                java.util.Arrays.fill(a, val);
189:            }
190:
191:            public static void fill(long[] a, int fromIndex, int toIndex,
192:                    long val) {
193:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
194:            }
195:
196:            public static void fill(int[] a, int val) {
197:                java.util.Arrays.fill(a, val);
198:            }
199:
200:            public static void fill(int[] a, int fromIndex, int toIndex, int val) {
201:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
202:            }
203:
204:            public static void fill(short[] a, short val) {
205:                java.util.Arrays.fill(a, val);
206:            }
207:
208:            public static void fill(short[] a, int fromIndex, int toIndex,
209:                    short val) {
210:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
211:            }
212:
213:            public static void fill(char[] a, char val) {
214:                java.util.Arrays.fill(a, val);
215:            }
216:
217:            public static void fill(char[] a, int fromIndex, int toIndex,
218:                    char val) {
219:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
220:            }
221:
222:            public static void fill(byte[] a, byte val) {
223:                java.util.Arrays.fill(a, val);
224:            }
225:
226:            public static void fill(byte[] a, int fromIndex, int toIndex,
227:                    byte val) {
228:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
229:            }
230:
231:            public static void fill(boolean[] a, boolean val) {
232:                java.util.Arrays.fill(a, val);
233:            }
234:
235:            public static void fill(boolean[] a, int fromIndex, int toIndex,
236:                    boolean val) {
237:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
238:            }
239:
240:            public static void fill(double[] a, double val) {
241:                java.util.Arrays.fill(a, val);
242:            }
243:
244:            public static void fill(double[] a, int fromIndex, int toIndex,
245:                    double val) {
246:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
247:            }
248:
249:            public static void fill(float[] a, float val) {
250:                java.util.Arrays.fill(a, val);
251:            }
252:
253:            public static void fill(float[] a, int fromIndex, int toIndex,
254:                    float val) {
255:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
256:            }
257:
258:            public static void fill(Object[] a, Object val) {
259:                java.util.Arrays.fill(a, val);
260:            }
261:
262:            public static void fill(Object[] a, int fromIndex, int toIndex,
263:                    Object val) {
264:                java.util.Arrays.fill(a, fromIndex, toIndex, val);
265:            }
266:
267:            // Cloning
268:
269:            /**
270:             * @since 1.6
271:             */
272:            public static Object[] copyOf(Object[] original, int newLength) {
273:                return copyOf(original, newLength, original.getClass());
274:            }
275:
276:            /**
277:             * @since 1.6
278:             */
279:            public static Object[] copyOf(Object[] original, int newLength,
280:                    Class newType) {
281:                Object[] arr = (newType == Object[].class) ? new Object[newLength]
282:                        : (Object[]) Array.newInstance(newType
283:                                .getComponentType(), newLength);
284:                int len = (original.length < newLength ? original.length
285:                        : newLength);
286:                System.arraycopy(original, 0, arr, 0, len);
287:                return arr;
288:            }
289:
290:            /**
291:             * @since 1.6
292:             */
293:            public static byte[] copyOf(byte[] original, int newLength) {
294:                byte[] arr = new byte[newLength];
295:                int len = (original.length < newLength ? original.length
296:                        : newLength);
297:                System.arraycopy(original, 0, arr, 0, len);
298:                return arr;
299:            }
300:
301:            /**
302:             * @since 1.6
303:             */
304:            public static short[] copyOf(short[] original, int newLength) {
305:                short[] arr = new short[newLength];
306:                int len = (original.length < newLength ? original.length
307:                        : newLength);
308:                System.arraycopy(original, 0, arr, 0, len);
309:                return arr;
310:            }
311:
312:            /**
313:             * @since 1.6
314:             */
315:            public static int[] copyOf(int[] original, int newLength) {
316:                int[] arr = new int[newLength];
317:                int len = (original.length < newLength ? original.length
318:                        : newLength);
319:                System.arraycopy(original, 0, arr, 0, len);
320:                return arr;
321:            }
322:
323:            /**
324:             * @since 1.6
325:             */
326:            public static long[] copyOf(long[] original, int newLength) {
327:                long[] arr = new long[newLength];
328:                int len = (original.length < newLength ? original.length
329:                        : newLength);
330:                System.arraycopy(original, 0, arr, 0, len);
331:                return arr;
332:            }
333:
334:            /**
335:             * @since 1.6
336:             */
337:            public static char[] copyOf(char[] original, int newLength) {
338:                char[] arr = new char[newLength];
339:                int len = (original.length < newLength ? original.length
340:                        : newLength);
341:                System.arraycopy(original, 0, arr, 0, len);
342:                return arr;
343:            }
344:
345:            /**
346:             * @since 1.6
347:             */
348:            public static float[] copyOf(float[] original, int newLength) {
349:                float[] arr = new float[newLength];
350:                int len = (original.length < newLength ? original.length
351:                        : newLength);
352:                System.arraycopy(original, 0, arr, 0, len);
353:                return arr;
354:            }
355:
356:            /**
357:             * @since 1.6
358:             */
359:            public static double[] copyOf(double[] original, int newLength) {
360:                double[] arr = new double[newLength];
361:                int len = (original.length < newLength ? original.length
362:                        : newLength);
363:                System.arraycopy(original, 0, arr, 0, len);
364:                return arr;
365:            }
366:
367:            /**
368:             * @since 1.6
369:             */
370:            public static boolean[] copyOf(boolean[] original, int newLength) {
371:                boolean[] arr = new boolean[newLength];
372:                int len = (original.length < newLength ? original.length
373:                        : newLength);
374:                System.arraycopy(original, 0, arr, 0, len);
375:                return arr;
376:            }
377:
378:            /**
379:             * @since 1.6
380:             */
381:            public static Object[] copyOfRange(Object[] original, int from,
382:                    int to) {
383:                return copyOfRange(original, from, to, original.getClass());
384:            }
385:
386:            /**
387:             * @since 1.6
388:             */
389:            public static Object[] copyOfRange(Object[] original, int from,
390:                    int to, Class newType) {
391:                int newLength = to - from;
392:                if (newLength < 0)
393:                    throw new IllegalArgumentException(from + " > " + to);
394:                Object[] arr = (newType == Object[].class) ? new Object[newLength]
395:                        : (Object[]) Array.newInstance(newType
396:                                .getComponentType(), newLength);
397:                int ceil = original.length - from;
398:                int len = (ceil < newLength) ? ceil : newLength;
399:                System.arraycopy(original, from, arr, 0, len);
400:                return arr;
401:            }
402:
403:            /**
404:             * @since 1.6
405:             */
406:            public static byte[] copyOfRange(byte[] original, int from, int to) {
407:                int newLength = to - from;
408:                if (newLength < 0)
409:                    throw new IllegalArgumentException(from + " > " + to);
410:                byte[] arr = new byte[newLength];
411:                int ceil = original.length - from;
412:                int len = (ceil < newLength) ? ceil : newLength;
413:                System.arraycopy(original, from, arr, 0, len);
414:                return arr;
415:            }
416:
417:            /**
418:             * @since 1.6
419:             */
420:            public static short[] copyOfRange(short[] original, int from, int to) {
421:                int newLength = to - from;
422:                if (newLength < 0)
423:                    throw new IllegalArgumentException(from + " > " + to);
424:                short[] arr = new short[newLength];
425:                int ceil = original.length - from;
426:                int len = (ceil < newLength) ? ceil : newLength;
427:                System.arraycopy(original, from, arr, 0, len);
428:                return arr;
429:            }
430:
431:            /**
432:             * @since 1.6
433:             */
434:            public static int[] copyOfRange(int[] original, int from, int to) {
435:                int newLength = to - from;
436:                if (newLength < 0)
437:                    throw new IllegalArgumentException(from + " > " + to);
438:                int[] arr = new int[newLength];
439:                int ceil = original.length - from;
440:                int len = (ceil < newLength) ? ceil : newLength;
441:                System.arraycopy(original, from, arr, 0, len);
442:                return arr;
443:            }
444:
445:            /**
446:             * @since 1.6
447:             */
448:            public static long[] copyOfRange(long[] original, int from, int to) {
449:                int newLength = to - from;
450:                if (newLength < 0)
451:                    throw new IllegalArgumentException(from + " > " + to);
452:                long[] arr = new long[newLength];
453:                int ceil = original.length - from;
454:                int len = (ceil < newLength) ? ceil : newLength;
455:                System.arraycopy(original, from, arr, 0, len);
456:                return arr;
457:            }
458:
459:            /**
460:             * @since 1.6
461:             */
462:            public static char[] copyOfRange(char[] original, int from, int to) {
463:                int newLength = to - from;
464:                if (newLength < 0)
465:                    throw new IllegalArgumentException(from + " > " + to);
466:                char[] arr = new char[newLength];
467:                int ceil = original.length - from;
468:                int len = (ceil < newLength) ? ceil : newLength;
469:                System.arraycopy(original, from, arr, 0, len);
470:                return arr;
471:            }
472:
473:            /**
474:             * @since 1.6
475:             */
476:            public static float[] copyOfRange(float[] original, int from, int to) {
477:                int newLength = to - from;
478:                if (newLength < 0)
479:                    throw new IllegalArgumentException(from + " > " + to);
480:                float[] arr = new float[newLength];
481:                int ceil = original.length - from;
482:                int len = (ceil < newLength) ? ceil : newLength;
483:                System.arraycopy(original, from, arr, 0, len);
484:                return arr;
485:            }
486:
487:            /**
488:             * @since 1.6
489:             */
490:            public static double[] copyOfRange(double[] original, int from,
491:                    int to) {
492:                int newLength = to - from;
493:                if (newLength < 0)
494:                    throw new IllegalArgumentException(from + " > " + to);
495:                double[] arr = new double[newLength];
496:                int ceil = original.length - from;
497:                int len = (ceil < newLength) ? ceil : newLength;
498:                System.arraycopy(original, from, arr, 0, len);
499:                return arr;
500:            }
501:
502:            /**
503:             * @since 1.6
504:             */
505:            public static boolean[] copyOfRange(boolean[] original, int from,
506:                    int to) {
507:                int newLength = to - from;
508:                if (newLength < 0)
509:                    throw new IllegalArgumentException(from + " > " + to);
510:                boolean[] arr = new boolean[newLength];
511:                int ceil = original.length - from;
512:                int len = (ceil < newLength) ? ceil : newLength;
513:                System.arraycopy(original, from, arr, 0, len);
514:                return arr;
515:            }
516:
517:            public static List asList(Object[] a) {
518:                return java.util.Arrays.asList(a);
519:            }
520:
521:            /**
522:             * @since 1.5
523:             */
524:            public static int hashCode(long a[]) {
525:                if (a == null)
526:                    return 0;
527:                int hash = 1;
528:                for (int i = 0; i < a.length; i++) {
529:                    long e = a[i];
530:                    hash = 31 * hash + (int) (e ^ (e >>> 32));
531:                }
532:                return hash;
533:            }
534:
535:            /**
536:             * @since 1.5
537:             */
538:            public static int hashCode(int a[]) {
539:                if (a == null)
540:                    return 0;
541:                int hash = 1;
542:                for (int i = 0; i < a.length; i++) {
543:                    hash = 31 * hash + a[i];
544:                }
545:                return hash;
546:            }
547:
548:            /**
549:             * @since 1.5
550:             */
551:            public static int hashCode(short a[]) {
552:                if (a == null)
553:                    return 0;
554:                int hash = 1;
555:                for (int i = 0; i < a.length; i++) {
556:                    hash = 31 * hash + a[i];
557:                }
558:                return hash;
559:            }
560:
561:            /**
562:             * @since 1.5
563:             */
564:            public static int hashCode(char a[]) {
565:                if (a == null)
566:                    return 0;
567:                int hash = 1;
568:                for (int i = 0; i < a.length; i++) {
569:                    hash = 31 * hash + a[i];
570:                }
571:                return hash;
572:            }
573:
574:            /**
575:             * @since 1.5
576:             */
577:            public static int hashCode(byte a[]) {
578:                if (a == null)
579:                    return 0;
580:                int hash = 1;
581:                for (int i = 0; i < a.length; i++) {
582:                    hash = 31 * hash + a[i];
583:                }
584:                return hash;
585:            }
586:
587:            /**
588:             * @since 1.5
589:             */
590:            public static int hashCode(boolean a[]) {
591:                if (a == null)
592:                    return 0;
593:                int hash = 1;
594:                for (int i = 0; i < a.length; i++) {
595:                    hash = 31 * hash + (a[i] ? 1231 : 1237);
596:                }
597:                return hash;
598:            }
599:
600:            /**
601:             * @since 1.5
602:             */
603:            public static int hashCode(float a[]) {
604:                if (a == null)
605:                    return 0;
606:                int hash = 1;
607:                for (int i = 0; i < a.length; i++) {
608:                    hash = 31 * hash + Float.floatToIntBits(a[i]);
609:                }
610:                return hash;
611:            }
612:
613:            /**
614:             * @since 1.5
615:             */
616:            public static int hashCode(double a[]) {
617:                if (a == null)
618:                    return 0;
619:                int hash = 1;
620:                for (int i = 0; i < a.length; i++) {
621:                    long e = Double.doubleToLongBits(a[i]);
622:                    hash = 31 * hash + (int) (e ^ (e >>> 32));
623:                }
624:                return hash;
625:            }
626:
627:            /**
628:             * @since 1.5
629:             */
630:            public static int hashCode(Object a[]) {
631:                if (a == null)
632:                    return 0;
633:                int hash = 1;
634:                for (int i = 0; i < a.length; i++) {
635:                    Object e = a[i];
636:                    hash = 31 * hash + (e == null ? 0 : e.hashCode());
637:                }
638:                return hash;
639:            }
640:
641:            /**
642:             * @since 1.5
643:             */
644:            public static int deepHashCode(Object a[]) {
645:                if (a == null)
646:                    return 0;
647:                int hash = 1;
648:                for (int i = 0; i < a.length; i++) {
649:                    Object e = a[i];
650:                    hash = 31
651:                            * hash
652:                            + (e instanceof  Object[] ? deepHashCode((Object[]) e)
653:                                    : (e instanceof  byte[] ? hashCode((byte[]) e)
654:                                            : (e instanceof  short[] ? hashCode((short[]) e)
655:                                                    : (e instanceof  int[] ? hashCode((int[]) e)
656:                                                            : (e instanceof  long[] ? hashCode((long[]) e)
657:                                                                    : (e instanceof  char[] ? hashCode((char[]) e)
658:                                                                            : (e instanceof  boolean[] ? hashCode((boolean[]) e)
659:                                                                                    : (e instanceof  float[] ? hashCode((float[]) e)
660:                                                                                            : (e instanceof  double[] ? hashCode((double[]) e)
661:                                                                                                    : (e != null ? e
662:                                                                                                            .hashCode()
663:                                                                                                            : 0))))))))));
664:                }
665:                return hash;
666:            }
667:
668:            /**
669:             * @since 1.5
670:             */
671:            public static boolean deepEquals(Object[] a1, Object[] a2) {
672:                if (a1 == a2)
673:                    return true;
674:                if (a1 == null || a2 == null)
675:                    return false;
676:                int len = a1.length;
677:                if (len != a2.length)
678:                    return false;
679:                for (int i = 0; i < len; i++) {
680:                    Object e1 = a1[i];
681:                    Object e2 = a2[i];
682:                    if (e1 == e2)
683:                        continue;
684:                    if (e1 == null)
685:                        return false;
686:                    boolean eq = (e1.getClass() != e2.getClass() || e1
687:                            .getClass().isArray()) ? e1.equals(e2)
688:                            : (e1 instanceof  Object[] && e2 instanceof  Object[]) ? deepEquals(
689:                                    (Object[]) e1, (Object[]) e2)
690:                                    : (e1 instanceof  byte[] && e2 instanceof  byte[]) ? equals(
691:                                            (byte[]) e1, (byte[]) e2)
692:                                            : (e1 instanceof  short[] && e2 instanceof  short[]) ? equals(
693:                                                    (short[]) e1, (short[]) e2)
694:                                                    : (e1 instanceof  int[] && e2 instanceof  int[]) ? equals(
695:                                                            (int[]) e1,
696:                                                            (int[]) e2)
697:                                                            : (e1 instanceof  long[] && e2 instanceof  long[]) ? equals(
698:                                                                    (long[]) e1,
699:                                                                    (long[]) e2)
700:                                                                    : (e1 instanceof  char[] && e2 instanceof  char[]) ? equals(
701:                                                                            (char[]) e1,
702:                                                                            (char[]) e2)
703:                                                                            : (e1 instanceof  boolean[] && e2 instanceof  boolean[]) ? equals(
704:                                                                                    (boolean[]) e1,
705:                                                                                    (boolean[]) e2)
706:                                                                                    : (e1 instanceof  float[] && e2 instanceof  float[]) ? equals(
707:                                                                                            (float[]) e1,
708:                                                                                            (float[]) e2)
709:                                                                                            : (e1 instanceof  double[] && e2 instanceof  double[]) ? equals(
710:                                                                                                    (double[]) e1,
711:                                                                                                    (double[]) e2)
712:                                                                                                    : e1
713:                                                                                                            .equals(e2);
714:
715:                    if (!eq)
716:                        return false;
717:                }
718:                return true;
719:            }
720:
721:            /**
722:             * @since 1.5
723:             */
724:            public static String toString(long[] a) {
725:                if (a == null)
726:                    return "null";
727:                if (a.length == 0)
728:                    return "[]";
729:                StringBuffer buf = new StringBuffer();
730:                buf.append('[').append(a[0]);
731:                for (int i = 1; i < a.length; i++)
732:                    buf.append(", ").append(a[i]);
733:                buf.append(']');
734:                return buf.toString();
735:            }
736:
737:            /**
738:             * @since 1.5
739:             */
740:            public static String toString(int[] a) {
741:                if (a == null)
742:                    return "null";
743:                if (a.length == 0)
744:                    return "[]";
745:                StringBuffer buf = new StringBuffer();
746:                buf.append('[').append(a[0]);
747:                for (int i = 1; i < a.length; i++)
748:                    buf.append(", ").append(a[i]);
749:                buf.append(']');
750:                return buf.toString();
751:            }
752:
753:            /**
754:             * @since 1.5
755:             */
756:            public static String toString(short[] a) {
757:                if (a == null)
758:                    return "null";
759:                if (a.length == 0)
760:                    return "[]";
761:                StringBuffer buf = new StringBuffer();
762:                buf.append('[').append(a[0]);
763:                for (int i = 1; i < a.length; i++)
764:                    buf.append(", ").append(a[i]);
765:                buf.append(']');
766:                return buf.toString();
767:            }
768:
769:            /**
770:             * @since 1.5
771:             */
772:            public static String toString(char[] a) {
773:                if (a == null)
774:                    return "null";
775:                if (a.length == 0)
776:                    return "[]";
777:                StringBuffer buf = new StringBuffer();
778:                buf.append('[').append(a[0]);
779:                for (int i = 1; i < a.length; i++)
780:                    buf.append(", ").append(a[i]);
781:                buf.append(']');
782:                return buf.toString();
783:            }
784:
785:            /**
786:             * @since 1.5
787:             */
788:            public static String toString(byte[] a) {
789:                if (a == null)
790:                    return "null";
791:                if (a.length == 0)
792:                    return "[]";
793:                StringBuffer buf = new StringBuffer();
794:                buf.append('[').append(a[0]);
795:                for (int i = 1; i < a.length; i++)
796:                    buf.append(", ").append(a[i]);
797:                buf.append(']');
798:                return buf.toString();
799:            }
800:
801:            /**
802:             * @since 1.5
803:             */
804:            public static String toString(boolean[] a) {
805:                if (a == null)
806:                    return "null";
807:                if (a.length == 0)
808:                    return "[]";
809:                StringBuffer buf = new StringBuffer();
810:                buf.append('[').append(a[0]);
811:                for (int i = 1; i < a.length; i++)
812:                    buf.append(", ").append(a[i]);
813:                buf.append(']');
814:                return buf.toString();
815:            }
816:
817:            /**
818:             * @since 1.5
819:             */
820:            public static String toString(float[] a) {
821:                if (a == null)
822:                    return "null";
823:                if (a.length == 0)
824:                    return "[]";
825:                StringBuffer buf = new StringBuffer();
826:                buf.append('[').append(a[0]);
827:                for (int i = 1; i < a.length; i++)
828:                    buf.append(", ").append(a[i]);
829:                buf.append(']');
830:                return buf.toString();
831:            }
832:
833:            /**
834:             * @since 1.5
835:             */
836:            public static String toString(double[] a) {
837:                if (a == null)
838:                    return "null";
839:                if (a.length == 0)
840:                    return "[]";
841:                StringBuffer buf = new StringBuffer();
842:                buf.append('[').append(a[0]);
843:                for (int i = 1; i < a.length; i++)
844:                    buf.append(", ").append(a[i]);
845:                buf.append(']');
846:                return buf.toString();
847:            }
848:
849:            /**
850:             * @since 1.5
851:             */
852:            public static String toString(Object[] a) {
853:                if (a == null)
854:                    return "null";
855:                if (a.length == 0)
856:                    return "[]";
857:                StringBuffer buf = new StringBuffer();
858:                buf.append('[').append(a[0]);
859:                for (int i = 1; i < a.length; i++)
860:                    buf.append(", ").append(a[i]);
861:                buf.append(']');
862:                return buf.toString();
863:            }
864:
865:            /**
866:             * @since 1.5
867:             */
868:            public static String deepToString(Object[] a) {
869:                if (a == null)
870:                    return "null";
871:                StringBuffer buf = new StringBuffer();
872:                deepToString(a, buf, new ArrayList());
873:                return buf.toString();
874:            }
875:
876:            private static void deepToString(Object[] a, StringBuffer buf,
877:                    List seen) {
878:                seen.add(a);
879:                buf.append('[');
880:                for (int i = 0; i < a.length; i++) {
881:                    if (i > 0)
882:                        buf.append(", ");
883:                    Object e = a[i];
884:                    if (e == null) {
885:                        buf.append("null");
886:                    } else if (!e.getClass().isArray()) {
887:                        buf.append(e.toString());
888:                    } else if (e instanceof  Object[]) {
889:                        if (seen.contains(e))
890:                            buf.append("[...]");
891:                        else
892:                            deepToString((Object[]) e, buf, seen);
893:                    } else {
894:                        // primitive arr
895:                        buf
896:                                .append((e instanceof  byte[]) ? toString((byte[]) e)
897:                                        : (e instanceof  short[]) ? toString((short[]) e)
898:                                                : (e instanceof  int[]) ? toString((int[]) e)
899:                                                        : (e instanceof  long[]) ? toString((long[]) e)
900:                                                                : (e instanceof  char[]) ? toString((char[]) e)
901:                                                                        : (e instanceof  boolean[]) ? toString((boolean[]) e)
902:                                                                                : (e instanceof  float[]) ? toString((float[]) e)
903:                                                                                        : (e instanceof  double[]) ? toString((double[]) e)
904:                                                                                                : "");
905:                    }
906:                }
907:                buf.append(']');
908:                seen.remove(seen.size() - 1);
909:            }
910:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.