summaryrefslogtreecommitdiff
path: root/core/java/android/util/SparseIntArray.java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2013-07-16 13:23:55 -0700
committerDianne Hackborn <hackbod@google.com>2013-07-16 17:08:04 -0700
commit3e82ba1a67b0c756ab6a289985f4cfc53725b311 (patch)
tree1683ef4d66151ff27b7afe1c7257abceee69654b /core/java/android/util/SparseIntArray.java
parentcdae0f3c608ed5aee5ddbdf9c54ac86a5619e64b (diff)
Make ArrayMap public! :)
Also do some tweaking of the various container classes to synchronize them with the support lib and make it easier to copy code between the two. And update activity/fragment to use ArrayMap. Change-Id: I3cfe82392a17119dfc72c3d9961f64e1914f42be
Diffstat (limited to 'core/java/android/util/SparseIntArray.java')
-rw-r--r--core/java/android/util/SparseIntArray.java39
1 files changed, 33 insertions, 6 deletions
diff --git a/core/java/android/util/SparseIntArray.java b/core/java/android/util/SparseIntArray.java
index b6fb295b530f..c2bacb0906f3 100644
--- a/core/java/android/util/SparseIntArray.java
+++ b/core/java/android/util/SparseIntArray.java
@@ -54,8 +54,8 @@ public class SparseIntArray implements Cloneable {
*/
public SparseIntArray(int initialCapacity) {
if (initialCapacity == 0) {
- mKeys = SparseArray.EMPTY_INTS;
- mValues = SparseArray.EMPTY_INTS;
+ mKeys = ContainerHelpers.EMPTY_INTS;
+ mValues = ContainerHelpers.EMPTY_INTS;
} else {
initialCapacity = ArrayUtils.idealIntArraySize(initialCapacity);
mKeys = new int[initialCapacity];
@@ -90,7 +90,7 @@ public class SparseIntArray implements Cloneable {
* if no such mapping has been made.
*/
public int get(int key, int valueIfKeyNotFound) {
- int i = SparseArray.binarySearch(mKeys, mSize, key);
+ int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
if (i < 0) {
return valueIfKeyNotFound;
@@ -103,7 +103,7 @@ public class SparseIntArray implements Cloneable {
* Removes the mapping from the specified key, if there was any.
*/
public void delete(int key) {
- int i = SparseArray.binarySearch(mKeys, mSize, key);
+ int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
if (i >= 0) {
removeAt(i);
@@ -125,7 +125,7 @@ public class SparseIntArray implements Cloneable {
* was one.
*/
public void put(int key, int value) {
- int i = SparseArray.binarySearch(mKeys, mSize, key);
+ int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
if (i >= 0) {
mValues[i] = value;
@@ -190,7 +190,7 @@ public class SparseIntArray implements Cloneable {
* key is not mapped.
*/
public int indexOfKey(int key) {
- return SparseArray.binarySearch(mKeys, mSize, key);
+ return ContainerHelpers.binarySearch(mKeys, mSize, key);
}
/**
@@ -245,4 +245,31 @@ public class SparseIntArray implements Cloneable {
mValues[pos] = value;
mSize = pos + 1;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p>This implementation composes a string by iterating over its mappings.
+ */
+ @Override
+ public String toString() {
+ if (size() <= 0) {
+ return "{}";
+ }
+
+ StringBuilder buffer = new StringBuilder(mSize * 28);
+ buffer.append('{');
+ for (int i=0; i<mSize; i++) {
+ if (i > 0) {
+ buffer.append(", ");
+ }
+ int key = keyAt(i);
+ buffer.append(key);
+ buffer.append('=');
+ int value = valueAt(i);
+ buffer.append(value);
+ }
+ buffer.append('}');
+ return buffer.toString();
+ }
}