Package org.revapi
Class ReportComparator
- java.lang.Object
-
- org.revapi.ReportComparator
-
- All Implemented Interfaces:
Comparator<Report>
public class ReportComparator extends Object implements Comparator<Report>
Whileelements
of a single API analyzer are by definition mutually comparable, the same doesn't apply for reports. Reports are collected across multiple api analyzers and therefore 2 reports, coming from 2 different api analyzers can contain elements that are not mutually comparable.This comparator tries to overcome that and offer a way of ordering all the reports in some predictable order.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReportComparator.Builder
static class
ReportComparator.Strategy
The comparison strategy defines the way the elements of the same type are compared with each other.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ReportComparator(List<Class<?>> baseTypeOrder, Map<Class<?>,Comparator<?>> perTypeComparators, ReportComparator.Strategy comparisonStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <E extends Element<E>>
intcompare(E e1, E e2)
Compares the two elements based on the comparison strategy.int
compare(Report o1, Report o2)
protected int
defaultCompareIncomparable(Element<?> el1, Element<?> el2)
This method is called to compare the two elements that are of different base types and no explicit order has been set for the base types.protected static Class<?>
getBaseType(Class<?> elementClass)
The elements are always derived from some base type, all subclasses of which must be mutually comparable.protected <E extends Element<E>>
Comparator<E>getComparatorFor(E element)
protected Element<?>
getElement(Report report)
Returns the new element or, if the new element is null, the old element of the report.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Constructor Detail
-
ReportComparator
protected ReportComparator(List<Class<?>> baseTypeOrder, Map<Class<?>,Comparator<?>> perTypeComparators, ReportComparator.Strategy comparisonStrategy)
-
-
Method Detail
-
compare
public int compare(Report o1, Report o2)
- Specified by:
compare
in interfaceComparator<Report>
-
defaultCompareIncomparable
protected int defaultCompareIncomparable(Element<?> el1, Element<?> el2)
This method is called to compare the two elements that are of different base types and no explicit order has been set for the base types. The default implementation just uses the class names of the two elements for the comparison.
-
getComparatorFor
protected <E extends Element<E>> Comparator<E> getComparatorFor(E element)
-
compare
protected <E extends Element<E>> int compare(E e1, E e2)
Compares the two elements based on the comparison strategy. It uses the comparator returned fromgetComparatorFor(Element)
for direct comparisons of any two elements.- Type Parameters:
E
- the base type of the elements- Parameters:
e1
- the first elemente2
- the second element- Returns:
- the result of the comparison
-
getBaseType
protected static Class<?> getBaseType(Class<?> elementClass)
The elements are always derived from some base type, all subclasses of which must be mutually comparable. This method finds such base type.- Parameters:
elementClass
- the type of some element- Returns:
- the base type for comparison
-
-