1 package org.displaytag.test; 2 3 import java.util.Comparator ; 4 5 import org.apache.commons.beanutils.ConvertUtils; 6 7 8 14 public class NumberComparator implements Comparator 15 { 16 17 20 public int compare(Object obj1, Object obj2) 21 { 22 double dbl1 = 0; 23 if (obj1 instanceof Number ) 24 { 25 dbl1 = ((Number ) obj1).doubleValue(); 26 } 27 else if (obj1 != null) 28 { 29 dbl1 = ((Number ) ConvertUtils.convert(obj1.toString(), Number .class)).doubleValue(); 30 } 31 32 double dbl2 = 0; 33 if (obj2 instanceof Number ) 34 { 35 dbl2 = ((Number ) obj2).doubleValue(); 36 } 37 else if (obj1 != null) 38 { 39 dbl2 = ((Number ) ConvertUtils.convert(obj2.toString(), Number .class)).doubleValue(); 40 } 41 42 return new Double (dbl1).compareTo(new Double (dbl2)); 43 } 44 } 45 | Popular Tags |