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

Commit f3b09b9c authored by Tejas Khorana's avatar Tejas Khorana
Browse files

indexOfValueByValue now uses .equals

To address the issue that indexOfValue does not compare objects by
value (using .equals). I have made a method that does the indexOfValue
operation but instead comparing Objects using equals. New method created
as it was too late to change indexOfValue itself.

Change-Id: Ie58ce279aca74ef25ce151d8f8bde769f644f0d0
parent de8ca169
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40660,6 +40660,7 @@ package android.util {
    method public E get(int, E);
    method public int indexOfKey(int);
    method public int indexOfValue(E);
    method public int indexOfValueByValue(E);
    method public int keyAt(int);
    method public void put(int, E);
    method public void remove(int);
+1 −0
Original line number Diff line number Diff line
@@ -43785,6 +43785,7 @@ package android.util {
    method public E get(int, E);
    method public int indexOfKey(int);
    method public int indexOfValue(E);
    method public int indexOfValueByValue(E);
    method public int keyAt(int);
    method public void put(int, E);
    method public void remove(int);
+1 −0
Original line number Diff line number Diff line
@@ -40741,6 +40741,7 @@ package android.util {
    method public E get(int, E);
    method public int indexOfKey(int);
    method public int indexOfValue(E);
    method public int indexOfValueByValue(E);
    method public int keyAt(int);
    method public void put(int, E);
    method public void remove(int);
+32 −2
Original line number Diff line number Diff line
@@ -346,10 +346,40 @@ public class SparseArray<E> implements Cloneable {
            gc();
        }

        for (int i = 0; i < mSize; i++)
            if (mValues[i] == value)
        for (int i = 0; i < mSize; i++) {
            if (mValues[i] == value) {
                return i;
            }
        }

        return -1;
    }

    /**
     * Returns an index for which {@link #valueAt} would return the
     * specified key, or a negative number if no keys map to the
     * specified value.
     * <p>Beware that this is a linear search, unlike lookups by key,
     * and that multiple keys can map to the same value and this will
     * find only one of them.
     * <p>Note also that this method uses {@code equals} unlike {@code indexOfValue}.
     */
    public int indexOfValueByValue(E value) {
        if (mGarbage) {
            gc();
        }

        for (int i = 0; i < mSize; i++) {
            if (value == null) {
                if (mValues[i] == null) {
                    return i;
                }
            } else {
                if (value.equals(mValues[i])) {
                    return i;
                }
            }
        }
        return -1;
    }