Enum Class FieldCloneStrategy

java.lang.Object
java.lang.Enum<FieldCloneStrategy>
cloud.opencode.base.deepclone.strategy.FieldCloneStrategy
All Implemented Interfaces:
Serializable, Comparable<FieldCloneStrategy>, Constable

public enum FieldCloneStrategy extends Enum<FieldCloneStrategy>
Enumeration of field cloning strategies 字段克隆策略枚举

Defines how individual fields should be handled during object cloning. Can be determined from field annotations or explicitly specified.

定义对象克隆期间如何处理各个字段。可以从字段注解确定或显式指定。

Usage Examples | 使用示例:

Field field = MyClass.class.getDeclaredField("data");
FieldCloneStrategy strategy = FieldCloneStrategy.fromAnnotations(field);

switch (strategy) {
    case DEEP -> deepCloneField(field, source, target);
    case SHALLOW -> shallowCopyField(field, source, target);
    case IGNORE -> {} // Skip the field
    case NULL -> setFieldNull(field, target);
}

Features | 主要功能:

  • Annotation-based strategy detection - 基于注解的策略检测
  • Four clone modes: DEEP, SHALLOW, IGNORE, NULL - 四种克隆模式
  • Priority-based annotation resolution - 基于优先级的注解解析

Security | 安全性:

  • Thread-safe: Yes (enum is immutable) - 线程安全: 是(枚举不可变)
Since:
JDK 25, opencode-base-deepclone V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Enum Constant Details

    • DEEP

      public static final FieldCloneStrategy DEEP
      Deep clone the field (default behavior) 深度克隆字段(默认行为)
    • SHALLOW

      public static final FieldCloneStrategy SHALLOW
      Shallow copy (reference only) 浅拷贝(仅复制引用)
    • IGNORE

      public static final FieldCloneStrategy IGNORE
      Ignore the field (keep default value) 忽略字段(保持默认值)
    • NULL

      public static final FieldCloneStrategy NULL
      Set field to null explicitly 显式设置字段为null
  • Method Details

    • values

      public static FieldCloneStrategy[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static FieldCloneStrategy valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified name
      NullPointerException - if the argument is null
    • fromAnnotations

      public static FieldCloneStrategy fromAnnotations(Field field)
      Determines the clone strategy from field annotations 从字段注解确定克隆策略

      Priority order: @CloneIgnore > @CloneReference > @CloneDeep > DEEP

      优先级顺序:@CloneIgnore > @CloneReference > @CloneDeep > DEEP

      Parameters:
      field - the field to analyze | 要分析的字段
      Returns:
      the determined strategy | 确定的策略