diff options
author | Chris Banes <chrisbanes@google.com> | 2014-02-11 09:54:31 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-02-11 09:54:31 +0000 |
commit | c39db8c96a707af6575509474c0ce0546807f5b2 (patch) | |
tree | 8d3a4e970913c9cda4b771340a312c5b470ab9e5 /common | |
parent | 4b15bb8eccc60b045e1587b472b22d81d9a12afb (diff) | |
parent | 75781ee0b837cff56da8454975bcbc9eed7ab1d5 (diff) | |
download | android-c39db8c96a707af6575509474c0ce0546807f5b2.tar.gz |
am 75781ee0: am e8362a50: Add randomList() method to Cheeses dummy data class
* commit '75781ee0b837cff56da8454975bcbc9eed7ab1d5':
Add randomList() method to Cheeses dummy data class
Diffstat (limited to 'common')
-rw-r--r-- | common/src/java/com/example/android/common/dummydata/Cheeses.java | 20 |
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); + } +} |