From ea61e20a524305d4ebf6fb5d47d13b9c6336bd6a Mon Sep 17 00:00:00 2001 From: shaper Date: Thu, 5 Dec 2002 22:11:03 +0000 Subject: [PATCH] Added indexOf() for float arrays. git-svn-id: https://samskivert.googlecode.com/svn/trunk@962 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/ArrayUtil.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/ArrayUtil.java b/projects/samskivert/src/java/com/samskivert/util/ArrayUtil.java index b4bd709c..bfe70a0e 100644 --- a/projects/samskivert/src/java/com/samskivert/util/ArrayUtil.java +++ b/projects/samskivert/src/java/com/samskivert/util/ArrayUtil.java @@ -1,5 +1,5 @@ // -// $Id: ArrayUtil.java,v 1.20 2002/12/03 23:55:52 shaper Exp $ +// $Id: ArrayUtil.java,v 1.21 2002/12/05 22:11:03 shaper Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Walter Korman @@ -127,6 +127,25 @@ public class ArrayUtil return maxes; } + /** + * 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 (float[] values, float value) + { + int idx = -1; + int count = (values == null) ? 0 : values.length; + for (int ii = 0; ii < count; ii++) { + if (values[ii] == value) { + return ii; + } + } + return idx; + } + /** * Reverses the elements in the given array. *