org.apache.commons.text.diff有什么用?

What is org.apache.commons.text.diff used for?

我阅读了 org.apache.commons.text.diff 的文档。但是我还是不明白类InsertCommandEditCommandKeepCommandDeleteCommand有什么用。有人知道它们是什么以及如何使用它们吗?

如果比较两个字符串:

A B C E F H (旧)
A C D E G H (新)

那么你的"script"是:

Keep   'A'
Delete 'B'
Keep   'C'
Insert 'D'
Keep   'E'
Delete 'F'
Insert 'G'
Keep   'H'

EditCommand 的 javadoc 中所述:

When two objects sequences are compared through the StringsComparator.getScript method, the result is provided has a script containing the commands that progressively transform the first sequence into the second one.