2015-04-20 15:36:01 -07:00
|
|
|
//: net/mindview/util/Generated.java
|
|
|
|
package net.mindview.util;
|
|
|
|
|
|
|
|
public class Generated {
|
|
|
|
// Fill an existing array:
|
|
|
|
public static <T> T[] array(T[] a, Generator<T> gen) {
|
2015-05-05 11:20:13 -07:00
|
|
|
return new CollectionData<>(gen, a.length).toArray(a);
|
2015-04-20 15:36:01 -07:00
|
|
|
}
|
|
|
|
// Create a new array:
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static <T> T[] array(Class<T> type,
|
|
|
|
Generator<T> gen, int size) {
|
|
|
|
T[] a =
|
|
|
|
(T[])java.lang.reflect.Array.newInstance(type, size);
|
2015-05-05 11:20:13 -07:00
|
|
|
return new CollectionData<>(gen, size).toArray(a);
|
2015-04-20 15:36:01 -07:00
|
|
|
}
|
2015-05-05 11:20:13 -07:00
|
|
|
} ///:~
|