Enum AfterGenerate

java.lang.Object
java.lang.Enum<AfterGenerate>
org.instancio.generator.AfterGenerate
All Implemented Interfaces:
Serializable, Comparable<AfterGenerate>, java.lang.constant.Constable

public enum AfterGenerate extends Enum<AfterGenerate>
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:
  • Enum Constant Details

    • DO_NOT_MODIFY

      public static final AfterGenerate 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:

      Note: callbacks provided via the onComplete() method will still be executed.

      Since:
      2.0.0
    • APPLY_SELECTORS

      public static final AfterGenerate 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

      public static final AfterGenerate POPULATE_NULLS
      Indicates that any null fields in an object created by the generator should be populated by the engine. Additionally, the object can be modified as specified by APPLY_SELECTORS.
      Since:
      2.0.0
    • POPULATE_NULLS_AND_DEFAULT_PRIMITIVES

      public static final AfterGenerate 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 by POPULATE_NULLS applies as well.

      Default values for primitive fields are:

      • Zero for all numeric types
      • false for boolean
      • '' (null character) for char

      For instance, if a boolean field was initialized to true, it will not be modified. However, if it is false, it may be randomised to either true or false.

      Since:
      2.0.0
    • POPULATE_ALL

      public static final AfterGenerate 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

      public static AfterGenerate[] 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

      public static AfterGenerate valueOf(String name)
      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 name
      NullPointerException - if the argument is null