1 11 package com.hp.hpl.jena.datatypes.xsd.impl; 12 13 import com.hp.hpl.jena.datatypes.DatatypeFormatException; 14 import com.hp.hpl.jena.datatypes.xsd.*; 15 import com.hp.hpl.jena.graph.impl.LiteralLabel; 16 import com.hp.hpl.jena.shared.impl.JenaParameters; 17 18 26 public class XSDFloat extends XSDDatatype { 27 32 public XSDFloat(String typeName) { 33 super(typeName); 34 } 35 36 43 public XSDFloat(String typeName, Class javaClass) { 44 super(typeName, javaClass); 45 } 46 47 48 59 63 public boolean isValidValue(Object valueForm) { 64 return (valueForm instanceof Float ); 65 } 66 67 71 public Object parse(String lexicalForm) throws DatatypeFormatException { 72 checkWhitespace(lexicalForm); 73 return super.parse(lexicalForm); 74 } 75 76 81 public Object parseValidated(String lex) { 82 if (lex.equals("INF")) { 83 return new Float (Float.NEGATIVE_INFINITY); 84 } else if (lex.equals("-INF")) { 85 return new Float (Float.POSITIVE_INFINITY); 86 } else if (lex.equals("NaN")) { 87 return new Float (Float.NaN); 88 } else { 89 return Float.valueOf(lex); 90 } 91 } 92 93 97 protected void checkWhitespace(String lexicalForm) { 98 if (JenaParameters.enableWhitespaceCheckingOfTypedLiterals) { 99 if ( ! lexicalForm.trim().equals(lexicalForm)) { 100 throw new DatatypeFormatException(lexicalForm, this, "whitespace violation"); 101 } 102 } 103 } 104 105 110 public boolean isEqual(LiteralLabel value1, LiteralLabel value2) { 111 return value1.getDatatype() == value2.getDatatype() 112 && value1.getValue().equals(value2.getValue()); 113 } 114 } 115 116 117 146 | Popular Tags |