public static Byte boxed(byte v) { return Byte.valueOf(v); }
@Override public Byte apply(String input) { return Byte.parseByte(input); } };
public static byte unboxed(Byte v) { return v == null ? 0 : v.byteValue(); }
/** * Get a byte associated with the given configuration key. * * @param key The configuration key. * @param defaultValue The default value. * @return The associated byte. * @throws ClassCastException is thrown if the key maps to an * object that is not a Byte. * @throws NumberFormatException is thrown if the value mapped * by the key has not a valid number format. */ public byte getByte(String key, byte defaultValue) { return getByte(key, new Byte(defaultValue)).byteValue(); }
/** * Returns a Byte instance representing the specified byte. * Byte.valueOf was added in JDK 1.5. * * @param b a byte value. * @return a Byte instance representing b. */ protected static Byte valueOf(final byte b) { return new Byte(b); }
/** * Returns the Byte value for the given key. If the key does not exists it will return the default value given. * The method fails if the value is not a Byte. */ public byte getByte(String key, byte defaultValue) { addToDefaults(key, Byte.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } else { return Byte.valueOf(value); } }
/** * Helper method called by {@link #toString()} in order to convert a single map key into a string. * This is protected to allow subclasses to override the appearance of a given key. */ protected String keyToString(byte key) { return Byte.toString(key); }
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 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()); }
public void set(String key, Byte value) { if (value != null) { attributes.put(key, value.intValue()); } }
/** * Gets the value as a Byte instance. * * @return the value as a Byte, never null */ public Object getValue() { return new Byte(this.value); }
@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)); }
public static String formatByte(byte b) { if (b == Byte.MAX_VALUE) { return "Byte.MAX_VALUE"; } if (b == Byte.MIN_VALUE) { return "Byte.MIN_VALUE"; } return "(byte) " + Byte.toString(b); }
@Override public void toJson(JsonWriter writer, Byte value) throws IOException { writer.value(value.intValue() & 0xff); }
public static Byte boxed(byte v) { return Byte.valueOf(v); }
/** * Constructs a new MutableByte parsing the given string. * * @param value the string to parse, not null * @throws NumberFormatException if the string cannot be parsed into a byte * @since 2.5 */ public MutableByte(final String value) { super(); this.value = Byte.parseByte(value); }
public static byte unboxed(Byte v) { return v == null ? 0 : v.byteValue(); }
/** * <p>Converts an array of primitive bytes to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array a <code>byte</code> array * @return a <code>Byte</code> array, <code>null</code> if null array input */ public static Byte[] toObject(byte[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_BYTE_OBJECT_ARRAY; } final Byte[] result = new Byte[array.length]; for (int i = 0; i < array.length; i++) { result[i] = new Byte(array[i]); } return result; }