Package com.jalios.jcms
Class QueryResultSet.ScoreComparator<T extends Publication>
- java.lang.Object
-
- com.jalios.jstore.BasicStorable.CdateComparator<T>
-
- com.jalios.jcms.comparator.BasicComparator<T>
-
- com.jalios.jcms.QueryResultSet.ScoreComparator<T>
-
- 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>
ThisComparator
compares twoObject
s using a score retrieved from a map ofObject
tofloat
.
If two Storable have the same score, a "parent" compararator is used, default "parent" comparator isMdateComparator
.
Note: because a high score must be first, it behaves in the opposite way of whatComparator
says see thecompare(Object, Object)
method.- Since:
- jcms-5.5.0
- Version:
- $Revision: 133461 $
- Author:
- Olivier Jaquemet
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.jalios.jcms.comparator.BasicComparator
BasicComparator.StringComparisonMethod
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PARENT_COMPARATOR
static java.lang.String
QUERY_RESULT_SET
-
Fields inherited from class com.jalios.jcms.comparator.BasicComparator
channel, comparisonMethod, contextMap, jcmsContext, language, locale
-
-
Constructor Summary
Constructors Constructor Description ScoreComparator()
Initialize aScoreComparator
from the contextual information retrieved through ComparatorManager parameterScoreComparator(QueryResultSet resultSet, java.util.Comparator parentComparator)
Initialize aScoreComparator
using the given parentComparator
, if null, default withMdateComparator
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(T o1, T o2)
Compare two Object using their score from the QueryResulSet.-
Methods inherited from class com.jalios.jcms.comparator.BasicComparator
compareString
-
Methods inherited from class com.jalios.jstore.BasicStorable.CdateComparator
compareDate
-
-
-
-
Field Detail
-
PARENT_COMPARATOR
public static final java.lang.String PARENT_COMPARATOR
- See Also:
- Constant Field Values
-
QUERY_RESULT_SET
public static final java.lang.String QUERY_RESULT_SET
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ScoreComparator
public ScoreComparator()
Initialize aScoreComparator
from the contextual information retrieved through ComparatorManager parameter- A parent
Comparator
, is retrieved using attributePARENT_COMPARATOR
, if null, default withMdateComparator
. - The
QueryResultSet
, is retrieved using attributeQUERY_RESULT_SET
, must not be null.
- Throws:
java.lang.IllegalArgumentException
- if QueryResultSet is null
- A parent
-
ScoreComparator
public ScoreComparator(QueryResultSet resultSet, java.util.Comparator parentComparator)
Initialize aScoreComparator
using the given parentComparator
, if null, default withMdateComparator
.- Parameters:
resultSet
- theQueryResultSet
from which to retrieve score of eachPublication
.parentComparator
- theComparator
to use when score of comparedObject
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 interfacejava.util.Comparator<T extends Publication>
- Overrides:
compare
in classBasicStorable.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.
-
-