|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jidesoft.diff.Diff<T>
public class Diff<T>
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.
Field Summary | |
---|---|
protected List<T> |
a
The source list, AKA the "from" values. |
protected List<T> |
b
The target list, AKA the "to" values. |
protected List<Difference> |
diffs
The list of differences, as Difference instances. |
Constructor Summary | |
---|---|
Diff(List<T> from,
List<T> to)
Constructs the Diff object for the two lists, using the default comparison mechanism between the objects, such as equals and compareTo . |
|
Diff(List<T> from,
List<T> to,
Comparator<T> comparator)
Constructs the Diff object for the two lists, using the given comparator. |
|
Diff(T[] from,
T[] to)
Constructs the Diff object for the two arrays, using the default comparison mechanism between the objects, such as equals and compareTo . |
|
Diff(T[] from,
T[] to,
Comparator<T> comparator)
Constructs the Diff object for the two arrays, using the given comparator. |
Method Summary | |
---|---|
protected void |
append(Integer value)
Adds the given value to the "end" of the threshold map, that is, with the greatest index/key. |
protected boolean |
callFinishedA()
Override and return true in order to have finishedA invoked at the last element in the
from array. |
protected boolean |
callFinishedB()
Override and return true in order to have finishedB invoked at the last element in the
to array. |
List<Difference> |
diff()
Runs diff and returns the results. |
protected boolean |
equals(T x,
T y)
Compares the two objects, using the comparator provided with the constructor, if any. |
protected void |
finishedA(int lastA)
Invoked at the last element in a , if callFinishedA returns true. |
protected void |
finishedB(int lastB)
Invoked at the last element in b , if callFinishedB returns true. |
protected Integer |
getLastValue()
Returns the value for the greatest key in the map. |
Integer[] |
getLongestCommonSubsequences()
Returns an array of the longest common subsequences. |
protected Integer |
insert(Integer j,
Integer k)
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. |
boolean |
isItemsConsistent()
Gets the flag indicating if the items are consistent in the from and to items. |
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 |
isNonzero(Integer i)
Returns whether the integer is not zero (including if it is not null). |
protected void |
onANotB(int ai,
int bi)
Invoked for elements in a and not in b . |
protected void |
onBNotA(int ai,
int bi)
Invoked for elements in b and not in a . |
protected void |
onMatch(int ai,
int bi)
Invoked for elements matching in a and b . |
void |
setItemsConsistent(boolean itemsConsistent)
Sets the flag indicating if the items are consistent in the from and to items. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected List<T> a
protected List<T> b
protected List<Difference> diffs
Difference
instances.
Constructor Detail |
---|
public Diff(T[] from, T[] to, Comparator<T> comparator)
from
- the "from" value. It is the source list.to
- the "to" value. It is the target list.comparator
- the comparator.public Diff(T[] from, T[] to)
equals
and compareTo
.
from
- the "from" value. It is the source list.to
- the "to" value. It is the target list.public Diff(List<T> from, List<T> to, Comparator<T> comparator)
from
- the "from" value. It is the source list.to
- the "to" value. It is the target list.comparator
- the comparator.public Diff(List<T> from, List<T> to)
equals
and compareTo
.
from
- the "from" value. It is the source list.to
- the "to" value. It is the target list.Method Detail |
---|
public List<Difference> diff()
protected boolean callFinishedA()
finishedA
invoked at the last element in the
from
array.
protected boolean callFinishedB()
finishedB
invoked at the last element in the
to
array.
protected void finishedA(int lastA)
a
, if callFinishedA
returns true.
protected void finishedB(int lastB)
b
, if callFinishedB
returns true.
protected void onANotB(int ai, int bi)
a
and not in b
.
protected void onBNotA(int ai, int bi)
b
and not in a
.
protected void onMatch(int ai, int bi)
a
and b
.
protected boolean equals(T x, T y)
public Integer[] getLongestCommonSubsequences()
protected static boolean isNonzero(Integer i)
protected boolean isGreaterThan(Integer index, Integer val)
protected boolean isLessThan(Integer index, Integer val)
protected Integer getLastValue()
protected void append(Integer value)
protected Integer insert(Integer j, Integer k)
public boolean isItemsConsistent()
public void setItemsConsistent(boolean itemsConsistent)
itemsConsistent
- the flag
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |