Я пытаюсь проверять объекты в списке, используя алгоритм LEVENSHTEIN_DISTANCE, регистрируя CustomPropertyComparator и registerValue.
JaversBuilder.javers()
.registerCustomType(Device::class.java, DeviceComparator())
.registerValue(Device::class.java)
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
.build()
У меня есть сценарий ios, упомянутый ниже
var device1 = Device("d1", "device1")
var device2 = Device("d2", "device2")
var devices = mutableListOf<Device>()
devices.add(device1)
devices.add(device2)
val before = Node("n1", "node1", devices)
//1. Remove device2
val newDevice1 = Device("d1", "device1")
val newDevices = mutableListOf<Device>()
newDevices.add(newDevice1)
var after = Node("n1", "node1", newDevices)
var diff = javers.compare(before, after)
println("removed $diff")
//2. Add device2
device1 = Device("d1", "device1") // devices/d1 -
device2 = Device("d2", "device2") // devices/2
devices = mutableListOf<Device>()
devices.add(device1)
devices.add(device2)
val after1 = Node("n1", "node1", devices)
diff = javers.compare(after, after1)
println("added $diff")
//3. Remove device1 from the device list
device2 = Device("d2", "device2") // devices/2
var newDevices2 = mutableListOf<Device>()
newDevices2.add(device2)
val after2 = Node("n1", "node1", newDevices2)
diff = javers.compare(after1, after2)
println("removed device1 from the device list $diff")
Программа выше дает следующий вывод:
removed Diff:
changes on com.example.audit.Node/ :
- 'devices' collection changes :
1. 'Device(deviceCode=d2, name=device2)' removed
added Diff:
changes on com.example.audit.Node/ :
- 'devices' collection changes :
1. 'Device(deviceCode=d2, name=device2)' added
removed device1 from the device list Diff:
changes on com.example.audit.Node/ :
- 'devices' collection changes :
0. 'Device(deviceCode=d1, name=device1)' removed
Я ожидаю вывод чего-то вроде JaVers PrettyPrint, который упоминается ниже:
removed Diff:
* object removed: com.example.audit.Node/#devices/1
* changes on com.example.audit.Node/ :
- 'devices' collection changes :
1. 'com.example.audit.Node/#devices/1' removed
added Diff:
* new object: com.example.audit.Node/#devices/1
* changes on com.example.audit.Node/ :
- 'devices' collection changes :
1. 'com.example.audit.Node/#devices/1' added
removed device1 from the device list Diff:
* object removed: com.example.audit.Node/#devices/0
* changes on com.example.audit.Node/ :
- 'devices' collection changes :
0. 'com.example.audit.Node/#devices/0' removed
Какое изменение я должен сделать, чтобы получить ожидаемый результат?