Class RandomValue

java.lang.Object
ru.objectsfill.core.RandomValue

public final class RandomValue extends Object
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 Type
    Method
    Description
    static <T> T
    fill(Class<?> clazz)
    Creates a new instance of the given class and fills it with random values using default parameters.
    static <T> T
    fill(Object object)
    Fills the given object instance with random values using default parameters.
    static <T> T
    fill(Fill fill)
    Fills 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>
    void
    fillCollection(T collection, Fill fill)
    Populates the given collection with randomly generated elements.
    static <K> K
    Generates a single random value of the type specified in the Fill configuration.
    static <K> Stream<K>
    Creates a stream of randomly generated elements.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • fill

      public static <T> T fill(Fill 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

      public static <T> T fill(Object object)
      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

      public static <T> T fill(Class<?> clazz)
      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

      public static <T extends Collection<K>, K> void fillCollection(T collection, Fill fill)
      Populates the given collection with randomly generated elements. The number of elements is determined by Fill.getCollectionSize(). If a mutation function is configured via Extend.wrapByFunction(java.util.function.UnaryOperator<java.lang.Object>), each generated element is transformed through it before being added.
      Type Parameters:
      T - the collection type
      K - the type of elements in the collection
      Parameters:
      collection - the collection to populate
      fill - the configuration describing the element type and generation parameters
    • fillStream

      public static <K> Stream<K> fillStream(Fill fill)
      Creates a stream of randomly generated elements. The stream size is determined by Fill.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

      public static <T> T[] fillArray(Fill fill)
      Creates and fills an array with randomly generated elements. The array size is determined by Fill.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

      public static <K> K fillSingleVal(Fill fill)
      Generates a single random value of the type specified in the Fill configuration. 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