T
- specialization of Storablepublic class BasicComparator<T extends Storable> extends BasicStorable.CdateComparator<T>
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
through ComparatorManager.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); } }
Modifier and Type | Class and Description |
---|---|
static class |
BasicComparator.StringComparisonMethod
Possible implementation of String comparison.
|
Modifier and Type | Field and 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 through
ComparatorManager.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 and Description |
---|
BasicComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compareString(java.lang.String str1,
java.lang.String str2)
Compare the two specified String using default method configured.
|
compare, compareDate
protected final Channel channel
Never null.
protected final JcmsContext jcmsContext
Channel.getCurrentJcmsContext()
if you really need it, but use it wisely.protected final java.lang.String language
Never null.
protected final java.util.Locale locale
Never null.
protected final java.util.Map<java.lang.String,java.lang.Object> contextMap
ComparatorManager.getComparator(Class, String, boolean, Map)
. Never null.
protected BasicComparator.StringComparisonMethod comparisonMethod
public int compareString(java.lang.String str1, java.lang.String str2)
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, see
BasicComparator.StringComparisonMethod
.str1
- the first string to compare, null is authorizedstr2
- the second string to compare, null is authorizedCopyright © 2001-2021 Jalios SA. All Rights Reserved.