使用 Javers 比较地图

Comparing maps using Javers

我如何使用 JaVers 比较包含 Entity 个对象的两个地图的 ID、属性?

我想检测 Bob 在以下情况下将城市从伦敦更改为巴黎:

public void compareMaps() {
    Javers javers = JaversBuilder.javers().build();
    Map<Integer, Person> a = new HashMap<>();
    Map<Integer, Person> b = new HashMap<>();
    a.put(Integer.valueOf(1), new Person(1, "Bob", "London"));
    b.put(Integer.valueOf(1), new Person(1, "Bob", "London"));
    Diff diff = javers.compare(a, b);
    assertThat(diff.getChanges()).hasSize(0);
    b.get(Integer.valueOf(1)).setCity("Paris");
    diff = javers.compare(a, b);
    assertThat(diff.getChanges()).hasSize(1);
}

static public class Person {
    @Id
    int id;
    String name;
    String city;
    @Override
    public boolean equals(Object obj) {...}
    @Override
    public int hashCode() {...}
}

实际上,您无法比较顶级地图。作为一种解决方法,您可以将这些映射放在某个值对象中,这要归功于 JaVers 将能够确定键和值的类型。

对于顶级集合,有一种特殊方法 (javers.compareCollections()),但对于地图还没有。

在JaVers的更高版本中,可以实现以下方法 <K,V> Diff compareMaps(Map<K,V> oldVersion, Map<K,V> currentVersion, Class<K> keyClass, Class<V> valueClass);

In further version of JaVers, folowing method could be implemented Diff compareMaps(Map oldVersion, Map currentVersion, Class keyClass, Class valueClass);

此地图比较是已实施还是仍在开发中?