diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-06-18 09:27:23 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-06-18 09:29:56 -0700 |
commit | 43f4263a854e9043d6ae3eeaa6b227afe95f1c57 (patch) | |
tree | 2fac89585b8de96e422d4603bf2c767d73d4e877 | |
parent | b28f8c82d92b06e7eba3bcb5b5c2e9757597a7c9 (diff) | |
download | frameworks_base-43f4263a854e9043d6ae3eeaa6b227afe95f1c57.zip frameworks_base-43f4263a854e9043d6ae3eeaa6b227afe95f1c57.tar.gz frameworks_base-43f4263a854e9043d6ae3eeaa6b227afe95f1c57.tar.bz2 |
Add generic sugar for ArrayMap and ArraySet.
Change-Id: Id749bd41f2e53664c00a0199c14babd2b63087fb
-rw-r--r-- | core/java/com/google/android/collect/Maps.java | 9 | ||||
-rw-r--r-- | core/java/com/google/android/collect/Sets.java | 18 |
2 files changed, 27 insertions, 0 deletions
diff --git a/core/java/com/google/android/collect/Maps.java b/core/java/com/google/android/collect/Maps.java index d537e0c..fc2c9fe 100644 --- a/core/java/com/google/android/collect/Maps.java +++ b/core/java/com/google/android/collect/Maps.java @@ -16,6 +16,8 @@ package com.google.android.collect; +import android.util.ArrayMap; + import java.util.HashMap; /** @@ -30,4 +32,11 @@ public class Maps { public static <K, V> HashMap<K, V> newHashMap() { return new HashMap<K, V>(); } + + /** + * Creates a {@code ArrayMap} instance. + */ + public static <K, V> ArrayMap<K, V> newArrayMap() { + return new ArrayMap<K, V>(); + } } diff --git a/core/java/com/google/android/collect/Sets.java b/core/java/com/google/android/collect/Sets.java index fbfbe50..dd3cab1 100644 --- a/core/java/com/google/android/collect/Sets.java +++ b/core/java/com/google/android/collect/Sets.java @@ -16,6 +16,8 @@ package com.google.android.collect; +import android.util.ArraySet; + import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; @@ -90,4 +92,20 @@ public class Sets { return set; } + /** + * Creates a {@code ArraySet} instance. + */ + public static <E> ArraySet<E> newArraySet() { + return new ArraySet<E>(); + } + + /** + * Creates a {@code ArraySet} instance containing the given elements. + */ + public static <E> ArraySet<E> newArraySet(E... elements) { + int capacity = elements.length * 4 / 3 + 1; + ArraySet<E> set = new ArraySet<E>(capacity); + Collections.addAll(set, elements); + return set; + } } |