Package com.jalios.jcms.comparator
Class BasicComparator<T extends Storable>
- java.lang.Object
-
- com.jalios.jstore.BasicStorable.CdateComparator<T>
-
- com.jalios.jcms.comparator.BasicComparator<T>
-
- Type Parameters:
T
- specialization of Storable
- All Implemented Interfaces:
java.util.Comparator<T>
- Direct Known Subclasses:
Category.NameComparator
,Data.DataNameComparator
,Group.NameComparator
,Member.FirstNameComparator
,Member.NameComparator
,Publication.TitleComparator
,Publication.WorkspaceComparator
,QueryResultSet.ScoreComparator
,Workspace.NameComparator
public class BasicComparator<T extends Storable> extends BasicStorable.CdateComparator<T>
Basic comparator class providing advanced contextual informations and default comparison of Storable using their cdate.The following fields are available to your implementation :
Channel channel
: the ChannelString language
: current user language or default channel language.Locale locale
: current user Locale or default channel Locale.Map contextMap
: a Map containing contextual information received throughComparatorManager.getComparator(Class, String, boolean, Map)
.
compareString(String, String)
for simpler, homogenous and configurable string comparison.Example :
// Sorts Article by alphabetical order of their "intro" field, using current language. // Declare this comparator using the following property : // comparator.Article.articleintro: com.example.jcms.comparator.MyArticleIntroComparator public class MyArticleIntroComparator extends BasicComparator<Article> { public int compare(Article p1, Article p2) { // object nullity check if (p1 == null) { return (p2 == null) ? 0 : -1; } if (p2 == null) { return 1; } // Retrieve Article introduction int res = compareString(p1.getIntro(language), p2.getIntro(language)); if (res != 0) { return res; } return super.compare(p1, p2); } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BasicComparator.StringComparisonMethod
Possible implementation of String comparison.
-
Field Summary
Fields Modifier and Type Field Description protected Channel
channel
The Channel.protected BasicComparator.StringComparisonMethod
comparisonMethod
protected java.util.Map<java.lang.String,java.lang.Object>
contextMap
Contextual information map, retrieved throughComparatorManager.getComparator(Class, String, boolean, Map)
.protected JcmsContext
jcmsContext
Deprecated.protected java.lang.String
language
Current user language or default channel language.protected java.util.Locale
locale
Current user Locale or default channel Locale.
-
Constructor Summary
Constructors Constructor Description BasicComparator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareString(java.lang.String str1, java.lang.String str2)
Compare the two specified String using default method configured.-
Methods inherited from class com.jalios.jstore.BasicStorable.CdateComparator
compare, compareDate
-
-
-
-
Field Detail
-
channel
protected final Channel channel
The Channel.Never null.
-
jcmsContext
protected final JcmsContext jcmsContext
Deprecated.Was used to access the current JcmsContext. Warning : This field is always null since jcms-10.0.5 (JCMS-8435) to prevent a memory leak.
This variable will be removed in a future version.
SeeChannel.getCurrentJcmsContext()
if you really need it, but use it wisely.
-
language
protected final java.lang.String language
Current user language or default channel language.Never null.
-
locale
protected final java.util.Locale locale
Current user Locale or default channel Locale.Never null.
-
contextMap
protected final java.util.Map<java.lang.String,java.lang.Object> contextMap
Contextual information map, retrieved throughComparatorManager.getComparator(Class, String, boolean, Map)
.Never null.
-
comparisonMethod
protected BasicComparator.StringComparisonMethod comparisonMethod
-
-
Method Detail
-
compareString
public int compareString(java.lang.String str1, java.lang.String str2)
Compare the two specified String using default method configured.Example of use :
public int compare(Article p1, Article p2) { // object nullity check if (p1 == null) { return (p2 == null) ? 0 : -1; } if (p2 == null) { return 1; } // Retrieve Article introduction int res = compareString(p1.getIntro(language), p2.getIntro(language)); if (res != 0) { return res; } return super.compare(m1, m2); }
Default String comparison method can be configured globally or per class using property, seeBasicComparator.StringComparisonMethod
.- Parameters:
str1
- the first string to compare, null is authorizedstr2
- the second string to compare, null is authorized- Returns:
- Returns an integer value. Value is less than zero if str1 is lexicographically less than str2, value is zero if str1 and str2 are equal and value is greater than str1 if this is lexicographically greater than str2.
- Since:
- jcms-10.0.4 / JCMS-8000
-
-