From 7202cbd84e5461d3dad34971f98bffccc5934897 Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 10 Jun 2008 20:28:57 +0000 Subject: [PATCH] There's an indexOf in ListUtil, but that cannot find a null in an array. Here's one suggested by Dave. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2324 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/util/ArrayUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/java/com/samskivert/util/ArrayUtil.java b/src/java/com/samskivert/util/ArrayUtil.java index c4da7245..3109cfd1 100644 --- a/src/java/com/samskivert/util/ArrayUtil.java +++ b/src/java/com/samskivert/util/ArrayUtil.java @@ -31,6 +31,24 @@ import java.util.Random; */ public class ArrayUtil { + /** + * Looks for an element that tests true for Object equality with 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 (T[] values, T value) + { + int count = (values == null) ? 0 : values.length; + for (int ii = 0; ii < count; ii++) { + if (ObjectUtil.equals(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.