diff options
author | Chalard Jean <jchalard@google.com> | 2021-04-02 10:51:14 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-04-02 10:51:14 +0000 |
commit | e57663f2c1c08ee4be34d49237f6b3f1f1c96741 (patch) | |
tree | 3b005d52d0b29a2e5f3d6f37d02d78930bd48e4e /common/framework/com/android/net/module/util/CollectionUtils.java | |
parent | b29bc7287a4ae4d2f2d0b013e4aff67e33688da0 (diff) | |
parent | 35c90d6c506b292e70b90f6ff92b60cef9910b48 (diff) | |
download | net-e57663f2c1c08ee4be34d49237f6b3f1f1c96741.tar.gz |
Merge "Add a filter function to CollectionUtils" am: f1e182b5f8 am: 8273e9af8f am: 35c90d6c50
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1659981
Change-Id: Ice5d78d052087637601a9bf29ab4217bf2a3e8a7
Diffstat (limited to 'common/framework/com/android/net/module/util/CollectionUtils.java')
-rw-r--r-- | common/framework/com/android/net/module/util/CollectionUtils.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/common/framework/com/android/net/module/util/CollectionUtils.java b/common/framework/com/android/net/module/util/CollectionUtils.java index 44d0a6e9..a62a0bca 100644 --- a/common/framework/com/android/net/module/util/CollectionUtils.java +++ b/common/framework/com/android/net/module/util/CollectionUtils.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.util.SparseArray; +import java.util.ArrayList; import java.util.Collection; import java.util.Objects; import java.util.function.Predicate; @@ -149,4 +150,21 @@ public final class CollectionUtils { } return -1; } + + /** + * Returns a new collection of elements that match the passed predicate. + * @param source the elements to filter. + * @param test the predicate to test for. + * @return a new collection containing only the source elements that satisfy the predicate. + */ + @NonNull private static <T> ArrayList<T> filter(@NonNull final Collection<T> source, + @NonNull final Predicate<T> test) { + final ArrayList<T> matches = new ArrayList<>(); + for (final T e : source) { + if (test.test(e)) { + matches.add(e); + } + } + return matches; + } } |