Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 563c312e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix bug in ArrayUtils.filter."

parents 03e5b318 0dd52ce6
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -760,6 +760,7 @@ public class ArrayUtils {

    /**
     * Returns an array containing elements from the given one that match the given predicate.
     * The returned array may, in some cases, be the reference to the input array.
     */
    public static @Nullable <T> T[] filter(@Nullable T[] items,
            @NonNull IntFunction<T[]> arrayConstructor,
@@ -775,16 +776,13 @@ public class ArrayUtils {
                matchesCount++;
            }
        }
        if (matchesCount == 0) {
            return items;
        }
        if (matchesCount == items.length) {
            return items;
        }
        T[] result = arrayConstructor.apply(matchesCount);
        if (matchesCount == 0) {
            return null;
            return result;
        }
        T[] result = arrayConstructor.apply(matchesCount);
        int outIdx = 0;
        for (int i = 0; i < size; i++) {
            if (predicate.test(items[i])) {