1 package com.thaiopensource.datatype.xsd; 2 3 import java.math.BigDecimal ; 4 5 import org.relaxng.datatype.ValidationContext; 6 7 class DecimalDatatype extends DatatypeBase implements OrderRelation { 8 9 boolean lexicallyAllows(String str) { 10 int len = str.length(); 11 if (len == 0) 12 return false; 13 int i = 0; 14 switch (str.charAt(i)) { 15 case '+': 16 case '-': 17 if (++i == len) 18 return false; 19 } 20 boolean hadDecimalPoint = false; 21 if (str.charAt(i) == '.') { 22 hadDecimalPoint = true; 23 if (++i == len) 24 return false; 25 } 26 do { 27 switch (str.charAt(i)) { 28 case '0': 29 case '1': 30 case '2': 31 case '3': 32 case '4': 33 case '5': 34 case '6': 35 case '7': 36 case '8': 37 case '9': 38 break; 39 case '.': 40 if (hadDecimalPoint) 41 return false; 42 hadDecimalPoint = true; 43 break; 44 default: 45 return false; 46 } 47 } while (++i < len); 48 return true; 49 } 50 51 Object getValue(String str, ValidationContext vc) { 52 if (str.charAt(0) == '+') 53 str = str.substring(1); return new BigDecimal (str); 55 } 56 57 OrderRelation getOrderRelation() { 58 return this; 59 } 60 61 public boolean isLessThan(Object obj1, Object obj2) { 62 return ((BigDecimal )obj1).compareTo((BigDecimal )obj2) < 0; 63 } 64 65 70 71 public boolean sameValue(Object value1, Object value2) { 72 return ((BigDecimal )value1).compareTo((BigDecimal )value2) == 0; 73 } 74 75 public int valueHashCode(Object value) { 76 return ((BigDecimal )value).toBigInteger().hashCode(); 77 } 78 79 } 80 | Popular Tags |