Merge "Add indexOf method" am: 2318c7f334

Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1560368

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I6bd6108ca913d493dc70bd4c2eb986077e6d6606
diff --git a/staticlibs/framework/com/android/net/module/util/CollectionUtils.java b/staticlibs/framework/com/android/net/module/util/CollectionUtils.java
index cb1e3e7..e5bb58d 100644
--- a/staticlibs/framework/com/android/net/module/util/CollectionUtils.java
+++ b/staticlibs/framework/com/android/net/module/util/CollectionUtils.java
@@ -117,12 +117,17 @@
      * @return true if the array contains the specified value.
      */
     public static <T> boolean contains(@Nullable T[] array, @Nullable T value) {
-        if (array == null) return false;
-        for (T element : array) {
-            if (Objects.equals(element, value)) {
-                return true;
-            }
+        return indexOf(array, value) != -1;
+    }
+
+    /**
+     * Return first index of value in given array, or -1 if not found.
+     */
+    public static <T> int indexOf(@Nullable T[] array, @Nullable T value) {
+        if (array == null) return -1;
+        for (int i = 0; i < array.length; i++) {
+            if (Objects.equals(array[i], value)) return i;
         }
-        return false;
+        return -1;
     }
 }