From 5771302ca13c31cb85f17bc58da8f6f8227c9b85 Mon Sep 17 00:00:00 2001
From: Flavio Lerda
Date: Sun, 8 Sep 2013 18:04:58 +0100
Subject: 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
---
core/java/android/util/SparseBooleanArray.java | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
(limited to 'core/java/android/util/SparseBooleanArray.java')
diff --git a/core/java/android/util/SparseBooleanArray.java b/core/java/android/util/SparseBooleanArray.java
index da196d78161d..68487e391710 100644
--- a/core/java/android/util/SparseBooleanArray.java
+++ b/core/java/android/util/SparseBooleanArray.java
@@ -33,6 +33,12 @@ import com.android.internal.util.ArrayUtils;
* HashMap, since lookups require a binary search and adds and removes require inserting
* and deleting entries in the array. For containers holding up to hundreds of items,
* the performance difference is not significant, less than 50%.
+ *
+ * It is possible to iterate over the items in this container using
+ * {@link #keyAt(int)} and {@link #valueAt(int)}. Iterating over the keys using
+ * keyAt(int) 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 valueAt(int).
*/
public class SparseBooleanArray implements Cloneable {
/**
@@ -159,16 +165,27 @@ public class SparseBooleanArray implements Cloneable {
/**
* Given an index in the range 0...size()-1, returns
* the key from the indexth key-value mapping that this
- * SparseBooleanArray stores.
+ * SparseBooleanArray stores.
+ *
+ * The keys corresponding to indices in ascending order are guaranteed to
+ * be in ascending order, e.g., keyAt(0) will return the
+ * smallest key and keyAt(size()-1) will return the largest
+ * key.
*/
public int keyAt(int index) {
return mKeys[index];
}
-
+
/**
* Given an index in the range 0...size()-1, returns
* the value from the indexth key-value mapping that this
- * SparseBooleanArray stores.
+ * SparseBooleanArray stores.
+ *
+ * The values corresponding to indices in ascending order are guaranteed
+ * to be associated with keys in ascending order, e.g.,
+ * valueAt(0) will return the value associated with the
+ * smallest key and valueAt(size()-1) will return the value
+ * associated with the largest key.
*/
public boolean valueAt(int index) {
return mValues[index];
--
cgit v1.2.3