Package org.revapi
Interface CorrespondenceComparatorDeducer<E extends Element<E>>
-
public interface CorrespondenceComparatorDeducer<E extends Element<E>>
A correspondence comparator deducer produces a comparator that is used to compare elements from 2 collections.This is important in situations where the choice of the API comparison "partner" element cannot be determined without knowing its "neighborhood" in both element forests. A concrete example of this is comparison of overloaded methods.
- Since:
- 0.4.0
- Author:
- Lukas Krejci
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <E extends Element<E>>
CorrespondenceComparatorDeducer<E>editDistance(BiPredicate<? super E,? super E> equality)
This correspondence deducer is a good match for situations where the ordering of the children of some element is not semantic but rather positional, e.g.static <E extends Element<E>>
CorrespondenceComparatorDeducer<E>naturalOrder()
Comparator<? super E>
sortAndGetCorrespondenceComparator(List<E> first, List<E> second)
Deduces the correspondence comparator and sorts the provided lists so that the comparator, when used to compare the elements for the two lists mutually is consistent.
-
-
-
Method Detail
-
naturalOrder
static <E extends Element<E>> CorrespondenceComparatorDeducer<E> naturalOrder()
- Returns:
- a deducer that just uses the natural order of elements.
-
editDistance
static <E extends Element<E>> CorrespondenceComparatorDeducer<E> editDistance(BiPredicate<? super E,? super E> equality)
This correspondence deducer is a good match for situations where the ordering of the children of some element is not semantic but rather positional, e.g. method parameters or elements of an array. The deducer will then return a comparator that will make Revapi produce the minimal set of changes necessary to transform the old into the new.- Type Parameters:
E
- the base type of the elements- Parameters:
equality
- a function to determine the element equality- Returns:
- a correspondence comparator deducer that will produce a diff-like ordering of the elements
-
sortAndGetCorrespondenceComparator
Comparator<? super E> sortAndGetCorrespondenceComparator(List<E> first, List<E> second)
Deduces the correspondence comparator and sorts the provided lists so that the comparator, when used to compare the elements for the two lists mutually is consistent.The collections will contain elements of different types (which is consistent with how
ElementForest
stores the children) and it is assumed that the sorter is able to pick and choose which types of elements it is able to sort. The collections will be sorted according the natural order of the elements when entering this method.- Parameters:
first
- the first collection of elementssecond
- the second collection of elements
-
-