/** {@inheritDoc} */ @Override public Float fromString(String v) { try { return new Float(v); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot cast " + v + "to expected " + Float.class, nbe); } }
/** {@inheritDoc} */ @Override public Double fromString(String v) { try { return new Double(v); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot cast " + v + "to expected " + Double.class, nbe); } }
/** {@inheritDoc} */ @Override public BigDecimal fromString(String v) { try { return new BigDecimal(v); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot cast " + v + "to expected " + BigDecimal.class, nbe); } }
/** {@inheritDoc} */ @Override public Short fromString(String v) { try { return new Short(v); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot cast " + v + "to expected " + Short.class, nbe); } }
/** {@inheritDoc} */ @Override public Integer fromString(String v) { try { return new Integer(v); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot cast " + v + "to expected " + Integer.class, nbe); } }
/** {@inheritDoc} */ @Override public Long fromString(String v) { try { return new Long(v); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot cast " + v + "to expected " + Long.class, nbe); } }
/** {@inheritDoc} */ @Override public BigInteger fromString(String v) { try { return new BigInteger(v); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot cast " + v + "to expected " + BigInteger.class, nbe); } }
/** {@inheritDoc} */ @Override public Byte fromString(String v) { if (v == null) return null; if (v.length() == 0 || v.length() > 3) { throw new InvalidPropertyTypeException("A byte is a single byte, a single character"); } return v.getBytes()[0]; }
/** {@inheritDoc} */ @Override public Boolean fromString(String v) { if (!Boolean.TRUE.toString().equals(v.toLowerCase()) && !Boolean.FALSE.toString().equals(v) ) { throw new InvalidPropertyTypeException("Cannot cast " + v + "to expected " + Boolean.class); } return new Boolean(v); }
/** {@inheritDoc} */ @Override public byte getByte(String key) { String value = null; try { value = (String) getValue(key); return Byte.parseByte(value); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot create Byte from " + value, nbe); } }
/** * {@inheritDoc} * * Use the object : * <li> To handle 'null' and avoid NPE on unboxing * <li> To raise classCast if invalid property type... */ @Override public boolean getBoolean(String key) { String value = (String) getValue(key); if (!Boolean.TRUE.toString().equals(value.toLowerCase()) && !Boolean.FALSE.toString().equals(value.toLowerCase()) ) { throw new InvalidPropertyTypeException("Cannot create Boolean from " + value); } return new Boolean(value).booleanValue(); }
/** {@inheritDoc} */ @Override public double getDouble(String key) { try { return new Double((String) getValue(key)).doubleValue(); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot create Double from " + getValue(key), nbe); } }
/** {@inheritDoc} */ @Override public float getFloat(String key) { try { return new Float((String) getValue(key)).floatValue(); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot create Float from " + getValue(key), nbe); } }
/** {@inheritDoc} */ @Override public int getInt(String key) { try { return new Integer((String) getValue(key)).intValue(); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot create Integer from " + getValue(key), nbe); } }
/** {@inheritDoc} */ @Override public long getLong(String key) { try { return new Long((String) getValue(key)).longValue(); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot create Long from " + getValue(key), nbe); } }
/** {@inheritDoc} */ @Override public short getShort(String key) { try { return new Short((String) getValue(key)).shortValue(); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot create Short from " + getValue(key), nbe); } }
/** {@inheritDoc} */ @Override public BigDecimal getBigDecimal(String key) { try { return new BigDecimal((String) getValue(key)); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot create BigDecimal from " + getValue(key), nbe); } }
/** {@inheritDoc} */ @Override public BigInteger getBigInteger(String key) { try { return new BigInteger((String) getValue(key)); } catch(NumberFormatException nbe) { throw new InvalidPropertyTypeException("Cannot create BigInteger from " + getValue(key), nbe); } }