summaryrefslogtreecommitdiff
path: root/core/java/android/util/SparseArray.java
diff options
context:
space:
mode:
authorFlavio Lerda <flerda@google.com>2013-09-08 18:04:58 +0100
committerFlavio Lerda <flerda@google.com>2013-09-08 22:29:44 +0100
commit5771302ca13c31cb85f17bc58da8f6f8227c9b85 (patch)
treeef459de53c9d138b4996f2063de215a70c3394c4 /core/java/android/util/SparseArray.java
parentd57de6afb8981dc1663d41a842ab7cdae93427a1 (diff)
Document the order of values returned by keyAt().
The values returned by keyAt() are currently guaranteed to be in ascending order. This is helpful to users of the API to be able to make assumptions about the keys and values when iterating over one of the sparse array implementations. This commit adds documentation about this. Change-Id: I3d7eb78e115ce174f1167b83904b44bf5120b223
Diffstat (limited to 'core/java/android/util/SparseArray.java')
-rw-r--r--core/java/android/util/SparseArray.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/java/android/util/SparseArray.java b/core/java/android/util/SparseArray.java
index 6e6609051aae..6e168a8b4ccd 100644
--- a/core/java/android/util/SparseArray.java
+++ b/core/java/android/util/SparseArray.java
@@ -39,6 +39,12 @@ import com.android.internal.util.ArrayUtils;
* a single garbage collection step of all removed entries. This garbage collection will
* need to be performed at any time the array needs to be grown or the the map size or
* entry values are retrieved.</p>
+ *
+ * <p>It is possible to iterate over the items in this container using
+ * {@link #keyAt(int)} and {@link #valueAt(int)}. Iterating over the keys using
+ * <code>keyAt(int)</code> with ascending values of the index will return the
+ * keys in ascending order, or the values corresponding to the keys in ascending
+ * order in the case of <code>valueAt(int)<code>.</p>
*/
public class SparseArray<E> implements Cloneable {
private static final Object DELETED = new Object();
@@ -251,6 +257,11 @@ public class SparseArray<E> implements Cloneable {
* Given an index in the range <code>0...size()-1</code>, returns
* the key from the <code>index</code>th key-value mapping that this
* SparseArray stores.
+ *
+ * <p>The keys corresponding to indices in ascending order are guaranteed to
+ * be in ascending order, e.g., <code>keyAt(0)</code> will return the
+ * smallest key and <code>keyAt(size()-1)</code> will return the largest
+ * key.</p>
*/
public int keyAt(int index) {
if (mGarbage) {
@@ -264,6 +275,12 @@ public class SparseArray<E> implements Cloneable {
* Given an index in the range <code>0...size()-1</code>, returns
* the value from the <code>index</code>th key-value mapping that this
* SparseArray stores.
+ *
+ * <p>The values corresponding to indices in ascending order are guaranteed
+ * to be associated with keys in ascending order, e.g.,
+ * <code>valueAt(0)</code> will return the value associated with the
+ * smallest key and <code>valueAt(size()-1)</code> will return the value
+ * associated with the largest key.</p>
*/
@SuppressWarnings("unchecked")
public E valueAt(int index) {