Merge "Have NetworkStats implements iterable" am: 589a43475c

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1952101

Change-Id: I619d194086dfe6b88680e0a72e407694c02d3a2e
This commit is contained in:
Aaron Huang
2022-01-20 04:21:37 +00:00
committed by Automerger Merge Worker

View File

@@ -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";
/**
@@ -677,6 +678,35 @@ public final class NetworkStats implements Parcelable {
operations[i] = entry.operations;
}
/**
* 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