1414import static ru .objectsfill .utils .FieldUtils .getObjectUnaryOperator ;
1515
1616/**
17- The RandomValue class is designed to populate POJO classes with random data.
17+ * Main entry point for populating POJO classes with random data.
18+ * Provides static methods for filling single objects, collections, arrays, and streams.
19+ *
20+ * <p>Basic usage:
21+ * <pre>{@code
22+ * MyClass obj = RandomValue.fill(MyClass.class);
23+ * }</pre>
24+ *
25+ * <p>Advanced usage with {@link Fill} builder:
26+ * <pre>{@code
27+ * MyClass obj = RandomValue.fill(
28+ * Fill.object(MyClass.class)
29+ * .collectionSize(10)
30+ * .valueLength(15)
31+ * .gen());
32+ * }</pre>
1833 */
1934public final class RandomValue {
2035
@@ -23,11 +38,11 @@ private RandomValue() {
2338 }
2439
2540 /**
26-
27- Fills the given object with random values.
28- @param fill The object containing all the information about the target object.
29- @param <T> The type of the target object.
30- @return The filled object.
41+ * Fills the given object with random values using the provided configuration.
42+ *
43+ * @param fill the configuration object describing the target object and generation parameters
44+ * @param <T> the type of the target object
45+ * @return the filled object
3146 */
3247 @ SuppressWarnings ("unchecked" )
3348 public static <T > T fill (Fill fill ) {
@@ -36,34 +51,39 @@ public static <T> T fill(Fill fill) {
3651 }
3752
3853 /**
39- Fills the given object with random values shorter.
40- @param object The object to create fill.
41- @param <T> The type of the target object.
42- @return The filled object.
54+ * Fills the given object instance with random values using default parameters.
55+ *
56+ * @param object the object instance to fill
57+ * @param <T> the type of the target object
58+ * @return the filled object
4359 */
4460 public static <T > T fill (Object object ) {
4561 Fill gen = Fill .object (object ).gen ();
4662 return fill (gen );
4763 }
4864
4965 /**
50- Fills the given object with random values shorter.
51- @param clazz The class to create fill.
52- @param <T> The type of the target object.
53- @return The filled object.
66+ * Creates a new instance of the given class and fills it with random values using default parameters.
67+ *
68+ * @param clazz the class to instantiate and fill
69+ * @param <T> the type of the target object
70+ * @return the filled object
5471 */
5572 public static <T > T fill (Class <?> clazz ) {
5673 Fill gen = Fill .object (clazz ).gen ();
5774 return fill (gen );
5875 }
5976
6077 /**
61-
62- Fills the given collection with random values.
63- @param collection The collection type for populating.
64- @param fill The object containing all the information about the target collection.
65- @param <T> The type of the collection.
66- @param <K> The type of the elements in the collection.
78+ * Populates the given collection with randomly generated elements.
79+ * The number of elements is determined by {@link Fill#getCollectionSize()}.
80+ * If a mutation function is configured via {@link ru.objectsfill.object_param.Extend#wrapByFunction},
81+ * each generated element is transformed through it before being added.
82+ *
83+ * @param collection the collection to populate
84+ * @param fill the configuration describing the element type and generation parameters
85+ * @param <T> the collection type
86+ * @param <K> the type of elements in the collection
6787 */
6888 @ SuppressWarnings ({"unchecked" , "unused" })
6989 public static <T extends Collection <K >, K > void fillCollection (T collection , Fill fill ) {
@@ -73,18 +93,20 @@ public static <T extends Collection<K>, K> void fillCollection(T collection, Fil
7393 for (int i = 0 ; i < fill .getCollectionSize (); i ++) {
7494 Object o = mutationFunction .apply (new ElementCreationService ().generateSingleValue (fill .getClazz (), fill ));
7595
76- if (o . getClass ().isAssignableFrom (fill . getClazz ())) {
96+ if (fill . getClazz ().isAssignableFrom (o . getClass ())) {
7797 collection .add ((K ) o );
7898 }
7999 }
80100 }
81101
82102 /**
83-
84- Fills the given collection with random values.
85- @param fill The object containing all the information about the target collection.
86- @param <K> The type of stream
87- @return not closed stream
103+ * Creates a stream of randomly generated elements.
104+ * The stream size is determined by {@link Fill#getCollectionSize()}.
105+ * If a mutation function is configured, each element is transformed through it.
106+ *
107+ * @param fill the configuration describing the element type and generation parameters
108+ * @param <K> the type of stream elements
109+ * @return a finite stream of randomly generated elements
88110 */
89111 @ SuppressWarnings ({"unchecked" , "unused" })
90112 public static <K > Stream <K > fillStream (Fill fill ) {
@@ -95,30 +117,33 @@ public static <K> Stream<K> fillStream(Fill fill) {
95117 for (int i = 0 ; i < fill .getCollectionSize (); i ++) {
96118 Object o = mutationFunction .apply (new ElementCreationService ().generateSingleValue (fill .getClazz (), fill ));
97119
98- if (o . getClass ().isAssignableFrom (fill . getClazz ())) {
120+ if (fill . getClazz ().isAssignableFrom (o . getClass ())) {
99121 listForStream .add ((K ) o );
100122 }
101123 }
102124 return listForStream .stream ();
103125 }
104126
105127 /**
106- Creates and fills an array with random values.
107- @param fill The object containing all the information about the target array.
108- @param <T> The type of the elements in the array.
109- @return The filled array.
128+ * Creates and fills an array with randomly generated elements.
129+ * The array size is determined by {@link Fill#getCollectionSize()}.
130+ *
131+ * @param fill the configuration describing the element type and generation parameters
132+ * @param <T> the component type of the array
133+ * @return the filled array
110134 */
111135 @ SuppressWarnings ({"unchecked" , "unused" })
112136 public static <T > T [] fillArray (Fill fill ) {
113137 return (T []) new FillArray ().createArray (fill .getClazz (), fill );
114138 }
115139
116140 /**
117-
118- Generates a single random value.
119- @param fill The object containing all the information about the target value.
120- @param <K> The type of the value.
121- @return The generated value.
141+ * Generates a single random value of the type specified in the {@link Fill} configuration.
142+ * If a mutation function is configured, the generated value is transformed through it.
143+ *
144+ * @param fill the configuration describing the value type and generation parameters
145+ * @param <K> the type of the generated value
146+ * @return the generated value
122147 */
123148 @ SuppressWarnings ({"unchecked" , "unused" })
124149 public static <K > K fillSingleVal (Fill fill ) {
0 commit comments