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:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user