OnJava8-Examples/net/mindview/util/CollectionData.java

17 lines
500 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: net/mindview/util/CollectionData.java
// A Collection filled with data using a generator object.
package net.mindview.util;
import java.util.*;
public class CollectionData<T> extends ArrayList<T> {
public CollectionData(Generator<T> gen, int quantity) {
for(int i = 0; i < quantity; i++)
add(gen.next());
}
// A generic convenience method:
public static <T> CollectionData<T>
list(Generator<T> gen, int quantity) {
2015-05-05 11:20:13 -07:00
return new CollectionData<>(gen, quantity);
2015-04-20 15:36:01 -07:00
}
} ///:~