本文整理了Java中java.lang.Double.valueOf()
方法的一些代码示例,展示了Double.valueOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Double.valueOf()
方法的具体详情如下:
包路径:java.lang.Double
类名称:Double
方法名:valueOf
[英]Returns a Double instance for the specified double value.
[中]
代码示例来源:origin: google/guava
@Override
protected Double doForward(String value) {
return Double.valueOf(value);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected Double doParse(String parameter) throws NumberFormatException {
return Double.valueOf(parameter);
}
代码示例来源:origin: apache/incubator-dubbo
public static Double boxed(double v) {
return Double.valueOf(v);
}
代码示例来源:origin: apache/incubator-dubbo
public static Double boxed(double v) {
return Double.valueOf(v);
}
代码示例来源:origin: square/retrofit
@Override public Double convert(ResponseBody value) throws IOException {
return Double.valueOf(value.string());
}
}
代码示例来源:origin: apache/incubator-dubbo
/**
* 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;
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* 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));
}
代码示例来源:origin: google/guava
/**
* 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;
}
}
代码示例来源:origin: hankcs/HanLP
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);
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
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));
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void convertDoubleToBigInteger() {
Double decimal = Double.valueOf(3.14d);
assertEquals(new BigInteger("3"), NumberUtils.convertNumberToTargetClass(decimal, BigInteger.class));
}
代码示例来源:origin: google/guava
@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()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testStringToDouble() {
assertEquals(Double.valueOf("1.0"), conversionService.convert("1.0", Double.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testDoubleToString() {
assertEquals("1.0", conversionService.convert(Double.valueOf("1.0"), String.class));
}
代码示例来源:origin: spring-projects/spring-framework
@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));
}
代码示例来源:origin: spring-projects/spring-framework
@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));
}
代码示例来源:origin: spring-projects/spring-framework
@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));
}
代码示例来源:origin: spring-projects/spring-framework
@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));
}
代码示例来源:origin: spring-projects/spring-framework
@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();
}
}
内容来源于网络,如有侵权,请联系作者删除!