aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorChris Banes <chrisbanes@google.com>2014-02-11 09:37:58 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-02-11 09:37:58 +0000
commit75781ee0b837cff56da8454975bcbc9eed7ab1d5 (patch)
tree047e049a224f8462efcf4e1bdafd30cc3eeadfef /common
parentbaf217d6d4d005d48872bd4ff47ba13e241cbaf9 (diff)
parente8362a5065acc3de05444a237cdd04deb0593eee (diff)
downloadandroid-75781ee0b837cff56da8454975bcbc9eed7ab1d5.tar.gz
am e8362a50: Add randomList() method to Cheeses dummy data class
* commit 'e8362a5065acc3de05444a237cdd04deb0593eee': Add randomList() method to Cheeses dummy data class
Diffstat (limited to 'common')
-rw-r--r--common/src/java/com/example/android/common/dummydata/Cheeses.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/common/src/java/com/example/android/common/dummydata/Cheeses.java b/common/src/java/com/example/android/common/dummydata/Cheeses.java
index a386e68e..220d66a7 100644
--- a/common/src/java/com/example/android/common/dummydata/Cheeses.java
+++ b/common/src/java/com/example/android/common/dummydata/Cheeses.java
@@ -17,6 +17,8 @@
package com.example.android.common.dummydata;
import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Random;
/**
* Dummy data.
@@ -162,4 +164,20 @@ public class Cheeses {
}
return items;
}
-} \ No newline at end of file
+
+ /**
+ * Return a list of random cheeses.
+ *
+ * @param count the amount of cheeses to return.
+ */
+ public static ArrayList<String> randomList(int count) {
+ Random random = new Random();
+ HashSet<String> items = new HashSet<String>();
+
+ while (items.size() < count) {
+ items.add(CHEESES[random.nextInt(CHEESES.length)]);
+ }
+
+ return new ArrayList<String>(items);
+ }
+}