GraphComparator Java对象比较点表示法

时间:2017-05-05 00:34:18

标签: java object

我正在使用com.ceadarsoftware.url.GraphComparator来区分两个java对象。它看起来工作正常,但使用Delta.fieldName我无法确切地告诉对象树中的区别。在实时用例中,对象树会更大,在不同位置使用多个地址对象。

Deal d1 = new Deal();
Address address1 = new Address();
address1.setContactName("Mike");
address1.setCity("Chicago");
d1.setVendorAddress(address1);

Deal d2 = new Deal();
Address address2 = new Address();
address2.setContactName("Mike");
address2.setCity("Providence");
d2.setVendorAddress(address2);

List<GraphComparator.Delta> deltas = GraphComparator.compare(d1, d2, new GraphComparator.ID() {
  @Override
  public Object getId(Object o) {
    return "id";
  }
});

System.out.println(deltas.size()+" diff(s) found:");
for (GraphComparator.Delta d: deltas) {
  System.out.println(d.getFieldName()); //city
}

有谁知道是否有办法看到这个点符号? (例如vendorAddress.city)?我尝试了Javers,但它对我的需求来说有点太重了(这个特定项目的依赖性太多了)

谢谢,

0 个答案:

没有答案