commit | a620c39b669eae24ccc83a05f0dfabcab4cc4259 | [log] [tgz] |
---|---|---|
author | Paul Hu <paulhu@google.com> | Tue Feb 23 22:46:51 2021 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Tue Feb 23 22:46:51 2021 +0000 |
tree | 53426c3c5ac7f68fed22c7722ca2fac06684e5e8 | |
parent | 019601fb36f16d45d9bf8c5024f38e0aeeb33c1a [diff] | |
parent | 499578ad17f271cb366a80d462012a10ea6e2d45 [diff] |
Merge "Add indexOf method" am: 2318c7f334 am: 334a56ba7d Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1560368 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Iaae2cc70b299b924991263d942097096f6b5f0b5
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; } }