1 package prefuse.data.parser; 2 3 8 public class ByteParser implements DataParser { 9 10 14 public Class getType() { 15 return byte.class; 16 } 17 18 21 public String format(Object value) { 22 if ( value == null ) return null; 23 if ( !(value instanceof Number ) ) 24 throw new IllegalArgumentException ( 25 "This class can only format Objects of type Number."); 26 return String.valueOf(((Number )value).byteValue()); 27 } 28 29 32 public boolean canParse(String text) { 33 try { 34 Byte.parseByte(text); 35 return true; 36 } catch ( NumberFormatException e ) { 37 return false; 38 } 39 } 40 41 44 public Object parse(String text) throws DataParseException { 45 return new Byte (parseByte(text)); 46 } 47 48 54 public static byte parseByte(String text) throws DataParseException { 55 try { 56 return Byte.parseByte(text); 57 } catch ( NumberFormatException e ) { 58 throw new DataParseException(e); 59 } 60 } 61 62 } | Popular Tags |