Class EasyRandomParameters


  • public class EasyRandomParameters
    extends java.lang.Object
    Parameters of an EasyRandom instance.
    Author:
    Mahmoud Ben Hassine ([email protected])
    • Field Detail

      • DEFAULT_CHARSET

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

        public static final EasyRandomParameters.Range<java.lang.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:
        Constant Field Values
      • DEFAULT_RANDOMIZATION_DEPTH

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

        public static final EasyRandomParameters.Range<java.lang.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:
        Constant Field Values
      • DEFAULT_DATES_RANGE

        public static final EasyRandomParameters.Range<java.time.ZonedDateTime> DEFAULT_DATES_RANGE
        Default dates range.
    • Constructor Detail

      • EasyRandomParameters

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

      • setCollectionSizeRange

        public void setCollectionSizeRange​(EasyRandomParameters.Range<java.lang.Integer> collectionSizeRange)
      • 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 java.nio.charset.Charset getCharset()
      • setCharset

        public void setCharset​(java.nio.charset.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)
      • setExclusionPolicy

        public void setExclusionPolicy​(ExclusionPolicy exclusionPolicy)
      • setObjectFactory

        public void setObjectFactory​(ObjectFactory objectFactory)
      • setRandomizerProvider

        public void setRandomizerProvider​(RandomizerProvider randomizerProvider)
      • getFieldExclusionPredicates

        public java.util.Set<java.util.function.Predicate<java.lang.reflect.Field>> getFieldExclusionPredicates()
      • getTypeExclusionPredicates

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

        public <T> EasyRandomParameters randomize​(java.util.function.Predicate<java.lang.reflect.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:
        FieldPredicates
      • randomize

        public <T> EasyRandomParameters randomize​(java.lang.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<java.lang.reflect.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:
        FieldPredicates
      • excludeType

        public EasyRandomParameters excludeType​(java.util.function.Predicate<java.lang.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:
        FieldPredicates
      • 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​(java.nio.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
      • 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.