Package helma.util
Class Diff
java.lang.Object
helma.util.Diff
Compares two lists, returning a list of the additions, changes, and deletions
between them. A
Comparator
may be passed as an argument to the
constructor, and will thus be used. If not provided, the initial value in the
a
("from") list will be looked at to see if it supports the
Comparable
interface. If so, its equals
and
compareTo
methods will be invoked on the instances in the "from"
and "to" lists; otherwise, for speed, hash codes from the objects will be
used instead for comparison.
The file FileDiff.java shows an example usage of this class, in an application similar to the Unix "diff" program.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A legacy adapter that is compatible to the interface of the old GPL licenced Diff. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs the Diff object for the two arrays, using the default comparison mechanism between the objects, such asequals
andcompareTo
.Diff
(Object[] a, Object[] b, Comparator comp) Constructs the Diff object for the two arrays, using the given comparator.Constructs the Diff object for the two lists, using the default comparison mechanism between the objects, such asequals
andcompareTo
.Diff
(List a, List b, Comparator comp) Constructs the Diff object for the two lists, using the given comparator. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adds the given value to the "end" of the threshold map, that is, with the greatest index/key.protected boolean
Override and return true in order to havefinishedA
invoked at the last element in thea
array.protected boolean
Override and return true in order to havefinishedB
invoked at the last element in theb
array.diff()
Runs diff and returns the results.protected boolean
Compares the two objects, using the comparator provided with the constructor, if any.protected void
finishedA
(int lastA) Invoked at the last element ina
, ifcallFinishedA
returns true.protected void
finishedB
(int lastB) Invoked at the last element inb
, ifcallFinishedB
returns true.protected Integer
Returns the value for the greatest key in the map.Integer[]
Returns an array of the longest common subsequences.protected Integer
Inserts the given values into the threshold map.protected boolean
isGreaterThan
(Integer index, Integer val) Returns whether the value in the map for the given index is greater than the given value.protected boolean
isLessThan
(Integer index, Integer val) Returns whether the value in the map for the given index is less than the given value.protected static boolean
Returns whether the integer is not zero (including if it is not null).protected void
onANotB
(int ai, int bi) Invoked for elements ina
and not inb
.protected void
onBNotA
(int ai, int bi) Invoked for elements inb
and not ina
.protected void
onMatch
(int ai, int bi) Invoked for elements matching ina
andb
.protected void
Traverses the sequences, seeking the longest common subsequences, invoking the methodsfinishedA
,finishedB
,onANotB
, andonBNotA
.
-
Field Details
-
a
The source list, AKA the "from" values. -
b
The target list, AKA the "to" values. -
diffs
The list of differences, asDifference
instances.
-
-
Constructor Details
-
Diff
Constructs the Diff object for the two arrays, using the given comparator. -
Diff
Constructs the Diff object for the two arrays, using the default comparison mechanism between the objects, such asequals
andcompareTo
. -
Diff
Constructs the Diff object for the two lists, using the given comparator. -
Diff
Constructs the Diff object for the two lists, using the default comparison mechanism between the objects, such asequals
andcompareTo
.
-
-
Method Details
-
diff
Runs diff and returns the results. -
traverseSequences
protected void traverseSequences()Traverses the sequences, seeking the longest common subsequences, invoking the methodsfinishedA
,finishedB
,onANotB
, andonBNotA
. -
callFinishedA
protected boolean callFinishedA()Override and return true in order to havefinishedA
invoked at the last element in thea
array. -
callFinishedB
protected boolean callFinishedB()Override and return true in order to havefinishedB
invoked at the last element in theb
array. -
finishedA
protected void finishedA(int lastA) Invoked at the last element ina
, ifcallFinishedA
returns true. -
finishedB
protected void finishedB(int lastB) Invoked at the last element inb
, ifcallFinishedB
returns true. -
onANotB
protected void onANotB(int ai, int bi) Invoked for elements ina
and not inb
. -
onBNotA
protected void onBNotA(int ai, int bi) Invoked for elements inb
and not ina
. -
onMatch
protected void onMatch(int ai, int bi) Invoked for elements matching ina
andb
. -
equals
Compares the two objects, using the comparator provided with the constructor, if any. -
getLongestCommonSubsequences
Returns an array of the longest common subsequences. -
isNonzero
Returns whether the integer is not zero (including if it is not null). -
isGreaterThan
Returns whether the value in the map for the given index is greater than the given value. -
isLessThan
Returns whether the value in the map for the given index is less than the given value. -
getLastValue
Returns the value for the greatest key in the map. -
append
Adds the given value to the "end" of the threshold map, that is, with the greatest index/key. -
insert
Inserts the given values into the threshold map.
-