com.jalios.jcms.comparator
Class BasicComparator<T extends Storable>

java.lang.Object
  extended by com.jalios.jstore.BasicStorable.CdateComparator<T>
      extended by com.jalios.jcms.comparator.BasicComparator<T>
Type Parameters:
T - specialization of Storable
All Implemented Interfaces:
Comparator<T>
Direct Known Subclasses:
Data.DataNameComparator, 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 :

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
     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);
   }
 }
 


Field Summary
protected  Channel channel
          The Channel.
protected  Map<String,Object> contextMap
          Contextual information map, retrieved through ComparatorManager.getComparator(Class, String, boolean, Map).
protected  JcmsContext jcmsContext
          The current JcmsContext, if available.
protected  String language
          Current user language or default channel language.
protected  Locale locale
          Current user Locale or default channel Locale.
 
Constructor Summary
BasicComparator()
           
 
Method Summary
 
Methods inherited from class com.jalios.jstore.BasicStorable.CdateComparator
compare, compareDate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

channel

protected final Channel channel
The Channel.

Never null.


jcmsContext

protected final JcmsContext jcmsContext
The current JcmsContext, if available.

Might be null.


language

protected final String language
Current user language or default channel language.

Never null.


locale

protected final Locale locale
Current user Locale or default channel Locale.

Never null.


contextMap

protected final Map<String,Object> contextMap
Contextual information map, retrieved through ComparatorManager.getComparator(Class, String, boolean, Map).

Never null.

Constructor Detail

BasicComparator

public BasicComparator()


Copyright © 2001-2010 Jalios SA. All Rights Reserved.