Class DifferentBuilder

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

public class DifferentBuilder extends Object implements Builder<DifferentResult>
协助实现Differentable.diff(Object)方法
 public class Person implements Diffable<Person> {
   String name;
   int age;
   boolean smoker;

   ...

   public DiffResult diff(Person object) {
     // No need for null check, as NullPointerException correct if object is null
     return new DiffBuilder(this, object, ToStringStyle.SHORT_PREFIX_STYLE)
       .append("name", this.name, object.name)
       .append("age", this.age, object.age)
       .append("smoker", this.smoker, object.smoker)
       .build();
   }
 }
 
传递给构造函数的ToStringStyle嵌入到返回的DiffResult中, 并影响DiffResult. tostring()方法的风格。可以通过调用 DifferentResult.toString(ToStringStyle)覆盖此样式选择。.
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • DifferentBuilder

      public DifferentBuilder(Object lhs, Object rhs, ToStringStyle style, boolean testTriviallyEqual)
      使用指定样式为指定对象构造一个生成器 如果lhs == rhslhs.equals(rhs), 则构建器将不计算对append(…)的任何调用, 并在build()执行时返回一个空的DifferentResult.
      Parameters:
      lhs - this 对象
      rhs - 反对的对象
      style - 当输出对象时将使用该样式,null使用默认值
      testTriviallyEqual - 如果为真,这将测试lhs和rhs是否相同或相等。如果启用了简单的相等测试并返回true, 那么所有的append(fieldName、lhs、rhs)方法都将中止,而不创建字段Different 这个测试的结果在DifferentBuilder的整个生命周期内都不会改变。.
    • DifferentBuilder

      public DifferentBuilder(Object lhs, Object rhs, ToStringStyle style)
      使用指定样式为指定对象构造一个生成器
      Parameters:
      lhs - this 对象
      rhs - 反对的对象
      style - 当输出对象时将使用该样式,null使用默认值
  • Method Details

    • append

      public DifferentBuilder append(String fieldName, boolean lhs, boolean rhs)
      测试两个boolean是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 boolean
      rhs - 右边 boolean
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, boolean[] lhs, boolean[] rhs)
      测试两个boolean[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 boolean[]
      rhs - 右边 boolean[]
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, byte lhs, byte rhs)
      测试两个byte是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 byte
      rhs - 右边 byte
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, byte[] lhs, byte[] rhs)
      测试两个byte[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 byte[]
      rhs - 右边 byte[]
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, char lhs, char rhs)
      测试两个char是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 char
      rhs - 右边 char
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, char[] lhs, char[] rhs)
      测试两个char[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 char[]
      rhs - 右边 char[]
      Returns:
      this
      Throws:
      IllegalArgumentException - if field name is null
    • append

      public DifferentBuilder append(String fieldName, double lhs, double rhs)
      测试两个char[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 double
      rhs - 右边 double
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, double[] lhs, double[] rhs)
      测试两个 double[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 double[]
      rhs - 右边 double[]
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, float lhs, float rhs)
      测试两个 float是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 float
      rhs - 右边 float
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, float[] lhs, float[] rhs)
      测试两个 float[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 float[]
      rhs - 右边 float[]
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, int lhs, int rhs)
      测试两个 int是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 int
      rhs - 右边 int
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, int[] lhs, int[] rhs)
      测试两个 int[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 int[]
      rhs - 右边 int[]
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, long lhs, long rhs)
      测试两个 long是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 long
      rhs - 右边 long
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, long[] lhs, long[] rhs)
      测试两个 long[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 long[]
      rhs - 右边 long[]
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, short lhs, short rhs)
      测试两个 short是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 short
      rhs - 右边 short
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, short[] lhs, short[] rhs)
      测试两个 short[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 short[]
      rhs - 右边 short[]
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, Object lhs, Object rhs)
      测试两个 Objects是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 Object
      rhs - 右边 Object
      Returns:
      this
      Throws:
      IllegalArgumentException - if field name is null
    • append

      public DifferentBuilder append(String fieldName, Object[] lhs, Object[] rhs)
      测试两个 Object[]是否相等
      Parameters:
      fieldName - 字段名
      lhs - 左边 Object[]
      rhs - 右边 Object[]
      Returns:
      this
    • append

      public DifferentBuilder append(String fieldName, DifferentResult differentResult)
      附加来自另一个DiffResult的差异. 如果您想要比较本身是可扩散的属性,并且想要知道它的哪一部分是不同的, 那么这个方法是很有用的.
       public class Person implements Diffable<Person> {
         String name;
         Address address; // implements Diffable<Address>
      
         ...
      
         public DiffResult diff(Person object) {
           return new DiffBuilder(this, object, ToStringStyle.SHORT_PREFIX_STYLE)
             .append("name", this.name, object.name)
             .append("address", this.address.diff(object.address))
             .build();
         }
       }
       
      Parameters:
      fieldName - 字段名
      differentResult - 要附加的DiffResult
      Returns:
      this
    • build

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