Class QueryResultSet.ScoreComparator<T extends Publication>

  • Type Parameters:
    T - the type
    All Implemented Interfaces:
    java.util.Comparator<T>
    Enclosing class:
    QueryResultSet

    public static class QueryResultSet.ScoreComparator<T extends Publication>
    extends BasicComparator<T>
    This Comparator compares two Objects using a score retrieved from a map of Object to float.
    If two Storable have the same score, a "parent" compararator is used, default "parent" comparator is MdateComparator.
    Note: because a high score must be first, it behaves in the opposite way of what Comparator says see the compare(Object, Object) method.
    Since:
    jcms-5.5.0
    Author:
    Olivier Jaquemet
    • Constructor Detail

      • ScoreComparator

        public ScoreComparator()
        Initialize a ScoreComparator from the contextual information retrieved through ComparatorManager parameter

        • A parent Comparator, is retrieved using attribute PARENT_COMPARATOR, if null, default with MdateComparator.
        • The QueryResultSet, is retrieved using attribute QUERY_RESULT_SET, must not be null.
        Throws:
        java.lang.IllegalArgumentException - if QueryResultSet is null
      • ScoreComparator

        public ScoreComparator​(QueryResultSet resultSet,
                               java.util.Comparator parentComparator)
        Initialize a ScoreComparator using the given parent Comparator, if null, default with MdateComparator.
        Parameters:
        resultSet - the QueryResultSet from which to retrieve score of each Publication.
        parentComparator - the Comparator to use when score of compared Object are identical.
        Throws:
        java.lang.IllegalArgumentException - if QueryResultSet is null
    • Method Detail

      • compare

        public int compare​(T o1,
                           T o2)
        Compare two Object using their score from the QueryResulSet. If score are equals, use the parent Comparator.
        Specified by:
        compare in interface java.util.Comparator<T extends Publication>
        Overrides:
        compare in class BasicStorable.CdateComparator<T extends Publication>
        Returns:
        1 when o1 has a lower score than o2, -1 when has o1 higher score than o2 and returns parentComparator.compare value when scores are equals.