@Override protected Float doForward(String value) { return Float.valueOf(value); }
@Override protected Float doParse(String parameter) throws NumberFormatException { return Float.valueOf(parameter); }
public static Float boxed(float v) { return Float.valueOf(v); }
public static Float boxed(float v) { return Float.valueOf(v); }
public Object getObject () { return Float.valueOf(value); } };
public Object getObject () { return Float.valueOf(value); } };
@Override public Float convert(ResponseBody value) throws IOException { return Float.valueOf(value.string()); } }
/** * Append a float field value. * @param fieldName the name of the field, usually the member variable name * @param value the field value * @return this, to support call-chaining */ public ToStringCreator append(String fieldName, float value) { return append(fieldName, Float.valueOf(value)); }
/** * A reference implementation for {@code tryParse} that just catches the exception from {@link * Float#valueOf}. */ private static Float referenceTryParse(String input) { if (input.trim().length() < input.length()) { return null; } try { return Float.valueOf(input); } catch (NumberFormatException e) { return null; } }
public void testCompare() { for (float x : VALUES) { for (float y : VALUES) { // note: spec requires only that the sign is the same assertEquals(x + ", " + y, Float.valueOf(x).compareTo(y), Floats.compare(x, y)); } } }
@GwtIncompatible // Floats.tryParse private static void checkTryParse(float expected, String input) { assertEquals(Float.valueOf(expected), Floats.tryParse(input)); }
@Test public void testStringToFloat() { assertEquals(Float.valueOf("1.0"), conversionService.convert("1.0", Float.class)); }
@Test public void testFloatToString() { assertEquals("1.0", conversionService.convert(Float.valueOf("1.0"), String.class)); }
/** * Test update with dynamic SQL. */ @Test public void testSqlUpdateWithArguments() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ? and PR = ?"; int rowsAffected = 33; given(this.preparedStatement.executeUpdate()).willReturn(rowsAffected); int actualRowsAffected = this.template.update(sql, 4, new SqlParameterValue(Types.NUMERIC, 2, Float.valueOf(1.4142f))); assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected); verify(this.preparedStatement).setObject(1, 4); verify(this.preparedStatement).setObject(2, Float.valueOf(1.4142f), Types.NUMERIC, 2); verify(this.preparedStatement).close(); verify(this.connection).close(); }
@Test public void testLang1087(){ // no sign cases assertEquals(Float.class, NumberUtils.createNumber("0.0").getClass()); assertEquals(Float.valueOf("0.0"), NumberUtils.createNumber("0.0")); // explicit positive sign cases assertEquals(Float.class, NumberUtils.createNumber("+0.0").getClass()); assertEquals(Float.valueOf("+0.0"), NumberUtils.createNumber("+0.0")); // negative sign cases assertEquals(Float.class, NumberUtils.createNumber("-0.0").getClass()); assertEquals(Float.valueOf("-0.0"), NumberUtils.createNumber("-0.0")); }
@Test public void parseNumberUsingNumberFormat() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); String aByte = "" + Byte.MAX_VALUE; String aShort = "" + Short.MAX_VALUE; String anInteger = "" + Integer.MAX_VALUE; String aLong = "" + Long.MAX_VALUE; String aFloat = "" + Float.MAX_VALUE; String aDouble = "" + Double.MAX_VALUE; assertEquals("Byte did not parse", Byte.valueOf(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte.class, nf)); assertEquals("Short did not parse", Short.valueOf(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short.class, nf)); assertEquals("Integer did not parse", Integer.valueOf(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer.class, nf)); assertEquals("Long did not parse", Long.valueOf(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long.class, nf)); assertEquals("Float did not parse", Float.valueOf(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float.class, nf)); assertEquals("Double did not parse", Double.valueOf(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double.class, nf)); }
@Test public void parseNumberRequiringTrimUsingNumberFormat() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); String aByte = " " + Byte.MAX_VALUE + " "; String aShort = " " + Short.MAX_VALUE + " "; String anInteger = " " + Integer.MAX_VALUE + " "; String aLong = " " + Long.MAX_VALUE + " "; String aFloat = " " + Float.MAX_VALUE + " "; String aDouble = " " + Double.MAX_VALUE + " "; assertEquals("Byte did not parse", Byte.valueOf(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte.class, nf)); assertEquals("Short did not parse", Short.valueOf(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short.class, nf)); assertEquals("Integer did not parse", Integer.valueOf(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer.class, nf)); assertEquals("Long did not parse", Long.valueOf(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long.class, nf)); assertEquals("Float did not parse", Float.valueOf(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float.class, nf)); assertEquals("Double did not parse", Double.valueOf(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double.class, nf)); }
@Test public void parseNumberRequiringTrim() { String aByte = " " + Byte.MAX_VALUE + " "; String aShort = " " + Short.MAX_VALUE + " "; String anInteger = " " + Integer.MAX_VALUE + " "; String aLong = " " + Long.MAX_VALUE + " "; String aFloat = " " + Float.MAX_VALUE + " "; String aDouble = " " + Double.MAX_VALUE + " "; assertEquals("Byte did not parse", Byte.valueOf(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte.class)); assertEquals("Short did not parse", Short.valueOf(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short.class)); assertEquals("Integer did not parse", Integer.valueOf(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer.class)); assertEquals("Long did not parse", Long.valueOf(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long.class)); assertEquals("Float did not parse", Float.valueOf(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float.class)); assertEquals("Double did not parse", Double.valueOf(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double.class)); }
@Test public void parseNumber() { String aByte = "" + Byte.MAX_VALUE; String aShort = "" + Short.MAX_VALUE; String anInteger = "" + Integer.MAX_VALUE; String aLong = "" + Long.MAX_VALUE; String aFloat = "" + Float.MAX_VALUE; String aDouble = "" + Double.MAX_VALUE; assertEquals("Byte did not parse", Byte.valueOf(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte.class)); assertEquals("Short did not parse", Short.valueOf(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short.class)); assertEquals("Integer did not parse", Integer.valueOf(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer.class)); assertEquals("Long did not parse", Long.valueOf(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long.class)); assertEquals("Float did not parse", Float.valueOf(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float.class)); assertEquals("Double did not parse", Double.valueOf(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double.class)); }
@Test public void testCreateFloat() { assertEquals("createFloat(String) failed", Float.valueOf("1234.5"), NumberUtils.createFloat("1234.5")); assertEquals("createFloat(null) failed", null, NumberUtils.createFloat(null)); this.testCreateFloatFailure(""); this.testCreateFloatFailure(" "); this.testCreateFloatFailure("\b\t\n\f\r"); // Funky whitespaces this.testCreateFloatFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F"); }