public static Byte boxed(byte v) { return Byte.valueOf(v); }
public static Byte boxed(byte v) { return Byte.valueOf(v); }
/** * Gets the value as a Byte instance. * * @return the value as a Byte, never null */ @Override public Byte getValue() { return Byte.valueOf(this.value); }
@Override public Byte getRight() { return Byte.valueOf(rhs); } });
@Override public Byte convert(ResponseBody value) throws IOException { return Byte.valueOf(value.string()); } }
@Override public Object decode(Object jv) { if (jv instanceof Number) { return Byte.valueOf(((Number) jv).byteValue()); } return (Byte) null; } };
@Override public Object decode(Object jv) { if (jv instanceof Number) { return Byte.valueOf(((Number) jv).byteValue()); } return (Byte) null; } };
/** * 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)); }
/** * 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()); }
@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)); }
@Test public void testStringToByte() throws Exception { assertEquals(Byte.valueOf("1"), conversionService.convert("1", Byte.class)); }
@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 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 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)); }
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); } } } }
@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()); }
@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()); }
@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()); }
@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()); }