Package org.aoju.bus.core.builder
Class DifferentBuilder
java.lang.Object
org.aoju.bus.core.builder.DifferentBuilder
- All Implemented Interfaces:
Serializable,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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.aoju.bus.core.builder.Builder
Builder.HashKey -
Constructor Summary
ConstructorsConstructorDescriptionDifferentBuilder(Object lhs, Object rhs, ToStringStyle style) 使用指定样式为指定对象构造一个生成器DifferentBuilder(Object lhs, Object rhs, ToStringStyle style, boolean testTriviallyEqual) 使用指定样式为指定对象构造一个生成器 如果lhs == rhs或lhs.equals(rhs), 则构建器将不计算对append(…)的任何调用, 并在build()执行时返回一个空的DifferentResult. -
Method Summary
Modifier and TypeMethodDescription测试两个boolean[]是否相等测试两个boolean是否相等测试两个byte[]是否相等测试两个byte是否相等测试两个char[]是否相等测试两个char是否相等测试两个double[]是否相等测试两个char[]是否相等测试两个float[]是否相等测试两个float是否相等测试两个int[]是否相等测试两个int是否相等测试两个long[]是否相等测试两个long是否相等测试两个short[]是否相等测试两个short是否相等测试两个Object[]是否相等测试两个Objects是否相等append(String fieldName, DifferentResult differentResult) 附加来自另一个DiffResult的差异.build()包装唯一键(System.identityHashCode())使对象只有和自己 equals 此对象用于消除小概率下System.identityHashCode()产生的ID重复问题
-
Constructor Details
-
DifferentBuilder
使用指定样式为指定对象构造一个生成器 如果lhs == rhs或lhs.equals(rhs), 则构建器将不计算对append(…)的任何调用, 并在build()执行时返回一个空的DifferentResult.- Parameters:
lhs-this对象rhs- 反对的对象style- 当输出对象时将使用该样式,null使用默认值testTriviallyEqual- 如果为真,这将测试lhs和rhs是否相同或相等。如果启用了简单的相等测试并返回true, 那么所有的append(fieldName、lhs、rhs)方法都将中止,而不创建字段Different这个测试的结果在DifferentBuilder的整个生命周期内都不会改变。.
-
DifferentBuilder
使用指定样式为指定对象构造一个生成器- Parameters:
lhs-this对象rhs- 反对的对象style- 当输出对象时将使用该样式,null使用默认值
-
-
Method Details
-
append
测试两个boolean是否相等- Parameters:
fieldName- 字段名lhs- 左边booleanrhs- 右边boolean- Returns:
- this
-
append
测试两个boolean[]是否相等- Parameters:
fieldName- 字段名lhs- 左边boolean[]rhs- 右边boolean[]- Returns:
- this
-
append
测试两个byte是否相等- Parameters:
fieldName- 字段名lhs- 左边byterhs- 右边byte- Returns:
- this
-
append
测试两个byte[]是否相等- Parameters:
fieldName- 字段名lhs- 左边byte[]rhs- 右边byte[]- Returns:
- this
-
append
测试两个char是否相等- Parameters:
fieldName- 字段名lhs- 左边charrhs- 右边char- Returns:
- this
-
append
测试两个char[]是否相等- Parameters:
fieldName- 字段名lhs- 左边char[]rhs- 右边char[]- Returns:
- this
- Throws:
IllegalArgumentException- if field name isnull
-
append
测试两个char[]是否相等- Parameters:
fieldName- 字段名lhs- 左边doublerhs- 右边double- Returns:
- this
-
append
测试两个double[]是否相等- Parameters:
fieldName- 字段名lhs- 左边double[]rhs- 右边double[]- Returns:
- this
-
append
测试两个float是否相等- Parameters:
fieldName- 字段名lhs- 左边floatrhs- 右边float- Returns:
- this
-
append
测试两个float[]是否相等- Parameters:
fieldName- 字段名lhs- 左边float[]rhs- 右边float[]- Returns:
- this
-
append
测试两个int是否相等- Parameters:
fieldName- 字段名lhs- 左边intrhs- 右边int- Returns:
- this
-
append
测试两个int[]是否相等- Parameters:
fieldName- 字段名lhs- 左边int[]rhs- 右边int[]- Returns:
- this
-
append
测试两个long是否相等- Parameters:
fieldName- 字段名lhs- 左边longrhs- 右边long- Returns:
- this
-
append
测试两个long[]是否相等- Parameters:
fieldName- 字段名lhs- 左边long[]rhs- 右边long[]- Returns:
- this
-
append
测试两个short是否相等- Parameters:
fieldName- 字段名lhs- 左边shortrhs- 右边short- Returns:
- this
-
append
测试两个short[]是否相等- Parameters:
fieldName- 字段名lhs- 左边short[]rhs- 右边short[]- Returns:
- this
-
append
测试两个Objects是否相等- Parameters:
fieldName- 字段名lhs- 左边Objectrhs- 右边Object- Returns:
- this
- Throws:
IllegalArgumentException- if field name isnull
-
append
测试两个Object[]是否相等- Parameters:
fieldName- 字段名lhs- 左边Object[]rhs- 右边Object[]- Returns:
- this
-
append
附加来自另一个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
Description copied from interface:Builder包装唯一键(System.identityHashCode())使对象只有和自己 equals 此对象用于消除小概率下System.identityHashCode()产生的ID重复问题- Specified by:
buildin interfaceBuilder<DifferentResult>- Returns:
- 被构建的对象
-