嗨,我想展示这样的差异,我想知道Javers的最佳方法是什么:

a.name          leftV <-> rightB
a.b[0].value    leftV <-> rightB
a.b[0].c.foo    leftV <-> rightB


举个例子:

public class A {
    public A(String name, List<B> listOfB) {
        this.name = name;
        this.listOfB = listOfB;
    }

    String name;
    List<B> listOfB = new ArrayList<>();
}

public class B {
    public B(int id, String value, C c) {
        this.id = id;
        this.value = value;
        this.c = c;
    }

    @Id
    int id;
    String value;
    C c;
}

public class C {
    public C(String address) {
        this.address = address;
    }

    String address;
}

...
public void printGrpah() {
A a1 = new A("Foo", Arrays.asList(new B(1, "Bar", new C("Paris")),
                                  new B(2, "Other", new C("Madrid"))));
A a2 =new A("Fooo", Arrays.asList(new B(1, "Bar2", new C("London"))));


我想得到这样的东西:

Updated:
    name                 Foo <-> Fooo
    listOfB[0].value     Bar <-> Bar2
    listOfB[0].c.address Paris <-> London

Added
    listOfB[1].value     Other
    listOfB[1].c.address Madrid


我不是在寻找最终的解决方案,而是更多的线索来了解我需要在哪里插入代码:


我需要实现自己的访客吗
加上自定义的ChangeProcessor
...


提前谢谢。

克里斯多夫

最佳答案

ChangeProcessor专为此类任务而设计。见http://javers.org/javadoc_2.0/org/javers/core/Javers.html#processChangeList-java.util.List-org.javers.core.changelog.ChangeProcessor-

例如,要获取简单的更改日志,请调用:

 List<Change> changes = javers.calculateDiffs(...);
 String changeLog = javers.processChangeList(changes, new SimpleTextChangeLog());
 System.out.println( changeLog );

10-04 23:20