summaryrefslogtreecommitdiff
path: root/common/framework/com/android/net/module/util/CollectionUtils.java
diff options
context:
space:
mode:
authorPaul Hu <paulhu@google.com>2021-02-22 05:22:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-02-22 05:22:01 +0000
commit2318c7f33498c42831cdabc88f8463e63d5e949d (patch)
treecdca8a1a7b88f99b6d511c86aa2c0d94bce2ca1f /common/framework/com/android/net/module/util/CollectionUtils.java
parentac148e6bfe5a5d077e67764e70f3dd67cb699f3b (diff)
parent38f9fa789fd09fa22806cb850483be166e6f7de2 (diff)
downloadnet-2318c7f33498c42831cdabc88f8463e63d5e949d.tar.gz
Merge "Add indexOf method"
Diffstat (limited to 'common/framework/com/android/net/module/util/CollectionUtils.java')
-rw-r--r--common/framework/com/android/net/module/util/CollectionUtils.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/common/framework/com/android/net/module/util/CollectionUtils.java b/common/framework/com/android/net/module/util/CollectionUtils.java
index cb1e3e74..e5bb58d4 100644
--- a/common/framework/com/android/net/module/util/CollectionUtils.java
+++ b/common/framework/com/android/net/module/util/CollectionUtils.java
@@ -117,12 +117,17 @@ public final class CollectionUtils {
* @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;
}
}