Source Code Cross Referenced for ArraysUtil.java in  » Development » jodd » jodd » util » 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 » Development » jodd » jodd.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
0002:
0003:        package jodd.util;
0004:
0005:        import java.lang.reflect.Array;
0006:
0007:        /**
0008:         * More array utilities.
0009:         */
0010:        public class ArraysUtil {
0011:
0012:            // ---------------------------------------------------------------- join
0013:
0014:            /**
0015:             * Joins two arrays.
0016:             */
0017:            public static Object[] join(Object[] first, Object[] second) {
0018:                return join(first, second, null);
0019:            }
0020:
0021:            /**
0022:             * Joins two arrays.
0023:             */
0024:            public static Object[] join(Object[] first, Object[] second,
0025:                    Class elementType) {
0026:                if (elementType == null) {
0027:                    elementType = first.getClass().getComponentType();
0028:                }
0029:                Object[] temp = (Object[]) Array.newInstance(elementType,
0030:                        first.length + second.length);
0031:                System.arraycopy(first, 0, temp, 0, first.length);
0032:                System.arraycopy(second, 0, temp, first.length, second.length);
0033:                return temp;
0034:            }
0035:
0036:            /**
0037:             * Joins two arrays.
0038:             */
0039:            public static String[] join(String[] first, String[] second) {
0040:                String[] temp = new String[first.length + second.length];
0041:                System.arraycopy(first, 0, temp, 0, first.length);
0042:                System.arraycopy(second, 0, temp, first.length, second.length);
0043:                return temp;
0044:            }
0045:
0046:            /**
0047:             * Joins two arrays.
0048:             */
0049:            public static byte[] join(byte[] first, byte[] second) {
0050:                byte[] temp = new byte[first.length + second.length];
0051:                System.arraycopy(first, 0, temp, 0, first.length);
0052:                System.arraycopy(second, 0, temp, first.length, second.length);
0053:                return temp;
0054:            }
0055:
0056:            /**
0057:             * Joins two arrays.
0058:             */
0059:            public static char[] join(char[] first, char[] second) {
0060:                char[] temp = new char[first.length + second.length];
0061:                System.arraycopy(first, 0, temp, 0, first.length);
0062:                System.arraycopy(second, 0, temp, first.length, second.length);
0063:                return temp;
0064:            }
0065:
0066:            /**
0067:             * Joins two arrays.
0068:             */
0069:            public static short[] join(short[] first, short[] second) {
0070:                short[] temp = new short[first.length + second.length];
0071:                System.arraycopy(first, 0, temp, 0, first.length);
0072:                System.arraycopy(second, 0, temp, first.length, second.length);
0073:                return temp;
0074:            }
0075:
0076:            /**
0077:             * Joins two arrays.
0078:             */
0079:            public static int[] join(int[] first, int[] second) {
0080:                int[] temp = new int[first.length + second.length];
0081:                System.arraycopy(first, 0, temp, 0, first.length);
0082:                System.arraycopy(second, 0, temp, first.length, second.length);
0083:                return temp;
0084:            }
0085:
0086:            /**
0087:             * Joins two arrays.
0088:             */
0089:            public static long[] join(long[] first, long[] second) {
0090:                long[] temp = new long[first.length + second.length];
0091:                System.arraycopy(first, 0, temp, 0, first.length);
0092:                System.arraycopy(second, 0, temp, first.length, second.length);
0093:                return temp;
0094:            }
0095:
0096:            /**
0097:             * Joins two arrays.
0098:             */
0099:            public static float[] join(float[] first, float[] second) {
0100:                float[] temp = new float[first.length + second.length];
0101:                System.arraycopy(first, 0, temp, 0, first.length);
0102:                System.arraycopy(second, 0, temp, first.length, second.length);
0103:                return temp;
0104:            }
0105:
0106:            /**
0107:             * Joins two arrays.
0108:             */
0109:            public static double[] join(double[] first, double[] second) {
0110:                double[] temp = new double[first.length + second.length];
0111:                System.arraycopy(first, 0, temp, 0, first.length);
0112:                System.arraycopy(second, 0, temp, first.length, second.length);
0113:                return temp;
0114:            }
0115:
0116:            /**
0117:             * Joins two arrays.
0118:             */
0119:            public static boolean[] join(boolean[] first, boolean[] second) {
0120:                boolean[] temp = new boolean[first.length + second.length];
0121:                System.arraycopy(first, 0, temp, 0, first.length);
0122:                System.arraycopy(second, 0, temp, first.length, second.length);
0123:                return temp;
0124:            }
0125:
0126:            // ---------------------------------------------------------------- resize
0127:
0128:            /**
0129:             * Resizes an array.
0130:             */
0131:            public static Object[] resize(Object buffer[], int newSize) {
0132:                return resize(buffer, newSize, null);
0133:            }
0134:
0135:            /**
0136:             * Resizes an array.
0137:             */
0138:            public static Object[] resize(Object buffer[], int newSize,
0139:                    Class elementType) {
0140:                if (elementType == null) {
0141:                    elementType = buffer.getClass().getComponentType();
0142:                }
0143:                Object[] temp = (Object[]) Array.newInstance(elementType,
0144:                        newSize);
0145:                System.arraycopy(buffer, 0, temp, 0,
0146:                        buffer.length >= newSize ? newSize : buffer.length);
0147:                return temp;
0148:            }
0149:
0150:            /**
0151:             * Resizes an array.
0152:             */
0153:            public static String[] resize(String buffer[], int newSize) {
0154:                String temp[] = new String[newSize];
0155:                System.arraycopy(buffer, 0, temp, 0,
0156:                        buffer.length >= newSize ? newSize : buffer.length);
0157:                return temp;
0158:            }
0159:
0160:            /**
0161:             * Resizes an array.
0162:             */
0163:            public static byte[] resize(byte buffer[], int newSize) {
0164:                byte temp[] = new byte[newSize];
0165:                System.arraycopy(buffer, 0, temp, 0,
0166:                        buffer.length >= newSize ? newSize : buffer.length);
0167:                return temp;
0168:            }
0169:
0170:            /**
0171:             * Resizes an array.
0172:             */
0173:            public static char[] resize(char buffer[], int newSize) {
0174:                char temp[] = new char[newSize];
0175:                System.arraycopy(buffer, 0, temp, 0,
0176:                        buffer.length >= newSize ? newSize : buffer.length);
0177:                return temp;
0178:            }
0179:
0180:            /**
0181:             * Resizes an array.
0182:             */
0183:            public static short[] resize(short buffer[], int newSize) {
0184:                short temp[] = new short[newSize];
0185:                System.arraycopy(buffer, 0, temp, 0,
0186:                        buffer.length >= newSize ? newSize : buffer.length);
0187:                return temp;
0188:            }
0189:
0190:            /**
0191:             * Resizes an array.
0192:             */
0193:            public static int[] resize(int buffer[], int newSize) {
0194:                int temp[] = new int[newSize];
0195:                System.arraycopy(buffer, 0, temp, 0,
0196:                        buffer.length >= newSize ? newSize : buffer.length);
0197:                return temp;
0198:            }
0199:
0200:            /**
0201:             * Resizes an array.
0202:             */
0203:            public static long[] resize(long buffer[], int newSize) {
0204:                long temp[] = new long[newSize];
0205:                System.arraycopy(buffer, 0, temp, 0,
0206:                        buffer.length >= newSize ? newSize : buffer.length);
0207:                return temp;
0208:            }
0209:
0210:            /**
0211:             * Resizes an array.
0212:             */
0213:            public static float[] resize(float buffer[], int newSize) {
0214:                float temp[] = new float[newSize];
0215:                System.arraycopy(buffer, 0, temp, 0,
0216:                        buffer.length >= newSize ? newSize : buffer.length);
0217:                return temp;
0218:            }
0219:
0220:            /**
0221:             * Resizes an array.
0222:             */
0223:            public static double[] resize(double buffer[], int newSize) {
0224:                double temp[] = new double[newSize];
0225:                System.arraycopy(buffer, 0, temp, 0,
0226:                        buffer.length >= newSize ? newSize : buffer.length);
0227:                return temp;
0228:            }
0229:
0230:            /**
0231:             * Resizes an array.
0232:             */
0233:            public static boolean[] resize(boolean buffer[], int newSize) {
0234:                boolean temp[] = new boolean[newSize];
0235:                System.arraycopy(buffer, 0, temp, 0,
0236:                        buffer.length >= newSize ? newSize : buffer.length);
0237:                return temp;
0238:            }
0239:
0240:            // ---------------------------------------------------------------- subarray
0241:
0242:            /**
0243:             * Returns subarray.
0244:             */
0245:            public static Object[] subarray(Object buffer[], int offset,
0246:                    int length) {
0247:                return subarray(buffer, offset, length, null);
0248:            }
0249:
0250:            /**
0251:             * Returns subarray.
0252:             */
0253:            public static Object[] subarray(Object buffer[], int offset,
0254:                    int length, Class elementType) {
0255:                if (elementType == null) {
0256:                    elementType = buffer.getClass().getComponentType();
0257:                }
0258:                Object[] temp = (Object[]) Array.newInstance(elementType,
0259:                        length);
0260:                System.arraycopy(buffer, offset, temp, 0, length);
0261:                return temp;
0262:            }
0263:
0264:            /**
0265:             * Returns subarray.
0266:             */
0267:            public static String[] subarray(String buffer[], int offset,
0268:                    int length) {
0269:                String temp[] = new String[length];
0270:                System.arraycopy(buffer, offset, temp, 0, length);
0271:                return temp;
0272:            }
0273:
0274:            /**
0275:             * Returns subarray.
0276:             */
0277:            public static byte[] subarray(byte buffer[], int offset, int length) {
0278:                byte temp[] = new byte[length];
0279:                System.arraycopy(buffer, offset, temp, 0, length);
0280:                return temp;
0281:            }
0282:
0283:            /**
0284:             * Returns subarray.
0285:             */
0286:            public static char[] subarray(char buffer[], int offset, int length) {
0287:                char temp[] = new char[length];
0288:                System.arraycopy(buffer, offset, temp, 0, length);
0289:                return temp;
0290:            }
0291:
0292:            /**
0293:             * Returns subarray.
0294:             */
0295:            public static short[] subarray(short buffer[], int offset,
0296:                    int length) {
0297:                short temp[] = new short[length];
0298:                System.arraycopy(buffer, offset, temp, 0, length);
0299:                return temp;
0300:            }
0301:
0302:            /**
0303:             * Returns subarray.
0304:             */
0305:            public static int[] subarray(int buffer[], int offset, int length) {
0306:                int temp[] = new int[length];
0307:                System.arraycopy(buffer, offset, temp, 0, length);
0308:                return temp;
0309:            }
0310:
0311:            /**
0312:             * Returns subarray.
0313:             */
0314:            public static long[] subarray(long buffer[], int offset, int length) {
0315:                long temp[] = new long[length];
0316:                System.arraycopy(buffer, offset, temp, 0, length);
0317:                return temp;
0318:            }
0319:
0320:            /**
0321:             * Returns subarray.
0322:             */
0323:            public static float[] subarray(float buffer[], int offset,
0324:                    int length) {
0325:                float temp[] = new float[length];
0326:                System.arraycopy(buffer, offset, temp, 0, length);
0327:                return temp;
0328:            }
0329:
0330:            /**
0331:             * Returns subarray.
0332:             */
0333:            public static double[] subarray(double buffer[], int offset,
0334:                    int length) {
0335:                double temp[] = new double[length];
0336:                System.arraycopy(buffer, offset, temp, 0, length);
0337:                return temp;
0338:            }
0339:
0340:            /**
0341:             * Returns subarray.
0342:             */
0343:            public static boolean[] subarray(boolean buffer[], int offset,
0344:                    int length) {
0345:                boolean temp[] = new boolean[length];
0346:                System.arraycopy(buffer, offset, temp, 0, length);
0347:                return temp;
0348:            }
0349:
0350:            // ---------------------------------------------------------------- insert
0351:
0352:            /**
0353:             * Inserts one array into another.
0354:             */
0355:            public static Object[] insert(Object[] dest, Object[] src,
0356:                    int offset) {
0357:                return insert(dest, src, offset, null);
0358:            }
0359:
0360:            /**
0361:             * Inserts one array into another.
0362:             */
0363:            public static Object[] insert(Object[] dest, Object[] src,
0364:                    int offset, Class elementType) {
0365:                if (elementType == null) {
0366:                    elementType = dest.getClass().getComponentType();
0367:                }
0368:                Object[] temp = (Object[]) Array.newInstance(elementType,
0369:                        dest.length + src.length);
0370:                System.arraycopy(dest, 0, temp, 0, offset);
0371:                System.arraycopy(src, 0, temp, offset, src.length);
0372:                System.arraycopy(dest, offset, temp, src.length + offset,
0373:                        dest.length - offset);
0374:                return temp;
0375:            }
0376:
0377:            /**
0378:             * Inserts one array into another.
0379:             */
0380:            public static String[] insert(String[] dest, String[] src,
0381:                    int offset) {
0382:                String[] temp = new String[dest.length + src.length];
0383:                System.arraycopy(dest, 0, temp, 0, offset);
0384:                System.arraycopy(src, 0, temp, offset, src.length);
0385:                System.arraycopy(dest, offset, temp, src.length + offset,
0386:                        dest.length - offset);
0387:                return temp;
0388:            }
0389:
0390:            /**
0391:             * Inserts one array into another.
0392:             */
0393:            public static byte[] insert(byte[] dest, byte[] src, int offset) {
0394:                byte[] temp = new byte[dest.length + src.length];
0395:                System.arraycopy(dest, 0, temp, 0, offset);
0396:                System.arraycopy(src, 0, temp, offset, src.length);
0397:                System.arraycopy(dest, offset, temp, src.length + offset,
0398:                        dest.length - offset);
0399:                return temp;
0400:            }
0401:
0402:            /**
0403:             * Inserts one array into another.
0404:             */
0405:            public static char[] insert(char[] dest, char[] src, int offset) {
0406:                char[] temp = new char[dest.length + src.length];
0407:                System.arraycopy(dest, 0, temp, 0, offset);
0408:                System.arraycopy(src, 0, temp, offset, src.length);
0409:                System.arraycopy(dest, offset, temp, src.length + offset,
0410:                        dest.length - offset);
0411:                return temp;
0412:            }
0413:
0414:            /**
0415:             * Inserts one array into another.
0416:             */
0417:            public static short[] insert(short[] dest, short[] src, int offset) {
0418:                short[] temp = new short[dest.length + src.length];
0419:                System.arraycopy(dest, 0, temp, 0, offset);
0420:                System.arraycopy(src, 0, temp, offset, src.length);
0421:                System.arraycopy(dest, offset, temp, src.length + offset,
0422:                        dest.length - offset);
0423:                return temp;
0424:            }
0425:
0426:            /**
0427:             * Inserts one array into another.
0428:             */
0429:            public static int[] insert(int[] dest, int[] src, int offset) {
0430:                int[] temp = new int[dest.length + src.length];
0431:                System.arraycopy(dest, 0, temp, 0, offset);
0432:                System.arraycopy(src, 0, temp, offset, src.length);
0433:                System.arraycopy(dest, offset, temp, src.length + offset,
0434:                        dest.length - offset);
0435:                return temp;
0436:            }
0437:
0438:            /**
0439:             * Inserts one array into another.
0440:             */
0441:            public static long[] insert(long[] dest, long[] src, int offset) {
0442:                long[] temp = new long[dest.length + src.length];
0443:                System.arraycopy(dest, 0, temp, 0, offset);
0444:                System.arraycopy(src, 0, temp, offset, src.length);
0445:                System.arraycopy(dest, offset, temp, src.length + offset,
0446:                        dest.length - offset);
0447:                return temp;
0448:            }
0449:
0450:            /**
0451:             * Inserts one array into another.
0452:             */
0453:            public static float[] insert(float[] dest, float[] src, int offset) {
0454:                float[] temp = new float[dest.length + src.length];
0455:                System.arraycopy(dest, 0, temp, 0, offset);
0456:                System.arraycopy(src, 0, temp, offset, src.length);
0457:                System.arraycopy(dest, offset, temp, src.length + offset,
0458:                        dest.length - offset);
0459:                return temp;
0460:            }
0461:
0462:            /**
0463:             * Inserts one array into another.
0464:             */
0465:            public static double[] insert(double[] dest, double[] src,
0466:                    int offset) {
0467:                double[] temp = new double[dest.length + src.length];
0468:                System.arraycopy(dest, 0, temp, 0, offset);
0469:                System.arraycopy(src, 0, temp, offset, src.length);
0470:                System.arraycopy(dest, offset, temp, src.length + offset,
0471:                        dest.length - offset);
0472:                return temp;
0473:            }
0474:
0475:            /**
0476:             * Inserts one array into another.
0477:             */
0478:            public static boolean[] insert(boolean[] dest, boolean[] src,
0479:                    int offset) {
0480:                boolean[] temp = new boolean[dest.length + src.length];
0481:                System.arraycopy(dest, 0, temp, 0, offset);
0482:                System.arraycopy(src, 0, temp, offset, src.length);
0483:                System.arraycopy(dest, offset, temp, src.length + offset,
0484:                        dest.length - offset);
0485:                return temp;
0486:            }
0487:
0488:            // ---------------------------------------------------------------- insertAt
0489:
0490:            /**
0491:             * Inserts one array into another by replacing specified offset.
0492:             */
0493:            public static Object[] insertAt(Object[] dest, Object[] src,
0494:                    int offset) {
0495:                return insertAt(dest, src, offset, null);
0496:            }
0497:
0498:            /**
0499:             * Inserts one array into another by replacing specified offset.
0500:             */
0501:            public static Object[] insertAt(Object[] dest, Object[] src,
0502:                    int offset, Class elementType) {
0503:                if (elementType == null) {
0504:                    elementType = dest.getClass().getComponentType();
0505:                }
0506:                Object[] temp = (Object[]) Array.newInstance(elementType,
0507:                        dest.length + src.length - 1);
0508:                System.arraycopy(dest, 0, temp, 0, offset);
0509:                System.arraycopy(src, 0, temp, offset, src.length);
0510:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0511:                        dest.length - offset - 1);
0512:                return temp;
0513:            }
0514:
0515:            /**
0516:             * Inserts one array into another by replacing specified offset.
0517:             */
0518:            public static String[] insertAt(String[] dest, String[] src,
0519:                    int offset) {
0520:                String[] temp = new String[dest.length + src.length - 1];
0521:                System.arraycopy(dest, 0, temp, 0, offset);
0522:                System.arraycopy(src, 0, temp, offset, src.length);
0523:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0524:                        dest.length - offset - 1);
0525:                return temp;
0526:            }
0527:
0528:            /**
0529:             * Inserts one array into another by replacing specified offset.
0530:             */
0531:            public static byte[] insertAt(byte[] dest, byte[] src, int offset) {
0532:                byte[] temp = new byte[dest.length + src.length - 1];
0533:                System.arraycopy(dest, 0, temp, 0, offset);
0534:                System.arraycopy(src, 0, temp, offset, src.length);
0535:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0536:                        dest.length - offset - 1);
0537:                return temp;
0538:            }
0539:
0540:            /**
0541:             * Inserts one array into another by replacing specified offset.
0542:             */
0543:            public static char[] insertAt(char[] dest, char[] src, int offset) {
0544:                char[] temp = new char[dest.length + src.length - 1];
0545:                System.arraycopy(dest, 0, temp, 0, offset);
0546:                System.arraycopy(src, 0, temp, offset, src.length);
0547:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0548:                        dest.length - offset - 1);
0549:                return temp;
0550:            }
0551:
0552:            /**
0553:             * Inserts one array into another by replacing specified offset.
0554:             */
0555:            public static short[] insertAt(short[] dest, short[] src, int offset) {
0556:                short[] temp = new short[dest.length + src.length - 1];
0557:                System.arraycopy(dest, 0, temp, 0, offset);
0558:                System.arraycopy(src, 0, temp, offset, src.length);
0559:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0560:                        dest.length - offset - 1);
0561:                return temp;
0562:            }
0563:
0564:            /**
0565:             * Inserts one array into another by replacing specified offset.
0566:             */
0567:            public static int[] insertAt(int[] dest, int[] src, int offset) {
0568:                int[] temp = new int[dest.length + src.length - 1];
0569:                System.arraycopy(dest, 0, temp, 0, offset);
0570:                System.arraycopy(src, 0, temp, offset, src.length);
0571:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0572:                        dest.length - offset - 1);
0573:                return temp;
0574:            }
0575:
0576:            /**
0577:             * Inserts one array into another by replacing specified offset.
0578:             */
0579:            public static long[] insertAt(long[] dest, long[] src, int offset) {
0580:                long[] temp = new long[dest.length + src.length - 1];
0581:                System.arraycopy(dest, 0, temp, 0, offset);
0582:                System.arraycopy(src, 0, temp, offset, src.length);
0583:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0584:                        dest.length - offset - 1);
0585:                return temp;
0586:            }
0587:
0588:            /**
0589:             * Inserts one array into another by replacing specified offset.
0590:             */
0591:            public static float[] insertAt(float[] dest, float[] src, int offset) {
0592:                float[] temp = new float[dest.length + src.length - 1];
0593:                System.arraycopy(dest, 0, temp, 0, offset);
0594:                System.arraycopy(src, 0, temp, offset, src.length);
0595:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0596:                        dest.length - offset - 1);
0597:                return temp;
0598:            }
0599:
0600:            /**
0601:             * Inserts one array into another by replacing specified offset.
0602:             */
0603:            public static double[] insertAt(double[] dest, double[] src,
0604:                    int offset) {
0605:                double[] temp = new double[dest.length + src.length - 1];
0606:                System.arraycopy(dest, 0, temp, 0, offset);
0607:                System.arraycopy(src, 0, temp, offset, src.length);
0608:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0609:                        dest.length - offset - 1);
0610:                return temp;
0611:            }
0612:
0613:            /**
0614:             * Inserts one array into another by replacing specified offset.
0615:             */
0616:            public static boolean[] insertAt(boolean[] dest, boolean[] src,
0617:                    int offset) {
0618:                boolean[] temp = new boolean[dest.length + src.length - 1];
0619:                System.arraycopy(dest, 0, temp, 0, offset);
0620:                System.arraycopy(src, 0, temp, offset, src.length);
0621:                System.arraycopy(dest, offset + 1, temp, src.length + offset,
0622:                        dest.length - offset - 1);
0623:                return temp;
0624:            }
0625:
0626:            // ---------------------------------------------------------------- indexof
0627:
0628:            /**
0629:             * Finds the first occurence in an array.
0630:             */
0631:            public static int indexOf(byte[] array, byte value) {
0632:                for (int i = 0; i < array.length; i++) {
0633:                    if (array[i] == value) {
0634:                        return i;
0635:                    }
0636:                }
0637:                return -1;
0638:            }
0639:
0640:            /**
0641:             * Finds the first occurence in an array from specified given position.
0642:             */
0643:            public static int indexOf(byte[] array, byte value, int startIndex) {
0644:                for (int i = startIndex; i < array.length; i++) {
0645:                    if (array[i] == value) {
0646:                        return i;
0647:                    }
0648:                }
0649:                return -1;
0650:            }
0651:
0652:            /**
0653:             * Finds the first occurence in an array from specified given position and upto given length.
0654:             */
0655:            public static int indexOf(byte[] array, byte value, int startIndex,
0656:                    int endIndex) {
0657:                for (int i = startIndex; i < endIndex; i++) {
0658:                    if (array[i] == value) {
0659:                        return i;
0660:                    }
0661:                }
0662:                return -1;
0663:            }
0664:
0665:            /**
0666:             * Finds the first occurence in an array.
0667:             */
0668:            public static int indexOf(char[] array, char value) {
0669:                for (int i = 0; i < array.length; i++) {
0670:                    if (array[i] == value) {
0671:                        return i;
0672:                    }
0673:                }
0674:                return -1;
0675:            }
0676:
0677:            /**
0678:             * Finds the first occurence in an array from specified given position.
0679:             */
0680:            public static int indexOf(char[] array, char value, int startIndex) {
0681:                for (int i = startIndex; i < array.length; i++) {
0682:                    if (array[i] == value) {
0683:                        return i;
0684:                    }
0685:                }
0686:                return -1;
0687:            }
0688:
0689:            /**
0690:             * Finds the first occurence in an array from specified given position and upto given length.
0691:             */
0692:            public static int indexOf(char[] array, char value, int startIndex,
0693:                    int endIndex) {
0694:                for (int i = startIndex; i < endIndex; i++) {
0695:                    if (array[i] == value) {
0696:                        return i;
0697:                    }
0698:                }
0699:                return -1;
0700:            }
0701:
0702:            /**
0703:             * Finds the first occurence in an array.
0704:             */
0705:            public static int indexOf(short[] array, short value) {
0706:                for (int i = 0; i < array.length; i++) {
0707:                    if (array[i] == value) {
0708:                        return i;
0709:                    }
0710:                }
0711:                return -1;
0712:            }
0713:
0714:            /**
0715:             * Finds the first occurence in an array from specified given position.
0716:             */
0717:            public static int indexOf(short[] array, short value, int startIndex) {
0718:                for (int i = startIndex; i < array.length; i++) {
0719:                    if (array[i] == value) {
0720:                        return i;
0721:                    }
0722:                }
0723:                return -1;
0724:            }
0725:
0726:            /**
0727:             * Finds the first occurence in an array from specified given position and upto given length.
0728:             */
0729:            public static int indexOf(short[] array, short value,
0730:                    int startIndex, int endIndex) {
0731:                for (int i = startIndex; i < endIndex; i++) {
0732:                    if (array[i] == value) {
0733:                        return i;
0734:                    }
0735:                }
0736:                return -1;
0737:            }
0738:
0739:            /**
0740:             * Finds the first occurence in an array.
0741:             */
0742:            public static int indexOf(int[] array, int value) {
0743:                for (int i = 0; i < array.length; i++) {
0744:                    if (array[i] == value) {
0745:                        return i;
0746:                    }
0747:                }
0748:                return -1;
0749:            }
0750:
0751:            /**
0752:             * Finds the first occurence in an array from specified given position.
0753:             */
0754:            public static int indexOf(int[] array, int value, int startIndex) {
0755:                for (int i = startIndex; i < array.length; i++) {
0756:                    if (array[i] == value) {
0757:                        return i;
0758:                    }
0759:                }
0760:                return -1;
0761:            }
0762:
0763:            /**
0764:             * Finds the first occurence in an array from specified given position and upto given length.
0765:             */
0766:            public static int indexOf(int[] array, int value, int startIndex,
0767:                    int endIndex) {
0768:                for (int i = startIndex; i < endIndex; i++) {
0769:                    if (array[i] == value) {
0770:                        return i;
0771:                    }
0772:                }
0773:                return -1;
0774:            }
0775:
0776:            /**
0777:             * Finds the first occurence in an array.
0778:             */
0779:            public static int indexOf(long[] array, long value) {
0780:                for (int i = 0; i < array.length; i++) {
0781:                    if (array[i] == value) {
0782:                        return i;
0783:                    }
0784:                }
0785:                return -1;
0786:            }
0787:
0788:            /**
0789:             * Finds the first occurence in an array from specified given position.
0790:             */
0791:            public static int indexOf(long[] array, long value, int startIndex) {
0792:                for (int i = startIndex; i < array.length; i++) {
0793:                    if (array[i] == value) {
0794:                        return i;
0795:                    }
0796:                }
0797:                return -1;
0798:            }
0799:
0800:            /**
0801:             * Finds the first occurence in an array from specified given position and upto given length.
0802:             */
0803:            public static int indexOf(long[] array, long value, int startIndex,
0804:                    int endIndex) {
0805:                for (int i = startIndex; i < endIndex; i++) {
0806:                    if (array[i] == value) {
0807:                        return i;
0808:                    }
0809:                }
0810:                return -1;
0811:            }
0812:
0813:            /**
0814:             * Finds the first occurence in an array.
0815:             */
0816:            public static int indexOf(float[] array, float value) {
0817:                for (int i = 0; i < array.length; i++) {
0818:                    if (array[i] == value) {
0819:                        return i;
0820:                    }
0821:                }
0822:                return -1;
0823:            }
0824:
0825:            /**
0826:             * Finds the first occurence in an array from specified given position.
0827:             */
0828:            public static int indexOf(float[] array, float value, int startIndex) {
0829:                for (int i = startIndex; i < array.length; i++) {
0830:                    if (array[i] == value) {
0831:                        return i;
0832:                    }
0833:                }
0834:                return -1;
0835:            }
0836:
0837:            /**
0838:             * Finds the first occurence in an array from specified given position and upto given length.
0839:             */
0840:            public static int indexOf(float[] array, float value,
0841:                    int startIndex, int endIndex) {
0842:                for (int i = startIndex; i < endIndex; i++) {
0843:                    if (array[i] == value) {
0844:                        return i;
0845:                    }
0846:                }
0847:                return -1;
0848:            }
0849:
0850:            /**
0851:             * Finds the first occurence in an array.
0852:             */
0853:            public static int indexOf(double[] array, double value) {
0854:                for (int i = 0; i < array.length; i++) {
0855:                    if (array[i] == value) {
0856:                        return i;
0857:                    }
0858:                }
0859:                return -1;
0860:            }
0861:
0862:            /**
0863:             * Finds the first occurence in an array from specified given position.
0864:             */
0865:            public static int indexOf(double[] array, double value,
0866:                    int startIndex) {
0867:                for (int i = startIndex; i < array.length; i++) {
0868:                    if (array[i] == value) {
0869:                        return i;
0870:                    }
0871:                }
0872:                return -1;
0873:            }
0874:
0875:            /**
0876:             * Finds the first occurence in an array from specified given position and upto given length.
0877:             */
0878:            public static int indexOf(double[] array, double value,
0879:                    int startIndex, int endIndex) {
0880:                for (int i = startIndex; i < endIndex; i++) {
0881:                    if (array[i] == value) {
0882:                        return i;
0883:                    }
0884:                }
0885:                return -1;
0886:            }
0887:
0888:            /**
0889:             * Finds the first occurence in an array.
0890:             */
0891:            public static int indexOf(boolean[] array, boolean value) {
0892:                for (int i = 0; i < array.length; i++) {
0893:                    if (array[i] == value) {
0894:                        return i;
0895:                    }
0896:                }
0897:                return -1;
0898:            }
0899:
0900:            /**
0901:             * Finds the first occurence in an array from specified given position.
0902:             */
0903:            public static int indexOf(boolean[] array, boolean value,
0904:                    int startIndex) {
0905:                for (int i = startIndex; i < array.length; i++) {
0906:                    if (array[i] == value) {
0907:                        return i;
0908:                    }
0909:                }
0910:                return -1;
0911:            }
0912:
0913:            /**
0914:             * Finds the first occurence in an array from specified given position and upto given length.
0915:             */
0916:            public static int indexOf(boolean[] array, boolean value,
0917:                    int startIndex, int endIndex) {
0918:                for (int i = startIndex; i < endIndex; i++) {
0919:                    if (array[i] == value) {
0920:                        return i;
0921:                    }
0922:                }
0923:                return -1;
0924:            }
0925:
0926:            // ---------------------------------------------------------------- indexof 2
0927:
0928:            /**
0929:             * Finds the first occurence in an array.
0930:             */
0931:            public static int indexOf(byte[] array, byte[] sub) {
0932:                return indexOf(array, sub, 0, array.length);
0933:            }
0934:
0935:            /**
0936:             * Finds the first occurence in an array from specified given position.
0937:             */
0938:            public static int indexOf(byte[] array, byte[] sub, int startIndex) {
0939:                return indexOf(array, sub, startIndex, array.length);
0940:            }
0941:
0942:            /**
0943:             * Finds the first occurence in an array from specified given position and upto given length.
0944:             */
0945:            public static int indexOf(byte[] array, byte[] sub, int startIndex,
0946:                    int endIndex) {
0947:                int sublen = sub.length;
0948:                if (sublen == 0) {
0949:                    return startIndex;
0950:                }
0951:                int total = endIndex - sublen + 1;
0952:                byte c = sub[0];
0953:                mainloop: for (int i = startIndex; i < total; i++) {
0954:                    if (array[i] != c) {
0955:                        continue;
0956:                    }
0957:                    int j = 1;
0958:                    int k = i + 1;
0959:                    while (j < sublen) {
0960:                        if (sub[j] != array[k]) {
0961:                            continue mainloop;
0962:                        }
0963:                        j++;
0964:                        k++;
0965:                    }
0966:                    return i;
0967:                }
0968:                return -1;
0969:            }
0970:
0971:            /**
0972:             * Finds the first occurence in an array.
0973:             */
0974:            public static int indexOf(char[] array, char[] sub) {
0975:                return indexOf(array, sub, 0, array.length);
0976:            }
0977:
0978:            /**
0979:             * Finds the first occurence in an array from specified given position.
0980:             */
0981:            public static int indexOf(char[] array, char[] sub, int startIndex) {
0982:                return indexOf(array, sub, startIndex, array.length);
0983:            }
0984:
0985:            /**
0986:             * Finds the first occurence in an array from specified given position and upto given length.
0987:             */
0988:            public static int indexOf(char[] array, char[] sub, int startIndex,
0989:                    int endIndex) {
0990:                int sublen = sub.length;
0991:                if (sublen == 0) {
0992:                    return startIndex;
0993:                }
0994:                int total = endIndex - sublen + 1;
0995:                char c = sub[0];
0996:                mainloop: for (int i = startIndex; i < total; i++) {
0997:                    if (array[i] != c) {
0998:                        continue;
0999:                    }
1000:                    int j = 1;
1001:                    int k = i + 1;
1002:                    while (j < sublen) {
1003:                        if (sub[j] != array[k]) {
1004:                            continue mainloop;
1005:                        }
1006:                        j++;
1007:                        k++;
1008:                    }
1009:                    return i;
1010:                }
1011:                return -1;
1012:            }
1013:
1014:            /**
1015:             * Finds the first occurence in an array.
1016:             */
1017:            public static int indexOf(short[] array, short[] sub) {
1018:                return indexOf(array, sub, 0, array.length);
1019:            }
1020:
1021:            /**
1022:             * Finds the first occurence in an array from specified given position.
1023:             */
1024:            public static int indexOf(short[] array, short[] sub, int startIndex) {
1025:                return indexOf(array, sub, startIndex, array.length);
1026:            }
1027:
1028:            /**
1029:             * Finds the first occurence in an array from specified given position and upto given length.
1030:             */
1031:            public static int indexOf(short[] array, short[] sub,
1032:                    int startIndex, int endIndex) {
1033:                int sublen = sub.length;
1034:                if (sublen == 0) {
1035:                    return startIndex;
1036:                }
1037:                int total = endIndex - sublen + 1;
1038:                short c = sub[0];
1039:                mainloop: for (int i = startIndex; i < total; i++) {
1040:                    if (array[i] != c) {
1041:                        continue;
1042:                    }
1043:                    int j = 1;
1044:                    int k = i + 1;
1045:                    while (j < sublen) {
1046:                        if (sub[j] != array[k]) {
1047:                            continue mainloop;
1048:                        }
1049:                        j++;
1050:                        k++;
1051:                    }
1052:                    return i;
1053:                }
1054:                return -1;
1055:            }
1056:
1057:            /**
1058:             * Finds the first occurence in an array.
1059:             */
1060:            public static int indexOf(int[] array, int[] sub) {
1061:                return indexOf(array, sub, 0, array.length);
1062:            }
1063:
1064:            /**
1065:             * Finds the first occurence in an array from specified given position.
1066:             */
1067:            public static int indexOf(int[] array, int[] sub, int startIndex) {
1068:                return indexOf(array, sub, startIndex, array.length);
1069:            }
1070:
1071:            /**
1072:             * Finds the first occurence in an array from specified given position and upto given length.
1073:             */
1074:            public static int indexOf(int[] array, int[] sub, int startIndex,
1075:                    int endIndex) {
1076:                int sublen = sub.length;
1077:                if (sublen == 0) {
1078:                    return startIndex;
1079:                }
1080:                int total = endIndex - sublen + 1;
1081:                int c = sub[0];
1082:                mainloop: for (int i = startIndex; i < total; i++) {
1083:                    if (array[i] != c) {
1084:                        continue;
1085:                    }
1086:                    int j = 1;
1087:                    int k = i + 1;
1088:                    while (j < sublen) {
1089:                        if (sub[j] != array[k]) {
1090:                            continue mainloop;
1091:                        }
1092:                        j++;
1093:                        k++;
1094:                    }
1095:                    return i;
1096:                }
1097:                return -1;
1098:            }
1099:
1100:            /**
1101:             * Finds the first occurence in an array.
1102:             */
1103:            public static int indexOf(long[] array, long[] sub) {
1104:                return indexOf(array, sub, 0, array.length);
1105:            }
1106:
1107:            /**
1108:             * Finds the first occurence in an array from specified given position.
1109:             */
1110:            public static int indexOf(long[] array, long[] sub, int startIndex) {
1111:                return indexOf(array, sub, startIndex, array.length);
1112:            }
1113:
1114:            /**
1115:             * Finds the first occurence in an array from specified given position and upto given length.
1116:             */
1117:            public static int indexOf(long[] array, long[] sub, int startIndex,
1118:                    int endIndex) {
1119:                int sublen = sub.length;
1120:                if (sublen == 0) {
1121:                    return startIndex;
1122:                }
1123:                int total = endIndex - sublen + 1;
1124:                long c = sub[0];
1125:                mainloop: for (int i = startIndex; i < total; i++) {
1126:                    if (array[i] != c) {
1127:                        continue;
1128:                    }
1129:                    int j = 1;
1130:                    int k = i + 1;
1131:                    while (j < sublen) {
1132:                        if (sub[j] != array[k]) {
1133:                            continue mainloop;
1134:                        }
1135:                        j++;
1136:                        k++;
1137:                    }
1138:                    return i;
1139:                }
1140:                return -1;
1141:            }
1142:
1143:            /**
1144:             * Finds the first occurence in an array.
1145:             */
1146:            public static int indexOf(float[] array, float[] sub) {
1147:                return indexOf(array, sub, 0, array.length);
1148:            }
1149:
1150:            /**
1151:             * Finds the first occurence in an array from specified given position.
1152:             */
1153:            public static int indexOf(float[] array, float[] sub, int startIndex) {
1154:                return indexOf(array, sub, startIndex, array.length);
1155:            }
1156:
1157:            /**
1158:             * Finds the first occurence in an array from specified given position and upto given length.
1159:             */
1160:            public static int indexOf(float[] array, float[] sub,
1161:                    int startIndex, int endIndex) {
1162:                int sublen = sub.length;
1163:                if (sublen == 0) {
1164:                    return startIndex;
1165:                }
1166:                int total = endIndex - sublen + 1;
1167:                float c = sub[0];
1168:                mainloop: for (int i = startIndex; i < total; i++) {
1169:                    if (array[i] != c) {
1170:                        continue;
1171:                    }
1172:                    int j = 1;
1173:                    int k = i + 1;
1174:                    while (j < sublen) {
1175:                        if (sub[j] != array[k]) {
1176:                            continue mainloop;
1177:                        }
1178:                        j++;
1179:                        k++;
1180:                    }
1181:                    return i;
1182:                }
1183:                return -1;
1184:            }
1185:
1186:            /**
1187:             * Finds the first occurence in an array.
1188:             */
1189:            public static int indexOf(double[] array, double[] sub) {
1190:                return indexOf(array, sub, 0, array.length);
1191:            }
1192:
1193:            /**
1194:             * Finds the first occurence in an array from specified given position.
1195:             */
1196:            public static int indexOf(double[] array, double[] sub,
1197:                    int startIndex) {
1198:                return indexOf(array, sub, startIndex, array.length);
1199:            }
1200:
1201:            /**
1202:             * Finds the first occurence in an array from specified given position and upto given length.
1203:             */
1204:            public static int indexOf(double[] array, double[] sub,
1205:                    int startIndex, int endIndex) {
1206:                int sublen = sub.length;
1207:                if (sublen == 0) {
1208:                    return startIndex;
1209:                }
1210:                int total = endIndex - sublen + 1;
1211:                double c = sub[0];
1212:                mainloop: for (int i = startIndex; i < total; i++) {
1213:                    if (array[i] != c) {
1214:                        continue;
1215:                    }
1216:                    int j = 1;
1217:                    int k = i + 1;
1218:                    while (j < sublen) {
1219:                        if (sub[j] != array[k]) {
1220:                            continue mainloop;
1221:                        }
1222:                        j++;
1223:                        k++;
1224:                    }
1225:                    return i;
1226:                }
1227:                return -1;
1228:            }
1229:
1230:            /**
1231:             * Finds the first occurence in an array.
1232:             */
1233:            public static int indexOf(boolean[] array, boolean[] sub) {
1234:                return indexOf(array, sub, 0, array.length);
1235:            }
1236:
1237:            /**
1238:             * Finds the first occurence in an array from specified given position.
1239:             */
1240:            public static int indexOf(boolean[] array, boolean[] sub,
1241:                    int startIndex) {
1242:                return indexOf(array, sub, startIndex, array.length);
1243:            }
1244:
1245:            /**
1246:             * Finds the first occurence in an array from specified given position and upto given length.
1247:             */
1248:            public static int indexOf(boolean[] array, boolean[] sub,
1249:                    int startIndex, int endIndex) {
1250:                int sublen = sub.length;
1251:                if (sublen == 0) {
1252:                    return startIndex;
1253:                }
1254:                int total = endIndex - sublen + 1;
1255:                boolean c = sub[0];
1256:                mainloop: for (int i = startIndex; i < total; i++) {
1257:                    if (array[i] != c) {
1258:                        continue;
1259:                    }
1260:                    int j = 1;
1261:                    int k = i + 1;
1262:                    while (j < sublen) {
1263:                        if (sub[j] != array[k]) {
1264:                            continue mainloop;
1265:                        }
1266:                        j++;
1267:                        k++;
1268:                    }
1269:                    return i;
1270:                }
1271:                return -1;
1272:            }
1273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.