View Javadoc
1 /* 2 * BeanComp.java 3 * 4 * Created on February 7, 2003, 5:47 AM 5 */ 6 7 package com.mlw.fps.util; 8 9 import java.util.Comparator; 10 11 import org.apache.commons.beanutils.BeanUtils; 12 13 /*** 14 * 15 * @author Matthew Wilson 16 */ 17 public class BeanComparable implements Comparator 18 { 19 private int direction = 0; 20 private String method = null; 21 22 /*** Creates a new instance of BeanComp 23 */ 24 public BeanComparable(String method, int direction) 25 { 26 this.method = method; 27 this.direction = direction; 28 } 29 30 public int compare(Object obj1, Object obj2) 31 { 32 try 33 { 34 obj1 = BeanUtils.getProperty(obj1,method); 35 obj2 = BeanUtils.getProperty(obj2,method); 36 if( obj1 instanceof String ) 37 { 38 double v1 = Double.parseDouble(obj1.toString()); 39 double v2 = Double.parseDouble(obj2.toString()); 40 return ((v1>v2)?1:(v1==v2)?0:-1)*direction; 41 } 42 } 43 catch(Exception e) 44 { 45 e.printStackTrace(); 46 } 47 return 0; 48 } 49 50 }

This page was automatically generated by Maven