public static Short boxed(short v) { return Short.valueOf(v); }
public static Short boxed(short v) { return Short.valueOf(v); }
@Override public Short getRight() { return Short.valueOf(rhs); } });
@Override public Short convert(ResponseBody value) throws IOException { return Short.valueOf(value.string()); } }
@Override public Object decode(Object jv) { if (jv instanceof Number) { return Short.valueOf(((Number) jv).shortValue()); } return (Short) null; } };
@Override public Object decode(Object jv) { if (jv instanceof Number) { return Short.valueOf(((Number) jv).shortValue()); } return (Short) null; } };
/** * Append a short 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, short value) { return append(fieldName, Short.valueOf(value)); }
/** * Gets this mutable as an instance of Short. * * @return a Short instance containing the value from this mutable, never null */ public Short toShort() { return Short.valueOf(shortValue()); }
@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 testStringToShort() { assertEquals(Short.valueOf("1"), conversionService.convert("1", Short.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)); }
@Test public void testShort() { final TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass(); class2.shortField = 42; final DiffResult list = class1.diff(class2); assertEquals(1, list.getNumberOfDiffs()); final Diff<?> diff = list.getDiffs().get(0); assertEquals(Short.valueOf(class1.shortField), diff.getLeft()); assertEquals(Short.valueOf(class2.shortField), diff.getRight()); }
public void testCompare() { for (short x : VALUES) { for (short y : VALUES) { // Only compare the sign of the result of compareTo(). int expected = Short.valueOf(x).compareTo(y); int actual = Shorts.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 testSubtractValueObject() { final MutableShort mutNum = new MutableShort((short) 1); mutNum.subtract(Short.valueOf((short) 1)); assertEquals((short) 0, mutNum.shortValue()); }
@Test public void testAddValueObject() { final MutableShort mutNum = new MutableShort((short) 1); mutNum.add(Short.valueOf((short) 1)); assertEquals((short) 2, mutNum.shortValue()); }
@Test public void testGetAndAddValueObject() { final MutableShort mutableShort = new MutableShort((short)0); final short result = mutableShort.getAndAdd(Short.valueOf((short) 1)); assertEquals((short) 0, result); assertEquals((short) 1, mutableShort.shortValue()); }
@Test public void testConstructors() { assertEquals((short) 0, new MutableShort().shortValue()); assertEquals((short) 1, new MutableShort((short) 1).shortValue()); assertEquals((short) 2, new MutableShort(Short.valueOf((short) 2)).shortValue()); assertEquals((short) 3, new MutableShort(new MutableShort((short) 3)).shortValue()); assertEquals((short) 2, new MutableShort("2").shortValue()); try { new MutableShort((Number)null); fail(); } catch (final NullPointerException ex) {} }