commit | 499578ad17f271cb366a80d462012a10ea6e2d45 | [log] [tgz] |
---|---|---|
author | Paul Hu <paulhu@google.com> | Tue Feb 23 22:11:20 2021 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Tue Feb 23 22:11:20 2021 +0000 |
tree | 53426c3c5ac7f68fed22c7722ca2fac06684e5e8 | |
parent | 95250098101c7a3ad03b68597ddc8ede578b80cf [diff] | |
parent | 985d402aea3562a59b0859dc34c617b29c3d387e [diff] |
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; } }