Package org.jeasy.random
Class EasyRandomParameters
java.lang.Object
org.jeasy.random.EasyRandomParameters
Parameters of an
EasyRandom
instance.- Author:
- Mahmoud Ben Hassine ([email protected])
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Utility class to hold a range of values. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Charset
Default charset for Strings.static final EasyRandomParameters.Range<Integer>
Default collection size range.static final int
Default date range in which dates will be generated: [now - 10 years, now + 10 years].static final EasyRandomParameters.Range<java.time.ZonedDateTime>
Default dates range.static final int
Number of different objects to generate for a type.static final int
Default value for randomization depth, which mean, that randomization depth is unlimitedstatic final long
Default seed.static final EasyRandomParameters.Range<Integer>
Default string length size. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbypassSetters
(boolean bypassSetters) Flag to bypass setters if any and use reflection directly instead.Set the charset to use for character based fields.collectionSizeRange
(int minCollectionSize, int maxCollectionSize) Set the collection size range.copy()
Return a shallow copy of randomization parameters.dateRange
(java.time.LocalDate min, java.time.LocalDate max) Set the date range.excludeField
(java.util.function.Predicate<Field> predicate) Exclude a field from being randomized.excludeType
(java.util.function.Predicate<Class<?>> predicate) Exclude a type from being randomized.exclusionPolicy
(ExclusionPolicy exclusionPolicy) Provide a custom exclusion policy.EasyRandomParameters.Range<java.time.LocalDate>
int
int
long
getSeed()
EasyRandomParameters.Range<java.time.LocalTime>
ignoreRandomizationErrors
(boolean ignoreRandomizationErrors) With this parameter, any randomization error will be silently ignored and the corresponding field will be set to null.boolean
boolean
boolean
boolean
objectFactory
(ObjectFactory objectFactory) Provide a custom object factory.objectPoolSize
(int objectPoolSize) Set the number of different objects to generate for a type.overrideDefaultInitialization
(boolean overrideDefaultInitialization) Should default initialization of field values be overridden? E.g.randomizationDepth
(int randomizationDepth) Set the randomization depth for objects graph.randomize
(Class<T> type, Randomizer<T> randomizer) Register a custom randomizer for a given type.randomize
(java.util.function.Predicate<Field> predicate, Randomizer<T> randomizer) Register a custom randomizer for the given field predicate.randomizerProvider
(RandomizerProvider randomizerProvider) Provide a custom randomizer provider.randomizerRegistry
(RandomizerRegistry registry) Register aRandomizerRegistry
.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.seed
(long seed) Set the initial random seed.void
setBypassSetters
(boolean bypassSetters) void
setCharset
(Charset charset) void
setCollectionSizeRange
(EasyRandomParameters.Range<Integer> collectionSizeRange) void
setDateRange
(EasyRandomParameters.Range<java.time.LocalDate> dateRange) void
setExclusionPolicy
(ExclusionPolicy exclusionPolicy) void
setIgnoreRandomizationErrors
(boolean ignoreRandomizationErrors) void
setObjectFactory
(ObjectFactory objectFactory) void
setObjectPoolSize
(int objectPoolSize) void
setOverrideDefaultInitialization
(boolean overrideDefaultInitialization) void
setRandomizationDepth
(int randomizationDepth) void
setRandomizerProvider
(RandomizerProvider randomizerProvider) void
setScanClasspathForConcreteTypes
(boolean scanClasspathForConcreteTypes) void
setSeed
(long seed) void
setStringLengthRange
(EasyRandomParameters.Range<Integer> stringLengthRange) void
setTimeRange
(EasyRandomParameters.Range<java.time.LocalTime> timeRange) stringLengthRange
(int minStringLength, int maxStringLength) Set the string length range.timeRange
(java.time.LocalTime min, java.time.LocalTime max) Set the time range.
-
Field Details
-
DEFAULT_SEED
public static final long DEFAULT_SEEDDefault seed.- See Also:
-
DEFAULT_CHARSET
Default charset for Strings. -
DEFAULT_COLLECTION_SIZE_RANGE
Default collection size range. -
DEFAULT_OBJECT_POOL_SIZE
public static final int DEFAULT_OBJECT_POOL_SIZENumber of different objects to generate for a type.- See Also:
-
DEFAULT_RANDOMIZATION_DEPTH
public static final int DEFAULT_RANDOMIZATION_DEPTHDefault value for randomization depth, which mean, that randomization depth is unlimited- See Also:
-
DEFAULT_STRING_LENGTH_RANGE
Default string length size. -
DEFAULT_DATE_RANGE
public static final int DEFAULT_DATE_RANGEDefault date range in which dates will be generated: [now - 10 years, now + 10 years].- See Also:
-
DEFAULT_DATES_RANGE
Default dates range.
-
-
Constructor Details
-
EasyRandomParameters
public EasyRandomParameters()Create a newEasyRandomParameters
with default values.
-
-
Method Details
-
getCollectionSizeRange
-
setCollectionSizeRange
-
getDateRange
-
setDateRange
-
getTimeRange
-
setTimeRange
-
getStringLengthRange
-
setStringLengthRange
-
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
-
setCharset
-
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
-
setExclusionPolicy
-
getObjectFactory
-
setObjectFactory
-
getRandomizerProvider
-
setRandomizerProvider
-
getFieldExclusionPredicates
-
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 fieldrandomizer
- to register- Returns:
- the current
EasyRandomParameters
instance for method chaining - See Also:
-
randomize
Register a custom randomizer for a given type.- Type Parameters:
T
- The field type- Parameters:
type
- class of the type to randomizerandomizer
- the customRandomizer
to use- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
excludeField
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
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
Provide a custom exclusion policy.- Parameters:
exclusionPolicy
- to use- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
objectFactory
Provide a custom object factory.- Parameters:
objectFactory
- to use- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
randomizerProvider
Provide a custom randomizer provider.- Parameters:
randomizerProvider
- to use- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
seed
Set the initial random seed.- Parameters:
seed
- the initial seed- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
collectionSizeRange
Set the collection size range.- Parameters:
minCollectionSize
- the minimum collection sizemaxCollectionSize
- the maximum collection size- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
stringLengthRange
Set the string length range.- Parameters:
minStringLength
- the minimum string lengthmaxStringLength
- the maximum string length- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
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
Set the randomization depth for objects graph.- Parameters:
randomizationDepth
- the maximum randomization depth- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
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
Set the date range.- Parameters:
min
- datemax
- date- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
timeRange
Set the time range.- Parameters:
min
- timemax
- time- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
randomizerRegistry
Register aRandomizerRegistry
.- Parameters:
registry
- theRandomizerRegistry
to register- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
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
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
Should default initialization of field values be overridden? E.g. should the values of thestrings
andintegers
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); } }
- Parameters:
overrideDefaultInitialization
- whether to override default initialization of field values or not- Returns:
- the current
EasyRandomParameters
instance for method chaining
-
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
Return a shallow copy of randomization parameters.- Returns:
- a shallow copy of randomization parameters.
-