T
- specialization of Storablepublic class BasicComparator<T extends Storable> extends BasicStorable.CdateComparator<T>
The following fields are available to your implementation :
Channel channel
: the ChannelJcmsContext jcmsContext
: the current JcmsContext if availableString 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)
.// 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 String t1 = p1.getIntro(language); String t2 = p2.getIntro(language); if (t1 == null) { return (t2 == null) ? 0 : -1; } if (t2 == null) { return 1; } t1 = Util.unaccentuate(t1); t2 = Util.unaccentuate(t2); int res = t1.compareToIgnoreCase(t2); if (res != 0) { return res; } return super.compare(p1, p2); } }
Modifier and Type | Field and Description |
---|---|
protected Channel |
channel
The Channel.
|
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
The current JcmsContext, if available.
|
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() |
compare, compareDate
protected final Channel channel
Never null.
protected final JcmsContext jcmsContext
Might be null.
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.
Copyright © 2001-2010 Jalios SA. All Rights Reserved.