本文整理了Java中java.lang.Byte.valueOf()
方法的一些代码示例,展示了Byte.valueOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Byte.valueOf()
方法的具体详情如下:
包路径:java.lang.Byte
类名称:Byte
方法名:valueOf
[英]Returns a Byte instance for the specified byte value.
If it is not necessary to get a new Byte instance, it is recommended to use this method instead of the constructor, since it maintains a cache of instances which may result in better performance.
[中]返回指定字节值的字节实例。
如果不需要获取新的字节实例,建议使用此方法而不是构造函数,因为它可以维护实例缓存,从而提高性能。
代码示例来源:origin: apache/incubator-dubbo
public static Byte boxed(byte v) {
return Byte.valueOf(v);
}
代码示例来源:origin: apache/incubator-dubbo
public static Byte boxed(byte v) {
return Byte.valueOf(v);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Gets the value as a Byte instance.
*
* @return the value as a Byte, never null
*/
@Override
public Byte getValue() {
return Byte.valueOf(this.value);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Override
public Byte getRight() {
return Byte.valueOf(rhs);
}
});
代码示例来源:origin: square/retrofit
@Override public Byte convert(ResponseBody value) throws IOException {
return Byte.valueOf(value.string());
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public Object decode(Object jv) {
if (jv instanceof Number) {
return Byte.valueOf(((Number) jv).byteValue());
}
return (Byte) null;
}
};
代码示例来源:origin: apache/incubator-dubbo
@Override
public Object decode(Object jv) {
if (jv instanceof Number) {
return Byte.valueOf(((Number) jv).byteValue());
}
return (Byte) null;
}
};
代码示例来源:origin: spring-projects/spring-framework
/**
* Append a byte 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, byte value) {
return append(fieldName, Byte.valueOf(value));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Gets this mutable as an instance of Byte.
*
* @return a Byte instance containing the value from this mutable
*/
public Byte toByte() {
return Byte.valueOf(byteValue());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parseNumberAsHex() {
String aByte = "0x" + Integer.toHexString(Byte.valueOf(Byte.MAX_VALUE).intValue());
String aShort = "0x" + Integer.toHexString(Short.valueOf(Short.MAX_VALUE).intValue());
String anInteger = "0x" + Integer.toHexString(Integer.MAX_VALUE);
String aLong = "0x" + Long.toHexString(Long.MAX_VALUE);
String aReallyBigInt = "FEBD4E677898DFEBFFEE44";
assertByteEquals(aByte);
assertShortEquals(aShort);
assertIntegerEquals(anInteger);
assertLongEquals(aLong);
assertEquals("BigInteger did not parse",
new BigInteger(aReallyBigInt, 16), NumberUtils.parseNumber("0x" + aReallyBigInt, BigInteger.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testStringToByte() throws Exception {
assertEquals(Byte.valueOf("1"), conversionService.convert("1", Byte.class));
}
代码示例来源: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 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 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 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: google/guava
public void testCompare() {
for (byte x : VALUES) {
for (byte y : VALUES) {
// Only compare the sign of the result of compareTo().
int expected = Byte.valueOf(x).compareTo(y);
int actual = SignedBytes.compare(x, y);
if (expected == 0) {
assertEquals(x + ", " + y, expected, actual);
} else if (expected < 0) {
assertTrue(
x + ", " + y + " (expected: " + expected + ", actual" + actual + ")", actual < 0);
} else {
assertTrue(
x + ", " + y + " (expected: " + expected + ", actual" + actual + ")", actual > 0);
}
}
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testGetAndAddValueObject() {
final MutableByte mutableByte = new MutableByte((byte)0);
final byte result = mutableByte.getAndAdd(Byte.valueOf((byte) 1));
assertEquals((byte) 0, result);
assertEquals((byte) 1, mutableByte.byteValue());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testAddAndGetValueObject() {
final MutableByte mutableByte = new MutableByte((byte)0);
final byte result = mutableByte.addAndGet(Byte.valueOf((byte) 1));
assertEquals((byte) 1, result);
assertEquals((byte) 1, mutableByte.byteValue());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testHashCode() {
final MutableByte mutNumA = new MutableByte((byte) 0);
final MutableByte mutNumB = new MutableByte((byte) 0);
final MutableByte mutNumC = new MutableByte((byte) 1);
assertTrue(mutNumA.hashCode() == mutNumA.hashCode());
assertTrue(mutNumA.hashCode() == mutNumB.hashCode());
assertFalse(mutNumA.hashCode() == mutNumC.hashCode());
assertTrue(mutNumA.hashCode() == Byte.valueOf((byte) 0).hashCode());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testConstructors() {
assertEquals((byte) 0, new MutableByte().byteValue());
assertEquals((byte) 1, new MutableByte((byte) 1).byteValue());
assertEquals((byte) 2, new MutableByte(Byte.valueOf((byte) 2)).byteValue());
assertEquals((byte) 3, new MutableByte(new MutableByte((byte) 3)).byteValue());
assertEquals((byte) 2, new MutableByte("2").byteValue());
}
内容来源于网络,如有侵权,请联系作者删除!