@Override protected Double doForward(String value) { return Double.valueOf(value); }
@Override protected Double doParse(String parameter) throws NumberFormatException { return Double.valueOf(parameter); }
public static Double boxed(double v) { return Double.valueOf(v); }
public static Double boxed(double v) { return Double.valueOf(v); }
@Override public Double convert(ResponseBody value) throws IOException { return Double.valueOf(value.string()); } }
/** * check if the environment is java 8 or beyond * * @return if on java 8 */ private static boolean isJava8() { String javaVersion = System.getProperty("java.specification.version"); return Double.valueOf(javaVersion) >= 1.8; } }
/** * Append a double 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, double value) { return append(fieldName, Double.valueOf(value)); }
/** * A reference implementation for {@code tryParse} that just catches the exception from {@link * Double#valueOf}. */ private static Double referenceTryParse(String input) { if (input.trim().length() < input.length()) { return null; } try { return Double.valueOf(input); } catch (NumberFormatException e) { return null; } }
private static Matrix read_vector(IOUtil.LineIterator lineIterator) { int rows = Integer.valueOf(lineIterator.next()); double[][] valueArray = new double[rows][1]; String[] args = lineIterator.next().split("\t"); for (int i = 0; i < rows; i++) { valueArray[i][0] = Double.valueOf(args[i]); } return new Matrix(valueArray); }
public void testForMapWildCardWithDefault() { Map<String, Integer> map = Maps.newHashMap(); map.put("One", 1); map.put("Three", 3); Number number = Double.valueOf(42); Function<String, Number> function = Functions.forMap(map, number); assertEquals(1, function.apply("One").intValue()); assertEquals(number, function.apply("Two")); assertEquals(3L, function.apply("Three").longValue()); }
public void testCompare() { for (double x : VALUES) { for (double y : VALUES) { // note: spec requires only that the sign is the same assertEquals(x + ", " + y, Double.valueOf(x).compareTo(y), Doubles.compare(x, y)); } } }
@Test public void convertDoubleToBigInteger() { Double decimal = Double.valueOf(3.14d); assertEquals(new BigInteger("3"), NumberUtils.convertNumberToTargetClass(decimal, BigInteger.class)); }
@GwtIncompatible // Doubles.tryParse private static void checkTryParse(double expected, String input) { assertEquals(Double.valueOf(expected), Doubles.tryParse(input)); assertThat(input) .matches( Pattern.compile( Doubles.FLOATING_POINT_PATTERN.pattern(), Doubles.FLOATING_POINT_PATTERN.flags())); }
@Test public void testStringToDouble() { assertEquals(Double.valueOf("1.0"), conversionService.convert("1.0", Double.class)); }
@Test public void testDoubleToString() { assertEquals("1.0", conversionService.convert(Double.valueOf("1.0"), String.class)); }
@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 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 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 testDefaultFormattersOn() throws Exception { FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean(); factory.afterPropertiesSet(); FormattingConversionService fcs = factory.getObject(); TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern")); LocaleContextHolder.setLocale(Locale.GERMAN); try { Object value = fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor); assertEquals(15.0, value); value = fcs.convert(15.0, descriptor, TypeDescriptor.valueOf(String.class)); assertEquals("15", value); } finally { LocaleContextHolder.resetLocaleContext(); } }