More changes requested by the puzzle pirates.

- Added ArrayUtil.indexOf(int[], int).
This has never been added, in all our years, because it exists in IntListUtil.
IntLists are sort of different from int[]s, they're designed such that a 0
is an empty slot. But indexOf() works the same in either one, so let's make
ArrayUtil the definitive container of this code, and have IntListUtil use
ArrayUtil.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2344 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray
2008-07-23 23:39:45 +00:00
parent a60b9da150
commit 82bd4c7f1f
2 changed files with 18 additions and 14 deletions
@@ -48,6 +48,22 @@ public class ArrayUtil
return -1;
}
/**
* Looks for an element that is equal to the supplied value and returns its index in the array.
*
* @return the index of the first matching value if one was found, 1 otherwise.
*/
public static int indexOf (int[] values, int value)
{
int count = (values == null) ? 0 : values.length;
for (int ii = 0; ii < count; ii++) {
if (values[ii] == value) {
return ii;
}
}
return -1;
}
/**
* Looks for an element that is equal to the supplied value and returns its index in the array.
*
+2 -14
View File
@@ -175,13 +175,7 @@ public class IntListUtil
*/
public static boolean contains (int[] list, int value)
{
int llength = list.length; // no optimizing bastards
for (int i = 0; i < llength; i++) {
if (list[i] == value) {
return true;
}
}
return false;
return (-1 != indexOf(list, value));
}
/**
@@ -195,13 +189,7 @@ public class IntListUtil
*/
public static int indexOf (int[] list, int value)
{
int llength = list.length; // no optimizing bastards
for (int i = 0; i < llength; i++) {
if (list[i] == value) {
return i;
}
}
return -1;
return ArrayUtil.indexOf(list, value);
}
/**