Package ru.objectsfill.core
Class RandomValue
java.lang.Object
ru.objectsfill.core.RandomValue
Main entry point for populating POJO classes with random data.
Provides static methods for filling single objects, collections, arrays, and streams.
Basic usage:
MyClass obj = RandomValue.fill(MyClass.class);
Advanced usage with Fill builder:
MyClass obj = RandomValue.fill(
Fill.object(MyClass.class)
.collectionSize(10)
.valueLength(15)
.gen());
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TCreates a new instance of the given class and fills it with random values using default parameters.static <T> TFills the given object instance with random values using default parameters.static <T> TFills the given object with random values using the provided configuration.static <T> T[]Creates and fills an array with randomly generated elements.static <T extends Collection<K>,K>
voidfillCollection(T collection, Fill fill) Populates the given collection with randomly generated elements.static <K> KfillSingleVal(Fill fill) Generates a single random value of the type specified in theFillconfiguration.static <K> Stream<K>fillStream(Fill fill) Creates a stream of randomly generated elements.
-
Method Details
-
fill
Fills the given object with random values using the provided configuration.- Type Parameters:
T- the type of the target object- Parameters:
fill- the configuration object describing the target object and generation parameters- Returns:
- the filled object
-
fill
Fills the given object instance with random values using default parameters.- Type Parameters:
T- the type of the target object- Parameters:
object- the object instance to fill- Returns:
- the filled object
-
fill
Creates a new instance of the given class and fills it with random values using default parameters.- Type Parameters:
T- the type of the target object- Parameters:
clazz- the class to instantiate and fill- Returns:
- the filled object
-
fillCollection
Populates the given collection with randomly generated elements. The number of elements is determined byFill.getCollectionSize(). If a mutation function is configured viaExtend.wrapByFunction(java.util.function.UnaryOperator<java.lang.Object>), each generated element is transformed through it before being added.- Type Parameters:
T- the collection typeK- the type of elements in the collection- Parameters:
collection- the collection to populatefill- the configuration describing the element type and generation parameters
-
fillStream
Creates a stream of randomly generated elements. The stream size is determined byFill.getCollectionSize(). If a mutation function is configured, each element is transformed through it.- Type Parameters:
K- the type of stream elements- Parameters:
fill- the configuration describing the element type and generation parameters- Returns:
- a finite stream of randomly generated elements
-
fillArray
Creates and fills an array with randomly generated elements. The array size is determined byFill.getCollectionSize().- Type Parameters:
T- the component type of the array- Parameters:
fill- the configuration describing the element type and generation parameters- Returns:
- the filled array
-
fillSingleVal
Generates a single random value of the type specified in theFillconfiguration. If a mutation function is configured, the generated value is transformed through it.- Type Parameters:
K- the type of the generated value- Parameters:
fill- the configuration describing the value type and generation parameters- Returns:
- the generated value
-