1 package prefuse.data.parser; 2 3 11 public class FloatParser implements DataParser { 12 13 17 public Class getType() { 18 return float.class; 19 } 20 21 24 public String format(Object value) { 25 if ( value == null ) return null; 26 if ( !(value instanceof Number ) ) 27 throw new IllegalArgumentException ( 28 "This class can only format Objects of type Number."); 29 return String.valueOf(((Number )value).floatValue())+"f"; 30 } 31 32 35 public boolean canParse(String text) { 36 try { 37 Float.parseFloat(text); 38 return true; 39 } catch ( NumberFormatException e ) { 40 return false; 41 } 42 } 43 44 47 public Object parse(String text) throws DataParseException { 48 return new Float (parseFloat(text)); 49 } 50 51 57 public static float parseFloat(String text) throws DataParseException { 58 try { 59 return Float.parseFloat(text); 60 } catch ( NumberFormatException e ) { 61 throw new DataParseException(e); 62 } 63 } 64 65 } | Popular Tags |