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>
Specifies actions to be taken on objects generated by a generator. This hint is communicated to the engine via the Generator.hints() method.

Each action determines how the engine processes the generated object, including whether and how its fields are populated or modified.

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 a generated object should remain unchanged. The engine will treat the object as read-only and assign it to the target field without further modification.

      Fields will not be populated, and matching selectors will have no effect. However, OnCompleteCallback callbacks provided via the onComplete() method will still be executed.

      Since:
      2.0.0
    • APPLY_SELECTORS

      public static final AfterGenerate APPLY_SELECTORS
      Indicates that a generated object can be modified only via explicitly specified selectors. Fields not targeted by selectors will remain unchanged.
      Since:
      2.0.0
    • POPULATE_NULLS

      public static final AfterGenerate POPULATE_NULLS
      Indicates that all null fields in a generated object should be populated by the engine. Additionally, the object can be modified as described by APPLY_SELECTORS.

      Non-null fields will remain unchanged unless explicitly targeted by selectors.

      Since:
      2.0.0
    • POPULATE_NULLS_AND_DEFAULT_PRIMITIVES

      public static final AfterGenerate POPULATE_NULLS_AND_DEFAULT_PRIMITIVES
      Indicates that both null fields and primitive fields containing default values in a generated object should be populated by the engine. This includes the behavior of POPULATE_NULLS.

      A primitive field is considered to have a default value if it contains:

      • 0 for numeric types (byte, short, int, long, float, double)
      • false for boolean
      • '' (null character) for char

      For example:

      • A boolean field with the value false may be randomized.
      • A boolean field with the value true will remain unchanged.
      • An int field with the value 0 may be randomized.
      • An int field with a non-zero value will remain unchanged.
      Since:
      2.0.0
    • POPULATE_ALL

      public static final AfterGenerate POPULATE_ALL
      Indicates that all fields in a generated object should be populated, regardless of their current values. This will overwrite all fields with new random values.

      This is the default behaviour for 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