aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorChris Banes <chrisbanes@google.com>2014-02-07 14:04:10 +0000
committerChris Banes <chrisbanes@google.com>2014-02-10 10:23:34 +0000
commite8362a5065acc3de05444a237cdd04deb0593eee (patch)
tree047e049a224f8462efcf4e1bdafd30cc3eeadfef /common
parent07f4ce3dfb44cc6fb2d6e86e476bc77b33596a28 (diff)
downloadandroid-e8362a5065acc3de05444a237cdd04deb0593eee.tar.gz
Add randomList() method to Cheeses dummy data class
Change-Id: If0bc908360f3509928001ffdb0e8ee9758c0168a
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);
+ }
+}