Package org.instancio.generator
Enum AfterGenerate
- All Implemented Interfaces:
Serializable,Comparable<AfterGenerate>,java.lang.constant.Constable
A hint that specifies an action to be taken after an object
is generated by a generator. This hint is communicated to
the engine via the
Generator.hints() method.
The hint indicates what action, if any, should be applied to the object(s) created by the generator.
Example usage:
public class CustomGenerator implements Generator<MyObject> {
@Override
public MyObject generate(Random random) {
// Generation logic
return new MyObject();
}
@Override
public Hints hints() {
return Hints.afterGenerate(AfterGenerate.POPULATE_NULLS);
}
}
- Since:
- 2.0.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionIndicates that an object created by the generator can be modified using any of the following methods:InstancioApi.set(TargetSelector, Object)InstancioApi.supply(TargetSelector, Generator)InstancioApi.generate(TargetSelector, GeneratorSpecProvider)Indicates that an object created by the generator should not be modified.Indicates that all fields should be populated, regardless of their initial values.Indicates that anynullfields in an object created by the generator should be populated by the engine.Indicates that primitive fields with default values in an object created by the generator should be populated by the engine. -
Method Summary
Modifier and TypeMethodDescriptionstatic AfterGenerateReturns the enum constant of this type with the specified name.static AfterGenerate[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
DO_NOT_MODIFY
Indicates that an object created by the generator should not be modified. The engine will treat the object as read-only and assign it to the target field as is.The following methods with matching selectors will not be applied to the object:
InstancioApi.set(TargetSelector, Object)InstancioApi.supply(TargetSelector, Generator)InstancioApi.generate(TargetSelector, GeneratorSpecProvider)
Note:
callbacksprovided via theonComplete()method will still be executed.- Since:
- 2.0.0
-
APPLY_SELECTORS
Indicates that an object created by the generator can be modified using any of the following methods:- Since:
- 2.0.0
-
POPULATE_NULLS
Indicates that anynullfields in an object created by the generator should be populated by the engine. Additionally, the object can be modified as specified byAPPLY_SELECTORS.- Since:
- 2.0.0
-
POPULATE_NULLS_AND_DEFAULT_PRIMITIVES
Indicates that primitive fields with default values in an object created by the generator should be populated by the engine. Additionally, the behavior described byPOPULATE_NULLSapplies as well.Default values for primitive fields are:
- Zero for all numeric types
falseforboolean' '(null character) forchar
For instance, if a
booleanfield was initialized totrue, it will not be modified. However, if it isfalse, it may be randomised to eithertrueorfalse.- Since:
- 2.0.0
-
POPULATE_ALL
Indicates that all fields should be populated, regardless of their initial values. This will cause all values to be overwritten with random data.This is the default mode of internal generators.
- Since:
- 2.0.0
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-