Currently I'm developing a merge between two sorted collections of elements of type T (the type is not important as long you provide a means to compare the Type, for example, in Java, A Comparator<T>
will do the work).
What I don't want is to necessarily merge both data structures involved in the merge process (I don't want to get an entire new structure holding both elements merged). What I want is to have some kind of observer of the merge process in order to define what to do with each merged element in another class. For example, a would like to have something like this:
merger.merge(leftCollection,rightCollection,theComparator,theObserver).
Where the observer is a object watching the merge algorithm and gets notified of the actions, i mean :
interface MergeObserver<T> {
/**
* Triggered when the merge algorithm decides to merge only the left entry.
* This case correspond to the case when there is no equivalent entry on the right collection.
*/
public void mergeLeft(T entry);
/**
* Triggered when the merge algorithm decides to merge both entries.
* This case correspond to the case when there exists the same entry on both collections.
*/
public void mergeBoth(T left, T right);
/**
* Triggered when the merge algorithm decides to merge only the right entry.
* This case correspond to the case when there is no equivalent entry on the left collection.
*/
public void mergeRight(T entry);
}
I have already make my implementation for sorted collections, but... I would like to share this feeling, and here comes the question, about if someone has thought of this before, specially in Guava Libraries, and what are the proper terminology employed.