diff options
| author | Aaron Huang <huangaaron@google.com> | 2022-01-20 04:09:00 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-01-20 04:09:00 +0000 |
| commit | 589a43475c11d67a02f096616a4c67dad57dbaac (patch) | |
| tree | 0166760d33aff4d863f9b2b07c7f1b01e545f23f /framework-t/src | |
| parent | 64f906a06aca9601ec7f36cb3b37311b12d036f8 (diff) | |
| parent | 1cad2ea6518cda5bd7031c80b529c466674b98bc (diff) | |
Merge "Have NetworkStats implements iterable"
Diffstat (limited to 'framework-t/src')
| -rw-r--r-- | framework-t/src/android/net/NetworkStats.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/framework-t/src/android/net/NetworkStats.java b/framework-t/src/android/net/NetworkStats.java index 9d532e7929..9175809d9c 100644 --- a/framework-t/src/android/net/NetworkStats.java +++ b/framework-t/src/android/net/NetworkStats.java @@ -41,6 +41,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Arrays; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; @@ -57,7 +58,7 @@ import java.util.function.Predicate; */ // @NotThreadSafe @SystemApi -public final class NetworkStats implements Parcelable { +public final class NetworkStats implements Parcelable, Iterable<NetworkStats.Entry> { private static final String TAG = "NetworkStats"; /** @@ -678,6 +679,35 @@ public final class NetworkStats implements Parcelable { } /** + * Iterate over Entry objects. + * + * Return an iterator of this object that will iterate through all contained Entry objects. + * + * This iterator does not support concurrent modification and makes no guarantee of fail-fast + * behavior. If any method that can mutate the contents of this object is called while + * iteration is in progress, either inside the loop or in another thread, then behavior is + * undefined. + * The remove() method is not implemented and will throw UnsupportedOperationException. + * @hide + */ + @SystemApi + @NonNull public Iterator<Entry> iterator() { + return new Iterator<Entry>() { + int mIndex = 0; + + @Override + public boolean hasNext() { + return mIndex < size; + } + + @Override + public Entry next() { + return getValues(mIndex++, null); + } + }; + } + + /** * Return specific stats entry. * @hide */ |
