diff options
Diffstat (limited to 'core/java/android/util/SparseDoubleArray.java')
| -rw-r--r-- | core/java/android/util/SparseDoubleArray.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/core/java/android/util/SparseDoubleArray.java b/core/java/android/util/SparseDoubleArray.java index dc93a473fe44..ed1643df92fb 100644 --- a/core/java/android/util/SparseDoubleArray.java +++ b/core/java/android/util/SparseDoubleArray.java @@ -81,9 +81,17 @@ public class SparseDoubleArray implements Cloneable { * if no such mapping has been made. */ public double get(int key) { + return get(key, 0); + } + + /** + * Gets the double mapped from the specified key, or the specified value + * if no such mapping has been made. + */ + public double get(int key, double valueIfKeyNotFound) { final int index = mValues.indexOfKey(key); if (index < 0) { - return 0.0d; + return valueIfKeyNotFound; } return valueAt(index); } @@ -138,6 +146,13 @@ public class SparseDoubleArray implements Cloneable { } /** + * Removes all key-value mappings from this SparseDoubleArray. + */ + public void clear() { + mValues.clear(); + } + + /** * {@inheritDoc} * * <p>This implementation composes a string by iterating over its mappings. |
