public Percentage add(final float value) { return new Percentage((floatValue() + value)); }
public Percentage add(final Percentage value) { return add(value.floatValue()); }
@Override public boolean equals(final Object other) { if (this == other) { return true; } if (other == null) { return false; } return other.getClass() == this.getClass() && equals((Percentage) other); }
@Override public int hashCode() { // multiply by 100 just in case the percentage is being stored as 0.0 to 1.0 return (int) (floatValue() * 100); }
@Override protected Object doRestore(final String data) { return new Percentage(Float.valueOf(data).floatValue()); }
public Percentage subtract(final float value) { return add(-value); }
public void testIsLessThan() { assertTrue(p1.isLessThan(p3)); assertFalse(p3.isLessThan(p1)); assertFalse(p1.isLessThan(p1)); } }
@Override protected String doEncode(final Object object) { final Percentage per = (Percentage) object; return String.valueOf(per.floatValue()); }
@Override protected Object doRestore(final String data) { return new Percentage(Float.valueOf(data).floatValue()); }
@Override protected String doEncode(final Object object) { final Percentage per = (Percentage) object; return String.valueOf(per.floatValue()); }
public Percentage multiply(final float value) { return new Percentage((floatValue() * value)); }
public Percentage subtract(final Percentage value) { return add(-value.floatValue()); }
public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) throws HibernateException, SQLException { float percentage = rs.getFloat(names[0]); if (rs.wasNull()) return null; return new Percentage(percentage); }
public void testEquals() { assertEquals(p1, p2); assertNotSame(p1, p2); assertFalse(p1.equals(p3)); }
private String titleString(final NumberFormat formatter, final Object value) { return value == null ? "" : format.format(((Percentage) value).floatValue()); }
public void testAddFloat() { Percentage p4 = p1.add(10.0f); assertEquals(20.5f, p4.floatValue(), 0.0f); }
@Override protected Object doParse(final Object original, final String text) { try { return new Percentage(new Float(format.parse(text).floatValue())); } catch (final ParseException e) { try { return new Percentage(new Float(DECIMAL_FORMAT.parse(text).floatValue())); } catch (final ParseException ee) { throw new TextEntryParseException("Not a number " + text, ee); } } }
private String titleString(final NumberFormat formatter, final Object value) { return value == null ? "" : format.format(((Percentage) value).floatValue()); }
public void testAddPercentage() { Percentage p4 = p1.add(p3); assertEquals(22.5f, p4.floatValue(), 0.0f); }