我有两个具有相同数据但顺序不同的列表。
为什么 JaverscompareCollections
方法会看到 Levenshtein 距离的两个变化(一个 ValueRemoved 和一个 ValueAdded)?
也许 Javers 不允许带有@Id
注释的多个字段?
代码:
class A {
@Id
private String a;
@Id
private String b;
public A() {
}
public A(String a, String b) {
this.a = a;
this.b = b;
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}
@Test
public void testJavers() {
List<A> oldList = Arrays.asList(
new A("a1", "b1"),
new A("a2", "b2"));
List<A> newList = Arrays.asList(
new A("a2", "b2"),
new A("a1", "b1"));
Javers javers = JaversBuilder.javers()
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
.build();
Diff diff = javers.compareCollections(oldList, newList, A.class);
System.out.println(javers.getJsonConverter().toJson(diff));
}
结果:
{
"changes": [
{
"changeType": "ListChange",
"globalId": {
"valueObject": "org.javers.core.graph.LiveGraphFactory$ListWrapper"
},
"property": "list",
"elementChanges": [
{
"elementChangeType": "ValueRemoved",
"index": 1,
"value": {
"a": "a2",
"b": "b2"
}
},
{
"elementChangeType": "ValueAdded",
"index": 0,
"value": {
"a": "a2",
"b": "b2"
}
}
]
}
]
}