Package org.revapi

Class ReportComparator

  • All Implemented Interfaces:
    Comparator<Report>

    public class ReportComparator
    extends Object
    implements Comparator<Report>
    While elements 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.

    • Method Detail

      • 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 from getComparatorFor(Element) for direct comparisons of any two elements.
        Type Parameters:
        E - the base type of the elements
        Parameters:
        e1 - the first element
        e2 - 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
      • getElement

        protected Element<?> getElement​(Report report)
        Returns the new element or, if the new element is null, the old element of the report. Thus the result is always a non-null value.