KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > sort > DoubleComparer


1 package com.icl.saxon.sort;
2 import com.icl.saxon.expr.*;
3
4 /**
5  * A Comparer used for comparing keys that are Doubles
6  *
7  * @author Michael H. Kay (mhkay@iclway.co.uk)
8  *
9  */

10
11 public class DoubleComparer extends Comparer {
12
13     /**
14     * Compare two String objects according to their numeric values
15     * @return <0 if a<b, 0 if a=b, >0 if a>b
16     * @throws ClassCastException if the objects are of the wrong type for this Comparer
17     */

18
19     public int compare(Object JavaDoc a, Object JavaDoc b) {
20         double a1 = Value.stringToNumber((String JavaDoc)a);
21         double b1 = Value.stringToNumber((String JavaDoc)b);
22         if (Double.isNaN(a1)) {
23             if (Double.isNaN(b1)) {
24                 return 0;
25             } else {
26                 return -1;
27             }
28         }
29         if (Double.isNaN(b1)) {
30             return +1;
31         }
32         if (a1 == b1) return 0;
33         if (a1 < b1) return -1;
34         return +1;
35     }
36     
37         
38 }
39
Popular Tags