|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.innig.collect.CollectionDiff
net.innig.collect.ListDiff
public class ListDiff
Finds the difference between two ordered lists. Given a pair of lists,
ListDiff provides a sequence of steps which will mutate the first list
into the second. These steps implement ListDiff.Step, and include
insert, move, and remove. You can ask for the steps using getSteps(),
or call applySteps to have the ListDiff walk
a ListMutator through the steps.
ListDiff is useful for situations where some structure (such as a user interface) is shadowing a changing list, and you don't want to rebuild the structure from scratch every time the list changes -- perhaps beacuse the cost of recreating the structure is high, or because you don't want to lose state information about existing elements whose position has changed in the list.
The algorithm ListDiff uses for generating the steps is quite simple. It does not guarantee the shortest possible sequence of steps, but usually comes quite close.
| Maturity: This is a mature API, and a stable implementation. It performs well in informal testing, but has not undergone methodical or real-world testing. |
| Plans: There are no current plans to expand or revise this class's functionality. It would be worth researching alternative algorithms for generating the steps. |
| Nested Class Summary | |
|---|---|
class |
ListDiff.Insert
A list transformation step: insert an object at a given position. |
class |
ListDiff.Move
A list transformation step: move an object from one position to another. |
class |
ListDiff.Remove
A list transformation step: remove an object at a given position. |
class |
ListDiff.Step
A step in a list transformation. |
| Constructor Summary | |
|---|---|
ListDiff(java.util.List oldStuff,
java.util.List newStuff)
Prepares a comparison of two lists. |
|
| Method Summary | |
|---|---|
void |
applySteps(ListMutator mutator)
Walks a ListMutator through the sequence of steps which transform the old list into the new. |
boolean |
equals(java.lang.Object other)
Returns true if the other object is a list diff comparing equal lists. |
java.util.Iterator |
getSteps()
Returns a sequence of steps which transform the old list into the new. |
static void |
main(java.lang.String[] args)
For testing |
| Methods inherited from class net.innig.collect.CollectionDiff |
|---|
getAdded, getRemoved, getSame, hashCode, sameElements |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ListDiff(java.util.List oldStuff,
java.util.List newStuff)
| Method Detail |
|---|
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exceptionpublic java.util.Iterator getSteps()
ListDiff.Step objects.
public void applySteps(ListMutator mutator)
public boolean equals(java.lang.Object other)
equals in class CollectionDiff
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||