Package org.jeasy.random
Class EasyRandom
- java.lang.Object
-
- java.util.Random
-
- org.jeasy.random.EasyRandom
-
- All Implemented Interfaces:
java.io.Serializable
public class EasyRandom extends java.util.Random
Extension ofRandom
that is able to generate random Java objects.- Author:
- Mahmoud Ben Hassine ([email protected])
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description EasyRandom()
Create a newEasyRandom
instance with default parameters.EasyRandom(EasyRandomParameters easyRandomParameters)
Create a newEasyRandom
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
nextObject(java.lang.Class<T> type)
Generate a random instance of the given type.<T> java.util.stream.Stream<T>
objects(java.lang.Class<T> type, int streamSize)
Generate a stream of random instances of the given type.
-
-
-
Constructor Detail
-
EasyRandom
public EasyRandom()
Create a newEasyRandom
instance with default parameters.
-
EasyRandom
public EasyRandom(EasyRandomParameters easyRandomParameters)
Create a newEasyRandom
instance.- Parameters:
easyRandomParameters
- randomization parameters
-
-
Method Detail
-
nextObject
public <T> T nextObject(java.lang.Class<T> type)
Generate a random instance of the given type.- Type Parameters:
T
- the actual type of the target object- Parameters:
type
- the type for which an instance will be generated- Returns:
- a random instance of the given type
- Throws:
ObjectCreationException
- when unable to create a new instance of the given type
-
objects
public <T> java.util.stream.Stream<T> objects(java.lang.Class<T> type, int streamSize)
Generate a stream of random instances of the given type.- Type Parameters:
T
- the actual type of the target objects- Parameters:
type
- the type for which instances will be generatedstreamSize
- the number of instances to generate- Returns:
- a stream of random instances of the given type
- Throws:
ObjectCreationException
- when unable to create a new instance of the given type
-
-