KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > datatype > xsd > FloatDatatype


1 package com.thaiopensource.datatype.xsd;
2
3 import org.relaxng.datatype.ValidationContext;
4
5 class FloatDatatype extends DoubleDatatype {
6
7   Object JavaDoc getValue(String JavaDoc str, ValidationContext vc) {
8     if (str.equals("INF"))
9       return new Float JavaDoc(Float.POSITIVE_INFINITY);
10     if (str.equals("-INF"))
11       return new Float JavaDoc(Float.NEGATIVE_INFINITY);
12     if (str.equals("NaN"))
13       return new Float JavaDoc(Float.NaN);
14     return new Float JavaDoc(str);
15   }
16
17   public boolean isLessThan(Object JavaDoc obj1, Object JavaDoc obj2) {
18     return ((Float JavaDoc)obj1).floatValue() < ((Float JavaDoc)obj2).floatValue();
19   }
20
21   public boolean sameValue(Object JavaDoc value1, Object JavaDoc value2) {
22     float f1 = ((Float JavaDoc)value1).floatValue();
23     float f2 = ((Float JavaDoc)value2).floatValue();
24     // NaN = NaN
25
return f1 == f2 || (f1 != f1 && f2 != f2);
26   }
27 }
28
Popular Tags