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

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

indexOfValue now uses .equals (cont.)

Addresses same issue addressed in SparseArray in LongSparseArray in
the method: indexByValue. Made a new method indexByValueByValue that
compares objects using .equals instead of ==.

Change-Id: I55735fe7ca364d0a9caab2a6909c2eaede845619
parent de8ca169
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40458,6 +40458,7 @@ package android.util {
    method public E get(long, E);
    method public int indexOfKey(long);
    method public int indexOfValue(E);
    method public int indexOfValueByValue(E);
    method public long keyAt(int);
    method public void put(long, E);
    method public void remove(long);
+1 −0
Original line number Diff line number Diff line
@@ -43583,6 +43583,7 @@ package android.util {
    method public E get(long, E);
    method public int indexOfKey(long);
    method public int indexOfValue(E);
    method public int indexOfValueByValue(E);
    method public long keyAt(int);
    method public void put(long, E);
    method public void remove(long);
+1 −0
Original line number Diff line number Diff line
@@ -40539,6 +40539,7 @@ package android.util {
    method public E get(long, E);
    method public int indexOfKey(long);
    method public int indexOfValue(E);
    method public int indexOfValueByValue(E);
    method public long keyAt(int);
    method public void put(long, E);
    method public void remove(long);
+31 −2
Original line number Diff line number Diff line
@@ -299,10 +299,39 @@ public class LongSparseArray<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;
    }