Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CustomComparator {
- public static integer compare(Object firstValue, Object secondValue){
- try
- {
- if(firstValue == null || secondValue == null) {
- return null;
- }
- if(firstValue instanceof Date || secondValue instanceof Date) {
- Date dateFirstValue = Date.valueOf(firstValue);
- Date datesecondValue = Date.valueOf(secondValue);
- if(dateFirstValue > datesecondValue){
- return 1;
- }else if(dateFirstValue < datesecondValue){
- return -1;
- }
- return 0;
- }
- if(firstValue instanceof DateTime || secondValue instanceof DateTime) {
- DateTime dateTimeFirstValue = DateTime.valueOf(firstValue);
- DateTime dateTimesecondValue = DateTime.valueOf(secondValue);
- if(dateTimeFirstValue > dateTimesecondValue){
- return 1;
- }else if(dateTimeFirstValue < dateTimesecondValue){
- return -1;
- }
- return 0;
- }
- else{
- Decimal decFirstValue = Decimal.valueOf(String.valueOf(firstValue));
- Decimal decSecondValue = Decimal.valueOf(String.valueOf(secondValue));
- if(decFirstValue > decSecondValue){
- return 1;
- }else if(decFirstValue < decSecondValue){
- return -1;
- }
- return 0;
- }
- }
- catch(Exception ex){
- System.debug('Oh, shi~ Cast error');
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement