public class RandomGenerator
extends java.lang.Object
Every method can work statically, without the need of an instance of RandomGenerator. The random seed is initialized when the JVM load the class, the seed is the Nanosec of the moment of charge in memory. User has not to initialize this class to use it
Modifier and Type | Field and Description |
---|---|
private static java.util.Random |
rnd
seed is time from epoch
|
Constructor and Description |
---|
RandomGenerator() |
Modifier and Type | Method and Description |
---|---|
static java.util.ArrayList<java.lang.String> |
randomArrayList()
returns a random ArrayList of Strings, formatted like UUID.
|
static void |
randomAttribute(java.lang.Object obj,
java.lang.reflect.Field field)
this function permits to fill a single field of an Object. you have to
pass the object entity as Object, and the field gathered by reflection.
|
static boolean |
randomBoolean()
returns a random boolean
|
static double |
randomDouble()
returns a random double
|
static <T extends java.lang.Enum<?>> |
randomEnum(java.lang.Class<T> myEnumClass)
e.g. for Enum State: randomEnum(State.class) = return State
(State.getValue() = Approved) this function uses reflections to bring you
a random element of a Enumeration.
|
static <T> java.util.ArrayList<T> |
randomGenericArrayList(java.lang.Class<T> clazz)
This is a generic method to create a randomized Array of an unknown (and supported by this module) class.
|
static long |
randomInt()
returns a random int
|
static LocalDate |
randomLocalDate()
provides a random date formatted as LocalDate between 1970 and 2300
|
static long |
randomLong()
returns a random long
|
static PointerBus |
randomPointerBus()
this function returns a new randomized PointerBus element
|
static java.lang.String |
randomString()
returns a randomString formatted as UUID.
|
public static void randomAttribute(java.lang.Object obj, java.lang.reflect.Field field) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException, java.lang.ClassNotFoundException, java.lang.InstantiationException
This function can randomize the content of field if it is a supported type, otherwise leave the field null. Behavior of the function is not predictable with unsupported field types This function supports a small number of ArrayList fields. This function could throw a large number of Exception, due to internal use of reflection with unknown classes. Due to implementation, entityType can not reflect real type of object!
obj
- is the instance to fill. (e.g. class Car has String door, you
have to pass randomAttribute(car, doorField))field
- is the field gathered by Reflection to fill up with random
content. (e.g. Car.getClass().getAttributes()[0])java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
java.lang.ClassNotFoundException
java.lang.InstantiationException
- TODO fix entityType generation, the object must be setted as the right type.public static java.lang.String randomString()
public static boolean randomBoolean()
public static double randomDouble()
public static long randomLong()
public static long randomInt()
public static PointerBus randomPointerBus()
public static java.util.ArrayList<java.lang.String> randomArrayList()
public static <T> java.util.ArrayList<T> randomGenericArrayList(java.lang.Class<T> clazz) throws java.lang.Exception
clazz
- is the class of every element of the Array, is the parameter of the functionjava.lang.Exception
public static LocalDate randomLocalDate()
public static <T extends java.lang.Enum<?>> T randomEnum(java.lang.Class<T> myEnumClass)