diff options
| author | Michael Wachenschwanz <mwachens@google.com> | 2022-01-21 10:08:12 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-01-21 10:08:12 +0000 |
| commit | 90a6c03c8fbdd4892596863bb02fd624cea4b07c (patch) | |
| tree | 2c995911f62d6cc534a4da1a3c36bd6e92d6e281 /core/java/android/util/SparseDoubleArray.java | |
| parent | f33b30dcb6c47ba4c0de6b934626f8382e51bad0 (diff) | |
| parent | b4c244ceb2beb0f2bbd7ec4aed93d0f53767a386 (diff) | |
Merge "Introduce modem element to power_profile.xml"
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 ccae92e53c5e..e8d96d8e26e4 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. |
