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 obj) {
// No need for null check, as NullPointerException correct if obj is null
return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
.append("name", this.name, obj.name)
.append("age", this.age, obj.age)
.append("smoker", this.smoker, obj.smoker)
.build();
}
}
传递给构造函数的ToStringStyle嵌入到返回的DiffResult中,
并影响DiffResult. tostring()方法的风格。可以通过调用
DifferentResult.toString(ToStringStyle)覆盖此样式选择。.Differentable,
Different,
DifferentResult,
ToStringStyleBuilder.HashKey| Constructor and Description |
|---|
DifferentBuilder(Object lhs,
Object rhs,
ToStringStyle style)
使用指定样式为指定对象构造一个生成器
|
DifferentBuilder(Object lhs,
Object rhs,
ToStringStyle style,
boolean testTriviallyEqual)
使用指定样式为指定对象构造一个生成器
如果
lhs == rhs或lhs.equals(rhs),
则构建器将不计算对append(…)的任何调用,
并在build()执行时返回一个空的DifferentResult. |
| Modifier and Type | Method and Description |
|---|---|
DifferentBuilder |
append(String fieldName,
boolean[] lhs,
boolean[] rhs)
测试两个
boolean[]是否相等 |
DifferentBuilder |
append(String fieldName,
boolean lhs,
boolean rhs)
测试两个
boolean是否相等 |
DifferentBuilder |
append(String fieldName,
byte[] lhs,
byte[] rhs)
测试两个
byte[]是否相等 |
DifferentBuilder |
append(String fieldName,
byte lhs,
byte rhs)
测试两个
byte是否相等 |
DifferentBuilder |
append(String fieldName,
char[] lhs,
char[] rhs)
测试两个
char[]是否相等 |
DifferentBuilder |
append(String fieldName,
char lhs,
char rhs)
测试两个
char是否相等 |
DifferentBuilder |
append(String fieldName,
DifferentResult differentResult)
附加来自另一个
DiffResult的差异. |
DifferentBuilder |
append(String fieldName,
double[] lhs,
double[] rhs)
测试两个
double[]是否相等 |
DifferentBuilder |
append(String fieldName,
double lhs,
double rhs)
测试两个
char[]是否相等 |
DifferentBuilder |
append(String fieldName,
float[] lhs,
float[] rhs)
测试两个
float[]是否相等 |
DifferentBuilder |
append(String fieldName,
float lhs,
float rhs)
测试两个
float是否相等 |
DifferentBuilder |
append(String fieldName,
int[] lhs,
int[] rhs)
测试两个
int[]是否相等 |
DifferentBuilder |
append(String fieldName,
int lhs,
int rhs)
测试两个
int是否相等 |
DifferentBuilder |
append(String fieldName,
long[] lhs,
long[] rhs)
测试两个
long[]是否相等 |
DifferentBuilder |
append(String fieldName,
long lhs,
long rhs)
测试两个
long是否相等 |
DifferentBuilder |
append(String fieldName,
Object[] lhs,
Object[] rhs)
测试两个
Object[]是否相等 |
DifferentBuilder |
append(String fieldName,
Object lhs,
Object rhs)
测试两个
Objects是否相等 |
DifferentBuilder |
append(String fieldName,
short[] lhs,
short[] rhs)
测试两个
short[]是否相等 |
DifferentBuilder |
append(String fieldName,
short lhs,
short rhs)
测试两个
short是否相等 |
DifferentResult |
build()
构建
|
public DifferentBuilder(Object lhs, Object rhs, ToStringStyle style, boolean testTriviallyEqual)
lhs == rhs或lhs.equals(rhs),
则构建器将不计算对append(…)的任何调用,
并在build()执行时返回一个空的DifferentResult.lhs - this 对象rhs - 反对的对象style - 当输出对象时将使用该样式,null使用默认值testTriviallyEqual - 如果为真,这将测试lhs和rhs是否相同或相等。如果启用了简单的相等测试并返回true,
那么所有的append(fieldName、lhs、rhs)方法都将中止,而不创建字段Different
这个测试的结果在DifferentBuilder的整个生命周期内都不会改变。.public DifferentBuilder(Object lhs, Object rhs, ToStringStyle style)
lhs - this 对象rhs - 反对的对象style - 当输出对象时将使用该样式,null使用默认值public DifferentBuilder append(String fieldName, boolean lhs, boolean rhs)
boolean是否相等fieldName - 字段名lhs - 左边 booleanrhs - 右边 booleanpublic DifferentBuilder append(String fieldName, boolean[] lhs, boolean[] rhs)
boolean[]是否相等fieldName - 字段名lhs - 左边 boolean[]rhs - 右边 boolean[]public DifferentBuilder append(String fieldName, byte lhs, byte rhs)
byte是否相等fieldName - 字段名lhs - 左边 byterhs - 右边 bytepublic DifferentBuilder append(String fieldName, byte[] lhs, byte[] rhs)
byte[]是否相等fieldName - 字段名lhs - 左边 byte[]rhs - 右边 byte[]public DifferentBuilder append(String fieldName, char lhs, char rhs)
char是否相等fieldName - 字段名lhs - 左边 charrhs - 右边 charpublic DifferentBuilder append(String fieldName, char[] lhs, char[] rhs)
char[]是否相等fieldName - 字段名lhs - 左边 char[]rhs - 右边 char[]IllegalArgumentException - if field name is nullpublic DifferentBuilder append(String fieldName, double lhs, double rhs)
char[]是否相等fieldName - 字段名lhs - 左边 doublerhs - 右边 doublepublic DifferentBuilder append(String fieldName, double[] lhs, double[] rhs)
double[]是否相等fieldName - 字段名lhs - 左边 double[]rhs - 右边 double[]public DifferentBuilder append(String fieldName, float lhs, float rhs)
float是否相等fieldName - 字段名lhs - 左边 floatrhs - 右边 floatpublic DifferentBuilder append(String fieldName, float[] lhs, float[] rhs)
float[]是否相等fieldName - 字段名lhs - 左边 float[]rhs - 右边 float[]public DifferentBuilder append(String fieldName, int lhs, int rhs)
int是否相等fieldName - 字段名lhs - 左边 intrhs - 右边 intpublic DifferentBuilder append(String fieldName, int[] lhs, int[] rhs)
int[]是否相等fieldName - 字段名lhs - 左边 int[]rhs - 右边 int[]public DifferentBuilder append(String fieldName, long lhs, long rhs)
long是否相等fieldName - 字段名lhs - 左边 longrhs - 右边 longpublic DifferentBuilder append(String fieldName, long[] lhs, long[] rhs)
long[]是否相等fieldName - 字段名lhs - 左边 long[]rhs - 右边 long[]public DifferentBuilder append(String fieldName, short lhs, short rhs)
short是否相等fieldName - 字段名lhs - 左边 shortrhs - 右边 shortpublic DifferentBuilder append(String fieldName, short[] lhs, short[] rhs)
short[]是否相等fieldName - 字段名lhs - 左边 short[]rhs - 右边 short[]public DifferentBuilder append(String fieldName, Object lhs, Object rhs)
Objects是否相等fieldName - 字段名lhs - 左边 Objectrhs - 右边 ObjectIllegalArgumentException - if field name is nullpublic DifferentBuilder append(String fieldName, Object[] lhs, Object[] rhs)
Object[]是否相等fieldName - 字段名lhs - 左边 Object[]rhs - 右边 Object[]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 obj) {
return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
.append("name", this.name, obj.name)
.append("address", this.address.diff(obj.address))
.build();
}
}
fieldName - 字段名differentResult - 要附加的DiffResultpublic DifferentResult build()
Builderbuild in interface Builder<DifferentResult>Copyright © 2020. All rights reserved.