Why doesn't Javers report the correct row(s) that was added when comparing two objects?

旧城冷巷雨未停 提交于 2019-12-12 05:29:16

问题


When comparing two objects of the same size, Javers compares 1-to-1. However, if a new change is added such as new row to one of the objects, the comparison reports changes that are NOT changes. Is it possible to have Javers ignore the addition/deletion for the sake of just comparing like objects?

Basically the indices get out of sync.

Row  Name  Age Phone(Cell/Work)
 1    Jo    20  123
 2    Sam   25  133
 3    Rick  30  152
 4    Rick  30  145

New List

Row  Name  Age Phone(Cell/Work)
 1   Jo    20  123
 2   Sam   25  133
 3   Bill  30  170
 4   Rick  30  152
 5   Rick  30  145

Because Bill is added the new comparison result will say that Rows 4,5 have changed when they actually didn't.

Thanks.


回答1:


I'm guessing that your 'rows' are objects representing rows in an excel table and that you have mapped them as ValueObjects and put them into some list.

Since ValueObjects don't have its own identity, it's unclear, even for a human, what was the actual change. Take a look at your row 4:

Row  Name  Age Phone(Cell/Work)
before:
4   Rick  30  145
after:
4   Rick  30  152

Did you changed Phone at row 4 from 145 to 152? Or maybe you inserted a new data to row 4? How can we know? We can't. By default, JaVers chooses the simplest answer, so reports value change at index 4.

If you don't care aboute the indices, you can change the list comparision algorithm from Simple to Levenshtein distance. See https://javers.org/documentation/diff-configuration/#list-algorithms

SIMPLE algorithm generates changes for shifted elements (in case when elements are inserted or removed in the middle of a list). On the contrary, Levenshtein algorithm calculates short and clear change list even in case when elements are shifted. It doesn’t care about index changes for shifted elements.

But, I'm not sure if Levenshtein is implemented for ValueObjects, if it is not implemented yet, it's a feature request to javers-core.



来源:https://stackoverflow.com/questions/45194674/why-doesnt-javers-report-the-correct-rows-that-was-added-when-comparing-two-o

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!