Class EasyRandomParameters

java.lang.Object
org.jeasy.random.EasyRandomParameters

public class EasyRandomParameters extends Object
Parameters of an EasyRandom instance.
Author:
Mahmoud Ben Hassine ([email protected])
  • 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 EasyRandomParameters.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 EasyRandomParameters.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 EasyRandomParameters.Range<java.time.ZonedDateTime> DEFAULT_DATES_RANGE
      Default dates range.
  • Constructor Details

    • EasyRandomParameters

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

    • getCollectionSizeRange

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

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

      public EasyRandomParameters.Range<java.time.LocalDate> getDateRange()
    • setDateRange

      public void setDateRange(EasyRandomParameters.Range<java.time.LocalDate> dateRange)
    • getTimeRange

      public EasyRandomParameters.Range<java.time.LocalTime> getTimeRange()
    • setTimeRange

      public void setTimeRange(EasyRandomParameters.Range<java.time.LocalTime> timeRange)
    • getStringLengthRange

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

      public void setStringLengthRange(EasyRandomParameters.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<java.util.function.Predicate<Field>> getFieldExclusionPredicates()
    • getTypeExclusionPredicates

      public Set<java.util.function.Predicate<Class<?>>> getTypeExclusionPredicates()
    • randomize

      public <T> EasyRandomParameters randomize(java.util.function.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 EasyRandomParameters instance for method chaining
      See Also:
    • randomize

      public <T> EasyRandomParameters 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 EasyRandomParameters instance for method chaining
    • excludeField

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

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

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

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

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

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

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

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

      public EasyRandomParameters 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 EasyRandomParameters instance for method chaining
    • randomizationDepth

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

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

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

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

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

      public EasyRandomParameters 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 EasyRandomParameters instance for method chaining
    • ignoreRandomizationErrors

      public EasyRandomParameters 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 EasyRandomParameters instance for method chaining
    • overrideDefaultInitialization

      public EasyRandomParameters 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 EasyRandomParameters instance for method chaining
    • bypassSetters

      public EasyRandomParameters 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 EasyRandomParameters instance for method chaining
    • copy

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