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 @Override 036 public int compare(Object oLeft, Object oRight) { 037 try { 038 if(pageException!=null) return 0; 039 else if(isAsc) return compareObjects(oLeft, oRight); 040 else return compareObjects(oRight, oLeft); 041 } catch (PageException e) { 042 pageException=e; 043 return 0; 044 } 045 } 046 047 private int compareObjects(Object oLeft, Object oRight) throws PageException { 048 String strLeft=Caster.toString(((SortRegister)oLeft).getValue()); 049 String strRight=Caster.toString(((SortRegister)oRight).getValue()); 050 if(ignoreCase) return strLeft.compareToIgnoreCase(strRight); 051 return strLeft.compareTo(strRight); 052 } 053 054 }