1 |
/* gnu.java.lang.ArrayHelper |
/* ArrayHelper.java -- Helper methods for handling array operations |
2 |
Copyright (C) 1998 Free Software Foundation, Inc. |
Copyright (C) 1998, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
8 |
the Free Software Foundation; either version 2, or (at your option) |
the Free Software Foundation; either version 2, or (at your option) |
9 |
any later version. |
any later version. |
10 |
|
|
11 |
GNU Classpath is distributed in the hope that it will be useful, but |
GNU Classpath is distributed in the hope that it will be useful, but |
12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
39 |
package gnu.java.lang; |
package gnu.java.lang; |
40 |
|
|
41 |
/** |
/** |
42 |
** ArrayHelper helps you do things with arrays. |
* ArrayHelper helps you do things with arrays. |
43 |
** |
* |
44 |
** @author John Keiser |
* @author John Keiser |
45 |
** @version 1.1.0, 29 Jul 1998 |
*/ |
46 |
**/ |
public class ArrayHelper |
47 |
|
{ |
48 |
public class ArrayHelper { |
/** |
49 |
public static boolean contains(Object[] array, Object searchFor) { |
* Counterpart to java.util.Collection.contains. |
50 |
return indexOf(array,searchFor) != -1; |
* |
51 |
} |
* @param array the array to search |
52 |
|
* @param searchFor the object to locate |
53 |
public static int indexOf(Object[] array, Object searchFor) { |
* @return true if some array element <code>equals(searchFor)</code> |
54 |
for(int i=0;i<array.length;i++) { |
*/ |
55 |
if(array[i].equals(searchFor)) { |
public static boolean contains(Object[] array, Object searchFor) |
56 |
return i; |
{ |
57 |
} |
return indexOf(array, searchFor) != -1; |
58 |
} |
} |
59 |
return -1; |
|
60 |
} |
/** |
61 |
|
* Counterpart to java.util.Collection.indexOf. |
62 |
public static boolean equalsArray(Object[] a, Object[] b) { |
* |
63 |
if(a.length == b.length) { |
* @param array the array to search |
64 |
for(int i=0;i<a.length;i++) { |
* @param searchFor the object to locate |
65 |
if(!a[i].equals(b[i])) { |
* @return the index of the first equal object, or -1 |
66 |
return false; |
*/ |
67 |
} |
public static int indexOf(Object[] array, Object searchFor) |
68 |
} |
{ |
69 |
return true; |
for (int i = 0; i < array.length; i++) |
70 |
} else { |
{ |
71 |
return false; |
if(array[i].equals(searchFor)) |
72 |
} |
{ |
73 |
} |
return i; |
74 |
|
} |
75 |
|
} |
76 |
|
return -1; |
77 |
|
} |
78 |
} |
} |