E - the element type.K - the key type (either the same as the element or a key contained in each list element).public abstract class ListMerger<E,K> extends Object
| Constructor and Description |
|---|
ListMerger() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
add(List<E> dest,
int index,
E element)
Add the given
element to the given destination-List dest at the specified index. |
protected abstract K |
getKey(E element)
Get the key from the given
element. |
void |
merge(List<E> source,
List<E> dest)
Merge the given source into the given destination.
|
protected void |
populateDestKey2element() |
protected void |
populateSourceKey2element() |
protected abstract void |
update(List<E> dest,
int index,
E sourceElement,
E destElement)
Update the the given
destElement with the data from sourceElement; or replace it altogether. |
public ListMerger()
public void merge(List<E> source, List<E> dest)
After this operation, both lists are semantically equal. This does not mean that their
equals(...) method returns true, though! This is, because the lists are merged
based on a key which might be wrapped by the elements. The elements are not required
to correctly implement equals(...).
source - the source from which to copy. Must not be null.dest - the destination into which to write. Must not be null.protected void add(List<E> dest, int index, E element)
element to the given destination-List dest at the specified index.
The default implementation simply calls: dest.add(index, element);
dest - the destination. Never null.index - the index at which the new element should be added.element - the element to be added.protected abstract K getKey(E element)
element.
If the element is the same as the key, this method should return the given element.
element - the element from which to extract the key. May be null, if the
source or the destination List contains null elements.null.protected abstract void update(List<E> dest, int index, E sourceElement, E destElement)
destElement with the data from sourceElement; or replace it altogether.
Depending on whether the elements wrap the actual information in a mutable way, or whether they
are immutable, this method may either copy the data from the sourceElement into the destElement
or instead invoke dest.set(index, sourceElement).
Important: This method is only invoked, if the key of both
sourceElement and destElement is the same!
dest - the destination List. Never null.index - the index in dest addressing the element to be replaced.sourceElement - the source from which to copy. May be null, if the source contains
null elements.destElement - the destination into which to write. May be null, if the destination contains
null elements.protected void populateSourceKey2element()
protected void populateDestKey2element()
Copyright © 2013–2019. All rights reserved.