Merge "Skip null values in Utils.safeForeach" into pi-dev
am: c5901f5a06
Change-Id: I7a715578f6e715262ccb294d2e5ea2326ae1c075
This commit is contained in:
@@ -113,10 +113,6 @@ public class ZenModeControllerImpl extends CurrentUserTracker implements ZenMode
|
||||
|
||||
@Override
|
||||
public void addCallback(Callback callback) {
|
||||
if (callback == null) {
|
||||
Slog.e(TAG, "Attempted to add a null callback.");
|
||||
return;
|
||||
}
|
||||
mCallbacks.add(callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,14 @@ public class Utils {
|
||||
|
||||
/**
|
||||
* Allows lambda iteration over a list. It is done in reverse order so it is safe
|
||||
* to add or remove items during the iteration.
|
||||
* to add or remove items during the iteration. Skips over null items.
|
||||
*/
|
||||
public static <T> void safeForeach(List<T> list, Consumer<T> c) {
|
||||
for (int i = list.size() - 1; i >= 0; i--) {
|
||||
c.accept(list.get(i));
|
||||
T item = list.get(i);
|
||||
if (item != null) {
|
||||
c.accept(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user