1 10 package com.hp.hpl.jena.datatypes.xsd.impl; 11 12 import java.math.BigDecimal ; 13 import java.math.BigInteger ; 14 15 import com.hp.hpl.jena.datatypes.*; 16 import com.hp.hpl.jena.datatypes.xsd.*; 17 import com.hp.hpl.jena.graph.impl.LiteralLabel; 18 import com.hp.hpl.jena.shared.impl.JenaParameters; 19 20 29 public class XSDBaseNumericType extends XSDDatatype { 30 31 36 public XSDBaseNumericType(String typeName) { 37 super(typeName); 38 } 39 40 47 public XSDBaseNumericType(String typeName, Class javaClass) { 48 super(typeName, javaClass); 49 } 50 51 52 59 public boolean isValidLiteral(LiteralLabel lit) { 60 if (isBaseTypeCompatible(lit)) { 61 String lex = lit.getLexicalForm(); 62 if (JenaParameters.enableWhitespaceCheckingOfTypedLiterals) { 63 if (lex.trim().equals(lex)) { 64 return isValid(lit.getLexicalForm()); 65 } else { 66 return false; 67 } 68 } else { 69 return isValid(lit.getLexicalForm()); 70 } 71 } else { 72 return false; 73 } 74 } 75 76 80 public boolean isValidValue(Object valueForm) { 81 if (valueForm instanceof Number ) { 82 return isValid(valueForm.toString()); 83 } else { 84 return false; 85 } 86 } 87 88 92 public Object parse(String lexicalForm) throws DatatypeFormatException { 93 checkWhitespace(lexicalForm); 94 return super.parse(lexicalForm); 95 } 96 97 101 protected void checkWhitespace(String lexicalForm) { 102 if (JenaParameters.enableWhitespaceCheckingOfTypedLiterals) { 103 if ( ! lexicalForm.trim().equals(lexicalForm)) { 104 throw new DatatypeFormatException(lexicalForm, this, "whitespace violation"); 105 } 106 } 107 } 108 109 114 public boolean isEqual(LiteralLabel value1, LiteralLabel value2) { 115 Object o1 = value1.getValue(); 116 Object o2 = value2.getValue(); 117 if (!(o1 instanceof Number ) || !(o2 instanceof Number )) { 118 return false; 119 } 120 if (o1 instanceof Float || o1 instanceof Double ) { 121 return (((Number )o1).doubleValue() == ((Number )o2).doubleValue()); 122 } else if (o1 instanceof BigInteger || o1 instanceof BigDecimal ) { 123 return o1.equals(o2); 124 } else { 125 return (((Number )o1).longValue() == ((Number )o2).longValue()); 126 } 127 } 128 } 129 130 159 | Popular Tags |