-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionDataTest.java
More file actions
44 lines (33 loc) · 986 Bytes
/
CollectionDataTest.java
File metadata and controls
44 lines (33 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package btp.oneP;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Set;
public class CollectionDataTest {
public static void main(String[] args) {
Set<String> set = new LinkedHashSet<String>(new CollectionData<String>(new Government(),7));
set.addAll(CollectionData.list(new Government(), 7));
System.out.println(set);
}
}
class CollectionData<T> extends ArrayList<T> {
public CollectionData(GeneratorN<T> gen,int quantity){
for(int i=0;i<quantity;i++){
this.add(gen.next());
}
}
public static <T> CollectionData<T> list(GeneratorN<T> gen,int quantity){
return new CollectionData<T>(gen,quantity);
}
}
interface GeneratorN<T>{
T next();
}
class Government implements GeneratorN<String>{
String[] foundation = "you are a hero not a coward".split(" ");
private int index;
@Override
public String next() {
// TODO Auto-generated method stub
return foundation[index++];
}
}