public class RandomFactory
extends java.lang.Object
public Employee(final String fullName, final Employee manager) {
...
}
And you created the random generator as follows:
public Object doGenerate(Class<?> type) {
return new Employee(RandomFactory.getRandomValue(String.class),
(Employee) RandomFactory.getRandomValue(Employee.class));
}
This would potentially cause a stack over-flow since there is a cyclic dependency of Employee on itself. So to
prevent stack over-flow (which would occur by trying to create a manager for every manager), this Factory has built
in protection (using GeneratedRandomValues) to prevent such a thing by recording for a current recursive call
if it's seen this type before, if so, it will return null the second time around.| Constructor and Description |
|---|
RandomFactory() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addRandomGenerator(RandomGenerator generator)
Add a random generator to the list of available generators.
|
static <T> T |
getRandomValue(java.lang.Class<T> type)
This method generates a random value of the requested type.
If the requested type isn't registered in the factory, an RandomGeneratorException will be thrown. |
static java.lang.Object |
getRandomValue(Parameterizable parameterizable) |
public static void addRandomGenerator(RandomGenerator generator)
generator - The generator to add.public static <T> T getRandomValue(java.lang.Class<T> type)
T - The class type to generate an object for.type - The type to get a random value of.public static java.lang.Object getRandomValue(Parameterizable parameterizable)
Copyright © 2010-2015. All Rights Reserved.