Created
August 24, 2012 17:24
-
-
Save caseycrites/3453143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.urbanairship.util; | |
import android.util.SparseArray; | |
public class SparseStringArray extends SparseArray<String> { | |
public SparseStringArray() { | |
this(10); | |
} | |
public SparseStringArray(int initialCapacity) { | |
super(initialCapacity); | |
} | |
@Override | |
public int indexOfValue(String value) { | |
int count = this.size(); | |
for (int i=0; i<count; i++) { | |
String currentValue = this.valueAt(i); | |
if ((currentValue == null && value == null) || | |
(currentValue != null && currentValue.equals(value))) { | |
return i; | |
} | |
} | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a faster version using a reduced number of checks: