public abstract class Differ<ObjectType,DiffType extends Difference>
extends java.lang.Object
Comparator may be passed as an
argument to the constructor, and will thus be used. If not provided, the
initial value in the from collection 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" collections; 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.
| Constructor and Description |
|---|
Differ(java.util.List<ObjectType> from,
java.util.List<ObjectType> to)
Constructs the Differ object for the two collections, using the default
comparison mechanism between the objects, such as
equals and
compareTo. |
Differ(java.util.List<ObjectType> from,
java.util.List<ObjectType> to,
java.util.Comparator<ObjectType> comp)
Constructs the Differ object for the two collections, using the given
comparator.
|
Differ(ObjectType[] from,
ObjectType[] to)
Constructs the Differ object for the two arrays, using the default
comparison mechanism between the objects, such as
equals and
compareTo. |
Differ(ObjectType[] from,
ObjectType[] to,
java.util.Comparator<ObjectType> comp)
Constructs the Differ object for the two arrays, using the given comparator.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addPending()
Adds the last difference, if pending.
|
abstract DiffType |
createDifference(java.lang.Integer delStart,
java.lang.Integer delEnd,
java.lang.Integer addStart,
java.lang.Integer addEnd)
Subclasses implement this to return their own subclass of
Difference. |
java.util.List<DiffType> |
diff()
Deprecated.
execute is a more accurate and descriptive name. |
java.util.List<DiffType> |
execute()
Runs diff and returns the results.
|
protected void |
onFromNotTo(int fromIdx,
int toIdx)
Invoked for elements in
from and not in to. |
protected void |
onMatch(int fromIdx,
int toIdx)
Invoked for elements matching in
from and to. |
protected void |
onToNotFrom(int fromIdx,
int toIdx)
Invoked for elements in
to and not in from. |
protected void |
traverseEndOfSequences(int fromIdx,
int toIdx) |
protected void |
traverseSequences()
Traverses the sequences, seeking the longest common subsequences,
invoking the methods
finishedFrom, finishedTo,
onFromNotTo, and onToNotFrom. |
public Differ(ObjectType[] from, ObjectType[] to, java.util.Comparator<ObjectType> comp)
public Differ(ObjectType[] from, ObjectType[] to)
equals and
compareTo.public Differ(java.util.List<ObjectType> from, java.util.List<ObjectType> to)
equals and
compareTo.public Differ(java.util.List<ObjectType> from, java.util.List<ObjectType> to, java.util.Comparator<ObjectType> comp)
public java.util.List<DiffType> execute()
@Deprecated public java.util.List<DiffType> diff()
execute is a more accurate and descriptive name.public abstract DiffType createDifference(java.lang.Integer delStart, java.lang.Integer delEnd, java.lang.Integer addStart, java.lang.Integer addEnd)
Difference.protected void addPending()
protected void traverseSequences()
finishedFrom, finishedTo,
onFromNotTo, and onToNotFrom.protected void traverseEndOfSequences(int fromIdx,
int toIdx)
protected void onFromNotTo(int fromIdx,
int toIdx)
from and not in to.protected void onToNotFrom(int fromIdx,
int toIdx)
to and not in from.protected void onMatch(int fromIdx,
int toIdx)
from and to.