Class ArrayGenerator<T>
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<T>
org.instancio.internal.generator.array.ArrayGenerator<T>
- All Implemented Interfaces:
Generator<T>,GeneratorSpec<T>,ArrayGeneratorSpec<T>,NullableGeneratorSpec<T>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionArrayGenerator(GeneratorContext context) ArrayGenerator(GeneratorContext context, Class<?> arrayType) -
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.hints()Hints provided by the generator to the engine.length(int length) length of array to generate.maxLength(int length) Maximum length of array to generate.minLength(int length) Minimum length of array to generate.nullable()Indicates thatnullvalue can be generated.nullable(boolean isNullable) Indicates thatnullvalues can be generated for array elements.Specifies the type of array that should be generated.protected TtryGenerateNonNull(Random random) Makes the best effort to return a non-null value.final ArrayGeneratorSpec<T>Adds given elements to the generated array at random positions.Methods inherited from class org.instancio.internal.generator.AbstractGenerator
generate, getContext, isNullable
-
Field Details
-
minLength
protected int minLength -
maxLength
protected int maxLength
-
-
Constructor Details
-
ArrayGenerator
-
ArrayGenerator
-
-
Method Details
-
apiMethod
Description copied from class:AbstractGeneratorReturns the public API method name of the generator spec. The returned name is used for reporting validation errors.- Specified by:
apiMethodin classAbstractGenerator<T>- Returns:
- spec name if defined, or
nullotherwise
-
minLength
Description copied from interface:ArrayGeneratorSpecMinimum length of array to generate.- Specified by:
minLengthin interfaceArrayGeneratorSpec<T>- Parameters:
length- minimum length (inclusive)- Returns:
- spec builder
-
maxLength
Description copied from interface:ArrayGeneratorSpecMaximum length of array to generate.- Specified by:
maxLengthin interfaceArrayGeneratorSpec<T>- Parameters:
length- maximum length (inclusive)- Returns:
- spec builder
-
length
Description copied from interface:ArrayGeneratorSpeclength of array to generate.- Specified by:
lengthin interfaceArrayGeneratorSpec<T>- Parameters:
length- of array- Returns:
- spec builder
-
nullable
Description copied from interface:NullableGeneratorSpecIndicates thatnullvalue can be generated.- Specified by:
nullablein interfaceArrayGeneratorSpec<T>- Specified by:
nullablein interfaceNullableGeneratorSpec<T>- Overrides:
nullablein classAbstractGenerator<T>- Returns:
- spec builder
-
nullable
- Overrides:
nullablein classAbstractGenerator<T>
-
nullableElements
Description copied from interface:ArrayGeneratorSpecIndicates thatnullvalues can be generated for array elements.- Specified by:
nullableElementsin interfaceArrayGeneratorSpec<T>- Returns:
- spec builder
-
subtype
Description copied from interface:ArrayGeneratorSpecSpecifies the type of array that should be generated.- Specified by:
subtypein interfaceArrayGeneratorSpec<T>- Parameters:
type- of array to generate- Returns:
- spec builder
-
with
Description copied from interface:ArrayGeneratorSpecAdds given elements to the generated array at random positions.- Specified by:
within interfaceArrayGeneratorSpec<T>- Parameters:
elements- to add- Returns:
- spec builder
-
tryGenerateNonNull
Description copied from class:AbstractGeneratorMakes the best effort to return a non-null value. However, in certain cases this method will produce anull.- Specified by:
tryGenerateNonNullin classAbstractGenerator<T>- Parameters:
random- for generating the value- Returns:
- generated value, either a null or non-null
-
hints
Description copied from interface:GeneratorHints provided by the generator to the engine.The most important hint for custom generators is
AfterGenerate. This hint indicates whether the object created by this generator:- should be populated (for example, if it has
nullfields) - can be modified using selectors
For example, setting the hint to
AfterGenerate.POPULATE_NULLSwill cause Instancio to populatenullfields on the object returned by this generator:@Override public Hints hints() { return Hints.afterGenerate(AfterGenerate.POPULATE_NULLS); }If the action is not specified, default behaviour will be based on the
AfterGeneratevalue configured in theSettingsusing the keyKeys.AFTER_GENERATE_HINT.In addition, the following hints can be provided for populating data structures:
- should be populated (for example, if it has
-