Esempio n. 1
0
 /** @param args */
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   Generator<CountedObject> gen = BasicGenerator.create(CountedObject.class);
   for (int i = 0; i < 5; i++) {
     System.out.println(gen.next());
   }
 }
 public static <T> List<T> fill(List<T> c, Generator<T> gen, int n) {
   System.out.println("List");
   for (int i = 0; i < n; i++) {
     c.add(gen.next());
   }
   return c;
 }
Esempio n. 3
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       for (int i = 0; i < ExchangerDemo.size; i++) holder.add(generator.next());
       // Exchange full for empty:
       holder = exchanger.exchange(holder);
     }
   } catch (InterruptedException e) {
     // OK to terminate this way.
   }
 }
 public static void main(String[] args) {
   Generator<CountedObject> gen = BasicGenerator.create(CountedObject.class);
   for (int i = 0; i < 5; i++) System.out.println(gen.next());
 }
 public static <T> T[] fill(T[] a, Generator<T> gen) {
   for (int i = 0; i < a.length; i++) a[i] = gen.next(); // 自动包装机制不能应用于数组,因此无法工作
   return a;
 }
Esempio n. 6
0
 // Generator version:
 public static <T> void fill(Addable<T> addable, Generator<T> generator, int size) {
   for (int i = 0; i < size; i++) addable.add(generator.next());
 }
 public static <T> Collection<T> fill(Collection<T> c, Generator<T> gen, int n) {
   for (int i = 0; i < n; i++) {
     c.add(gen.next());
   }
   return c;
 }