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