Class ReflectionBuilder

java.lang.Object
org.aoju.bus.core.builder.ReflectionBuilder
All Implemented Interfaces:
Serializable, Builder<DifferentResult>

public class ReflectionBuilder extends Object implements Builder<DifferentResult>
协助实现Differentable.diff(Object)方法.

使用反射发现要差异的对象的所有非静态、非瞬态字段(包括继承字段),并比较它们之间的差异.

 public class Person implements Diffable<Person> {
   String name;
   int age;
   boolean smoker;
   ...

   public DiffResult diff(Person obj) {
     return new ReflectionDiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
       .build();
   }
 }
 

传递给构造函数的ToStringStyle嵌入到返回的DiffResult中, 并影响DiffResult. tostring()方法的风格。可以通过调用 DifferentResult.toString(ToStringStyle)覆盖此样式选择.

Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • ReflectionBuilder

      public ReflectionBuilder(T lhs, T rhs, ToStringStyle style)
      使用指定样式为指定对象构造一个生成器

      如果lhs == rhslhs.equals(rhs), 则构建器将不计算对append(…)的任何调用, 并在build()执行时返回一个空的DifferentResult.

      Type Parameters:
      T - 要区分的对象的类型
      Parameters:
      lhs - this 对象
      rhs - 反对的对象
      style - 当输出对象时将使用该样式,null使用默认值
  • Method Details

    • build

      public DifferentResult build()
      Description copied from interface: Builder
      包装唯一键(System.identityHashCode())使对象只有和自己 equals 此对象用于消除小概率下System.identityHashCode()产生的ID重复问题
      Specified by:
      build in interface Builder<DifferentResult>
      Returns:
      被构建的对象