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            @Override
033            public int compare(Object oLeft, Object oRight) {
034                    try {
035                            if(pageException!=null) return 0;
036                            else if(isAsc) return compareObjects(oLeft, oRight);
037                            else return compareObjects(oRight, oLeft);
038                    } catch (PageException e) {
039                            pageException=e;
040                            return 0;
041                    }
042            }
043            
044            private int compareObjects(Object oLeft, Object oRight) throws PageException {
045            /*return Operator.compare(
046                    ((SortRegister)oLeft).getValue(),
047                    ((SortRegister)oRight).getValue()
048            );
049            */
050            return Operator.compare(
051                    Caster.toDoubleValue(((SortRegister)oLeft).getValue())
052                    ,
053                    Caster.toDoubleValue(((SortRegister)oRight).getValue())
054            );
055            
056            }
057    
058    }