-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFillTest.java
More file actions
45 lines (35 loc) · 996 Bytes
/
FillTest.java
File metadata and controls
45 lines (35 loc) · 996 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
45
package btp.oneP;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class FillTest {
public static void main(String[] args) {
List<Contract> contracts = new ArrayList<Contract>();
Fill.fill(contracts, Contract.class, 3);
System.out.println(contracts);
Fill.fill(contracts, TitleTransfer.class, 2);
System.out.println(contracts);
SimpleQueue<Contract> cq = new SimpleQueue<Contract>();
//Fill.fill(cq, Contract.class, 3);
}
}
class Fill{
public static <T> void fill(Collection<T> collection,Class<? extends T> classToken,int size){
for(int i=0;i<size;i++){
try{
collection.add(classToken.newInstance());
}catch(Exception e){
throw new RuntimeException();
}
}
}
}
class Contract{
private static long counter;
private final long id = counter++;
public String getString(){
return this.getClass().getName()+" "+id;
}
}
class TitleTransfer extends Contract{
}