49 lines
2.0 KiB
Java
49 lines
2.0 KiB
Java
// arrays/TestArrayGeneration.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
// Test the tools that use generators to fill arrays.
|
|
import java.util.*;
|
|
import onjava.*;
|
|
|
|
public class TestArrayGeneration {
|
|
public static void main(String[] args) {
|
|
int size = 6;
|
|
boolean[] a1 = ConvertTo.primitive(Generated.array(
|
|
Boolean.class, new RandomSupplier.Boolean(), size));
|
|
System.out.println("a1 = " + Arrays.toString(a1));
|
|
byte[] a2 = ConvertTo.primitive(Generated.array(
|
|
Byte.class, new RandomSupplier.Byte(), size));
|
|
System.out.println("a2 = " + Arrays.toString(a2));
|
|
char[] a3 = ConvertTo.primitive(Generated.array(
|
|
Character.class,
|
|
new RandomSupplier.Character(), size));
|
|
System.out.println("a3 = " + Arrays.toString(a3));
|
|
short[] a4 = ConvertTo.primitive(Generated.array(
|
|
Short.class, new RandomSupplier.Short(), size));
|
|
System.out.println("a4 = " + Arrays.toString(a4));
|
|
int[] a5 = ConvertTo.primitive(Generated.array(
|
|
Integer.class, new RandomSupplier.Integer(), size));
|
|
System.out.println("a5 = " + Arrays.toString(a5));
|
|
long[] a6 = ConvertTo.primitive(Generated.array(
|
|
Long.class, new RandomSupplier.Long(), size));
|
|
System.out.println("a6 = " + Arrays.toString(a6));
|
|
float[] a7 = ConvertTo.primitive(Generated.array(
|
|
Float.class, new RandomSupplier.Float(), size));
|
|
System.out.println("a7 = " + Arrays.toString(a7));
|
|
double[] a8 = ConvertTo.primitive(Generated.array(
|
|
Double.class, new RandomSupplier.Double(), size));
|
|
System.out.println("a8 = " + Arrays.toString(a8));
|
|
}
|
|
}
|
|
/* Output:
|
|
a1 = [true, false, true, false, false, true]
|
|
a2 = [104, -79, -76, 126, 33, -64]
|
|
a3 = [Z, n, T, c, Q, r]
|
|
a4 = [-13408, 22612, 15401, 15161, -28466, -12603]
|
|
a5 = [7704, 7383, 7706, 575, 8410, 6342]
|
|
a6 = [7674, 8804, 8950, 7826, 4322, 896]
|
|
a7 = [0.01, 0.2, 0.4, 0.79, 0.27, 0.45]
|
|
a8 = [0.16, 0.87, 0.7, 0.66, 0.87, 0.59]
|
|
*/
|