diff --git a/src/java/com/samskivert/util/ArrayUtil.java b/src/java/com/samskivert/util/ArrayUtil.java index a5419690..1307d0e0 100644 --- a/src/java/com/samskivert/util/ArrayUtil.java +++ b/src/java/com/samskivert/util/ArrayUtil.java @@ -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. * diff --git a/src/java/com/samskivert/util/IntListUtil.java b/src/java/com/samskivert/util/IntListUtil.java index 48f14377..0c3ddd1b 100644 --- a/src/java/com/samskivert/util/IntListUtil.java +++ b/src/java/com/samskivert/util/IntListUtil.java @@ -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); } /**