Class KRandomParameters

java.lang.Object
io.github.krandom.KRandomParameters

public class KRandomParameters extends Object
Parameters of an KRandom instance.
  • Field Details

    • DEFAULT_SEED

      public static final long DEFAULT_SEED
      Default seed.
      See Also:
    • DEFAULT_CHARSET

      public static final Charset DEFAULT_CHARSET
      Default charset for Strings.
    • DEFAULT_COLLECTION_SIZE_RANGE

      public static final KRandomParameters.Range<Integer> DEFAULT_COLLECTION_SIZE_RANGE
      Default collection size range.
    • DEFAULT_OBJECT_POOL_SIZE

      public static final int DEFAULT_OBJECT_POOL_SIZE
      Number of different objects to generate for a type.
      See Also:
    • DEFAULT_RANDOMIZATION_DEPTH

      public static final int DEFAULT_RANDOMIZATION_DEPTH
      Default value for randomization depth, which mean, that randomization depth is unlimited
      See Also:
    • DEFAULT_STRING_LENGTH_RANGE

      public static final KRandomParameters.Range<Integer> DEFAULT_STRING_LENGTH_RANGE
      Default string length size.
    • DEFAULT_DATE_RANGE

      public static final int DEFAULT_DATE_RANGE
      Default date range in which dates will be generated: [now - 10 years, now + 10 years].
      See Also:
    • DEFAULT_DATES_RANGE

      public static final KRandomParameters.Range<ZonedDateTime> DEFAULT_DATES_RANGE
      Default dates range.
  • Constructor Details

    • KRandomParameters

      public KRandomParameters()
      Create a new KRandomParameters with default values.
  • Method Details

    • getCollectionSizeRange

      public KRandomParameters.Range<Integer> getCollectionSizeRange()
    • setCollectionSizeRange

      public void setCollectionSizeRange(KRandomParameters.Range<Integer> collectionSizeRange)
    • getDateRange

      public KRandomParameters.Range<LocalDate> getDateRange()
    • setDateRange

      public void setDateRange(KRandomParameters.Range<LocalDate> dateRange)
    • getTimeRange

      public KRandomParameters.Range<LocalTime> getTimeRange()
    • setTimeRange

      public void setTimeRange(KRandomParameters.Range<LocalTime> timeRange)
    • getStringLengthRange

      public KRandomParameters.Range<Integer> getStringLengthRange()
    • setStringLengthRange

      public void setStringLengthRange(KRandomParameters.Range<Integer> stringLengthRange)
    • getSeed

      public long getSeed()
    • setSeed

      public void setSeed(long seed)
    • getObjectPoolSize

      public int getObjectPoolSize()
    • setObjectPoolSize

      public void setObjectPoolSize(int objectPoolSize)
    • getRandomizationDepth

      public int getRandomizationDepth()
    • setRandomizationDepth

      public void setRandomizationDepth(int randomizationDepth)
    • getCharset

      public Charset getCharset()
    • setCharset

      public void setCharset(Charset charset)
    • isScanClasspathForConcreteTypes

      public boolean isScanClasspathForConcreteTypes()
    • setScanClasspathForConcreteTypes

      public void setScanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes)
    • isOverrideDefaultInitialization

      public boolean isOverrideDefaultInitialization()
    • setOverrideDefaultInitialization

      public void setOverrideDefaultInitialization(boolean overrideDefaultInitialization)
    • isIgnoreRandomizationErrors

      public boolean isIgnoreRandomizationErrors()
    • setIgnoreRandomizationErrors

      public void setIgnoreRandomizationErrors(boolean ignoreRandomizationErrors)
    • isBypassSetters

      public boolean isBypassSetters()
    • setBypassSetters

      public void setBypassSetters(boolean bypassSetters)
    • getExclusionPolicy

      public ExclusionPolicy getExclusionPolicy()
    • setExclusionPolicy

      public void setExclusionPolicy(ExclusionPolicy exclusionPolicy)
    • getObjectFactory

      public ObjectFactory getObjectFactory()
    • setObjectFactory

      public void setObjectFactory(ObjectFactory objectFactory)
    • getRandomizerProvider

      public RandomizerProvider getRandomizerProvider()
    • setRandomizerProvider

      public void setRandomizerProvider(RandomizerProvider randomizerProvider)
    • getFieldExclusionPredicates

      public Set<Predicate<Field>> getFieldExclusionPredicates()
    • getTypeExclusionPredicates

      public Set<Predicate<Class<?>>> getTypeExclusionPredicates()
    • randomize

      public <T> KRandomParameters randomize(Predicate<Field> predicate, Randomizer<T> randomizer)
      Register a custom randomizer for the given field predicate. The predicate must at least specify the field type
      Type Parameters:
      T - The field type
      Parameters:
      predicate - to identify the field
      randomizer - to register
      Returns:
      the current KRandomParameters instance for method chaining
      See Also:
    • randomize

      public <T> KRandomParameters randomize(Class<T> type, Randomizer<T> randomizer)
      Register a custom randomizer for a given type.
      Type Parameters:
      T - The field type
      Parameters:
      type - class of the type to randomize
      randomizer - the custom Randomizer to use
      Returns:
      the current KRandomParameters instance for method chaining
    • excludeField

      public KRandomParameters excludeField(Predicate<Field> predicate)
      Exclude a field from being randomized.
      Parameters:
      predicate - to identify the field to exclude
      Returns:
      the current KRandomParameters instance for method chaining
      See Also:
    • excludeType

      public KRandomParameters excludeType(Predicate<Class<?>> predicate)
      Exclude a type from being randomized.
      Parameters:
      predicate - to identify the type to exclude
      Returns:
      the current KRandomParameters instance for method chaining
      See Also:
    • exclusionPolicy

      public KRandomParameters exclusionPolicy(ExclusionPolicy exclusionPolicy)
      Provide a custom exclusion policy.
      Parameters:
      exclusionPolicy - to use
      Returns:
      the current KRandomParameters instance for method chaining
    • objectFactory

      public KRandomParameters objectFactory(ObjectFactory objectFactory)
      Provide a custom object factory.
      Parameters:
      objectFactory - to use
      Returns:
      the current KRandomParameters instance for method chaining
    • randomizerProvider

      public KRandomParameters randomizerProvider(RandomizerProvider randomizerProvider)
      Provide a custom randomizer provider.
      Parameters:
      randomizerProvider - to use
      Returns:
      the current KRandomParameters instance for method chaining
    • seed

      public KRandomParameters seed(long seed)
      Set the initial random seed.
      Parameters:
      seed - the initial seed
      Returns:
      the current KRandomParameters instance for method chaining
    • collectionSizeRange

      public KRandomParameters collectionSizeRange(int minCollectionSize, int maxCollectionSize)
      Set the collection size range.
      Parameters:
      minCollectionSize - the minimum collection size
      maxCollectionSize - the maximum collection size
      Returns:
      the current KRandomParameters instance for method chaining
    • stringLengthRange

      public KRandomParameters stringLengthRange(int minStringLength, int maxStringLength)
      Set the string length range.
      Parameters:
      minStringLength - the minimum string length
      maxStringLength - the maximum string length
      Returns:
      the current KRandomParameters instance for method chaining
    • objectPoolSize

      public KRandomParameters objectPoolSize(int objectPoolSize)
      Set the number of different objects to generate for a type.
      Parameters:
      objectPoolSize - the number of objects to generate in the pool
      Returns:
      the current KRandomParameters instance for method chaining
    • randomizationDepth

      public KRandomParameters randomizationDepth(int randomizationDepth)
      Set the randomization depth for objects graph.
      Parameters:
      randomizationDepth - the maximum randomization depth
      Returns:
      the current KRandomParameters instance for method chaining
    • charset

      public KRandomParameters charset(Charset charset)
      Set the charset to use for character based fields.
      Parameters:
      charset - the charset to use
      Returns:
      the current KRandomParameters instance for method chaining
    • dateRange

      public KRandomParameters dateRange(LocalDate min, LocalDate max)
      Set the date range.
      Parameters:
      min - date
      max - date
      Returns:
      the current KRandomParameters instance for method chaining
    • timeRange

      public KRandomParameters timeRange(LocalTime min, LocalTime max)
      Set the time range.
      Parameters:
      min - time
      max - time
      Returns:
      the current KRandomParameters instance for method chaining
    • randomizerRegistry

      public KRandomParameters randomizerRegistry(RandomizerRegistry registry)
      Register a RandomizerRegistry.
      Parameters:
      registry - the RandomizerRegistry to register
      Returns:
      the current KRandomParameters instance for method chaining
    • scanClasspathForConcreteTypes

      public KRandomParameters scanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes)
      Should the classpath be scanned for concrete types when a field with an interface or abstract class type is encountered?

      Deactivated by default.

      Parameters:
      scanClasspathForConcreteTypes - whether to scan the classpath or not
      Returns:
      the current KRandomParameters instance for method chaining
    • ignoreRandomizationErrors

      public KRandomParameters ignoreRandomizationErrors(boolean ignoreRandomizationErrors)
      With this parameter, any randomization error will be silently ignored and the corresponding field will be set to null.

      Deactivated by default.

      Parameters:
      ignoreRandomizationErrors - whether to silently ignore randomization errors or not
      Returns:
      the current KRandomParameters instance for method chaining
    • overrideDefaultInitialization

      public KRandomParameters overrideDefaultInitialization(boolean overrideDefaultInitialization)
      Should default initialization of field values be overridden? E.g. should the values of the strings and integers fields below be kept untouched or should they be randomized.
      
       public class Bean {
           Set<String> strings = new HashSet<>();
           List<Integer> integers;
      
           public Bean() {
               integers = Arrays.asList(1, 2, 3);
           }
       }
       
      Deactivated by default.
      Parameters:
      overrideDefaultInitialization - whether to override default initialization of field values or not
      Returns:
      the current KRandomParameters instance for method chaining
    • bypassSetters

      public KRandomParameters bypassSetters(boolean bypassSetters)
      Flag to bypass setters if any and use reflection directly instead. False by default.
      Parameters:
      bypassSetters - true if setters should be ignored
      Returns:
      the current KRandomParameters instance for method chaining
    • copy

      public KRandomParameters copy()
      Return a shallow copy of randomization parameters.
      Returns:
      a shallow copy of randomization parameters.