Advertisement
YuraSidorets

Untitled

Aug 4th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. public class CustomComparator {
  2.            
  3.        public static integer compare(Object firstValue, Object secondValue){
  4.              try
  5.                 {
  6.              if(firstValue == null || secondValue == null) {
  7.                  return null;
  8.              }
  9.              if(firstValue instanceof Date || secondValue instanceof Date) {
  10.                
  11.                     Date dateFirstValue = Date.valueOf(firstValue);
  12.                     Date datesecondValue = Date.valueOf(secondValue);
  13.                    
  14.                     if(dateFirstValue > datesecondValue){
  15.                         return 1;
  16.                     }else if(dateFirstValue < datesecondValue){
  17.                         return -1;
  18.                     }
  19.                     return 0;  
  20.             }
  21.             if(firstValue instanceof DateTime || secondValue instanceof DateTime) {
  22.                
  23.                     DateTime dateTimeFirstValue = DateTime.valueOf(firstValue);
  24.                     DateTime dateTimesecondValue = DateTime.valueOf(secondValue);
  25.                    
  26.                     if(dateTimeFirstValue > dateTimesecondValue){
  27.                         return 1;
  28.                     }else if(dateTimeFirstValue < dateTimesecondValue){
  29.                         return -1;
  30.                     }
  31.                     return 0;  
  32.             }              
  33.              else{
  34.                
  35.                     Decimal decFirstValue = Decimal.valueOf(String.valueOf(firstValue));
  36.                     Decimal decSecondValue =  Decimal.valueOf(String.valueOf(secondValue));
  37.                    
  38.                     if(decFirstValue > decSecondValue){
  39.                         return 1;
  40.                     }else if(decFirstValue < decSecondValue){
  41.                         return -1;
  42.                     }
  43.                     return 0;
  44.                 }
  45.                 }
  46.                 catch(Exception ex){
  47.                             System.debug('Oh, shi~ Cast error');
  48.                                 return null;
  49.                     }
  50.             }
  51.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement