001 package railo.runtime.type.comparator; 002 003 import railo.runtime.exp.PageException; 004 import railo.runtime.op.Caster; 005 006 007 /** 008 * Implementation of a Comparator, compares to Softregister Objects 009 */ 010 public final class SortRegisterComparator implements ExceptionComparator { 011 012 private boolean isAsc; 013 private PageException pageException=null; 014 private boolean ignoreCase; 015 016 017 /** 018 * constructor of the class 019 * @param isAsc is ascending or descending 020 * @param ignoreCase do ignore case 021 */ 022 public SortRegisterComparator(boolean isAsc, boolean ignoreCase) { 023 this.isAsc=isAsc; 024 this.ignoreCase=ignoreCase; 025 026 } 027 028 /** 029 * @return Returns the expressionException. 030 */ 031 public PageException getPageException() { 032 return pageException; 033 } 034 035 /** 036 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 037 */ 038 public int compare(Object oLeft, Object oRight) { 039 try { 040 if(pageException!=null) return 0; 041 else if(isAsc) return compareObjects(oLeft, oRight); 042 else return compareObjects(oRight, oLeft); 043 } catch (PageException e) { 044 pageException=e; 045 return 0; 046 } 047 } 048 049 private int compareObjects(Object oLeft, Object oRight) throws PageException { 050 String strLeft=Caster.toString(((SortRegister)oLeft).getValue()); 051 String strRight=Caster.toString(((SortRegister)oRight).getValue()); 052 if(ignoreCase) return strLeft.compareToIgnoreCase(strRight); 053 return strLeft.compareTo(strRight); 054 } 055 056 }