如何用树格式计算差异

时间:2016-09-10 10:03:26

标签: java javers

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

return ackermann($n - 1, ackermann($n, $m - 1));

举个例子:

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"))));

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

  • 我是否需要实施自己的访客
  • Plus自定义ChangeProcessor
  • ...
提前谢谢。

克里斯托弗

1 个答案:

答案 0 :(得分:0)

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 );