如何在 Corda 中比较一个状态的两个实例
How to compare two instances of a state in Corda
我只想获取状态中更改的字段。所以我正在做的就像我正在获取消耗状态(在更新之前将具有初始状态)和未消耗状态(这将是具有更新字段的最新状态)。现在我有这两个状态,那么我将如何找到更改的字段(字段名称)?
您可以利用反射来实现这一点。以下是 Kotlin 代码片段
fun compareFields(lineItem1: State1, lineItem2: State1): List<String> {
val differentFieldsNames = ArrayList<String>()
val differentFields = State1::class.memberProperties.filter {
val startValue = it.get(lineItem1)
val endValue = it.get(lineItem2)
!Objects.deepEquals(startValue, endValue)
}
differentFields.forEach {
println("Fields not matching "+" "+it.name)
differentFieldsNames.add(it.name)
}
return differentFieldsNames
}
我只想获取状态中更改的字段。所以我正在做的就像我正在获取消耗状态(在更新之前将具有初始状态)和未消耗状态(这将是具有更新字段的最新状态)。现在我有这两个状态,那么我将如何找到更改的字段(字段名称)?
您可以利用反射来实现这一点。以下是 Kotlin 代码片段
fun compareFields(lineItem1: State1, lineItem2: State1): List<String> {
val differentFieldsNames = ArrayList<String>()
val differentFields = State1::class.memberProperties.filter {
val startValue = it.get(lineItem1)
val endValue = it.get(lineItem2)
!Objects.deepEquals(startValue, endValue)
}
differentFields.forEach {
println("Fields not matching "+" "+it.name)
differentFieldsNames.add(it.name)
}
return differentFieldsNames
}