public static Short boxed(short v) { return Short.valueOf(v); }
@Override public Short apply(String input) { return Short.parseShort(input); } };
public static short unboxed(Short v) { return v == null ? 0 : v.shortValue(); }
/** * Returns a Short instance representing the specified short. * Short.valueOf was added in JDK 1.5. * * @param b a short value. * @return a Byte instance representing b. */ protected static Short valueOf(final short b) { return new Short(b); }
/** * Returns the Short 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 Short. */ public short getShort(String key, short defaultValue) { addToDefaults(key, Short.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } else { return Short.valueOf(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 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); } } } }
@Override protected String doBackward(Short value) { return value.toString(); }
@Test public void canGetWithShortIndex() { Short index = 0; initial.setRegisters(0, new int[] { 0x42 }, "[I", 1, index, "S"); expected.setRegisters(index.intValue(), 0x42, "I", 1, Short.valueOf(index.shortValue()), "S"); VMTester.test(CLASS_NAME, "get()V", initial, expected); }
@Override public void toJson(JsonWriter writer, Short value) throws IOException { writer.value(value.intValue()); }
/** * Gets the value as a Short instance. * * @return the value as a Short, never null */ public Object getValue() { return new Short(this.value); }
@Test public void read() throws IOException { Short shortValue = Short.valueOf((short) 781); MockHttpServletRequest request = new MockHttpServletRequest(); request.setContentType(MediaType.TEXT_PLAIN_VALUE); request.setContent(shortValue.toString().getBytes(StringHttpMessageConverter.DEFAULT_CHARSET)); assertEquals(shortValue, this.converter.read(Short.class, new ServletServerHttpRequest(request))); Float floatValue = Float.valueOf(123); request = new MockHttpServletRequest(); request.setContentType(MediaType.TEXT_PLAIN_VALUE); request.setCharacterEncoding("UTF-16"); request.setContent(floatValue.toString().getBytes("UTF-16")); assertEquals(floatValue, this.converter.read(Float.class, new ServletServerHttpRequest(request))); Long longValue = Long.valueOf(55819182821331L); request = new MockHttpServletRequest(); request.setContentType(MediaType.TEXT_PLAIN_VALUE); request.setCharacterEncoding("UTF-8"); request.setContent(longValue.toString().getBytes("UTF-8")); assertEquals(longValue, this.converter.read(Long.class, new ServletServerHttpRequest(request))); }
/** * 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(short key) { return Short.toString(key); }
@Test public void canCreateIntegerArrayWithShortTypeLengthValue() { Short length = 1; initial.setRegisters(0, length, "S"); expected.setRegisters(0, new int[length.intValue()], "[I"); VMTester.test(CLASS_NAME, "createIntegerArray()V", initial, expected); }
public static Short boxed(short v) { return Short.valueOf(v); }
/** * Constructs a new MutableShort parsing the given string. * * @param value the string to parse, not null * @throws NumberFormatException if the string cannot be parsed into a short * @since 2.5 */ public MutableShort(final String value) { super(); this.value = Short.parseShort(value); }
public static short unboxed(Short v) { return v == null ? 0 : v.shortValue(); }
public static String formatShort(short s) { if (s == Short.MAX_VALUE) { return "Short.MAX_VALUE"; } if (s == Short.MIN_VALUE) { return "Short.MIN_VALUE"; } return "(short) " + Short.toString(s); }
@Test public void testIntToCharWithShort() { Short value = 0x62; initial.setRegisters(0, value, "S"); expected.setRegisters(0, (char) value.intValue(), "C"); VMTester.test(CLASS_NAME, "intToChar()V", initial, expected); }