public Integer toInt(Short self) { return self.intValue(); }
@Override public Integer toInteger(Object value) { return ((Short) value).intValue(); }
public void set(String key, Short value) { if (value != null) { attributes.put(key, value.intValue()); } }
public static Integer getInt(Object o) { if (o instanceof Long) { return ((Long) o).intValue(); } else if (o instanceof Integer) { return (Integer) o; } else if (o instanceof Short) { return ((Short) o).intValue(); } else { throw new IllegalArgumentException("Don't know how to convert " + o + " + to int"); } }
private static Integer extractIntegerValue(Field field) { Integer rtn = null; try { Object value = field.get( null ); if ( value instanceof Integer ) { rtn = (Integer) value; } else if ( value instanceof Short ) { rtn = ( (Short) value ).intValue(); } else if ( value instanceof Long ) { if ( (Long) value <= Integer.MAX_VALUE ) { rtn = ( (Long) value ).intValue(); } } } catch (IllegalAccessException ignore) { } return rtn; } }
@Override public void toJson(JsonWriter writer, Short value) throws IOException { writer.value(value.intValue()); }
public static BuilderInstruction buildConstant(Short value, int register) { return buildConstant(value.intValue(), register); }
private Integer coerceToInteger(Object o) { if(o == null) return null; Class<?> c = o.getClass(); if(c == Integer.class) return (Integer) o; else if(c == Byte.class) return ((Byte) o).intValue(); else if(c == Short.class) return ((Short) o).intValue(); else throw new SerializationException("Object of type " + c.getName() + " cannot be coerced to type " + JsonTypes.INT32 + " as the schema specifies."); }
protected void printAnnotationArrayValue(final Object value) { if (value instanceof String[]) { print(((String[]) value)[1]); } else if (value instanceof AnnotationNode) { printAnnotation((AnnotationNode) value, 0, -1); } else if (value instanceof String) { print(value); } else if (value instanceof Byte) { pw.print(((Byte) value).intValue()); } else if (value instanceof Boolean) { pw.print(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Character) { pw.print(new Integer(((Character) value).charValue())); } else if (value instanceof Short) { pw.print(((Short) value).intValue()); } else if (value instanceof Type) { pw.print(((Type) value).getDescriptor()); } else { print(value); } }
/** * Get the result of an Object path expression as an int. * * @param path The Object path. * @return The int matching the Object path. A {@link java.lang.ClassCastException} will be thrown if the object * cannot be casted to the expected type. */ public int getInt(String path) { //The type returned from Groovy depends on the input, so we need to handle different numerical types. Object value = get(path); if (value instanceof Integer) { return (Integer) value; } else if (value instanceof Short) { return ((Short) value).intValue(); } else if (value instanceof Long) { return ((Long) value).intValue(); } else { return ObjectConverter.convertObjectTo(value, Integer.class); } }
/** * Get the result of an Object path expression as an int. * * @param path The Object path. * @return The int matching the Object path. A {@link java.lang.ClassCastException} will be thrown if the object * cannot be casted to the expected type. */ public int getInt(String path) { //The type returned from Groovy depends on the input, so we need to handle different numerical types. Object value = get(path); if (value instanceof Integer) { return (Integer) value; } else if (value instanceof Short) { return ((Short) value).intValue(); } else if (value instanceof Long) { return ((Long) value).intValue(); } else { return ObjectConverter.convertObjectTo(value, Integer.class); } }
public Integer getIntProperty(final SimpleString key) throws ActiveMQPropertyConversionException { Object value = doGetProperty(key); if (value == null) { return Integer.valueOf(null); } else if (value instanceof Integer) { return (Integer) value; } else if (value instanceof Byte) { return ((Byte) value).intValue(); } else if (value instanceof Short) { return ((Short) value).intValue(); } else if (value instanceof SimpleString) { return Integer.parseInt(((SimpleString) value).toString()); } throw new ActiveMQPropertyConversionException("Invalid conversion: " + key); }
public final void writeVal(Short val) throws IOException { if (val == null) { writeNull(); } else { writeVal(val.intValue()); } }
public int readUnsignedShort() throws IOException { return ((Short)peekCallback().readFromStream()).intValue() & 0xffff; }
@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 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); }
@Test public void test() throws Exception { byte[] data = TestUtils.testDexASMifier(getClass(), "strict", "a"); Class<?> clz = TestUtils.defineClass("a", data); Object c = clz.newInstance(); Assert.assertNotNull(c); java.lang.reflect.Field f = clz.getDeclaredField("theField"); f.setAccessible(true); Short r = (Short) f.get(null); Assert.assertEquals(-1, r.intValue()); // it's already ok to run on JVM and able to convert to dex, // // check for I2S instruction // ClassReader cr = new ClassReader(data); // ClassNode cn = new ClassNode(); // cr.accept(cn, 0); // boolean find = false; // for (Object m : cn.methods) { // MethodNode method = (MethodNode) m; // for (AbstractInsnNode p = method.instructions.getFirst(); p != null; p = p.getNext()) { // if (p.getOpcode() == Opcodes.I2S) { // find = true; // break; // } // } // } // Assert.assertTrue("we need an I2S instruction", find); } }
return addConstantInteger(((Character) value).charValue()); } else if (value instanceof Short) { return addConstantInteger(((Short) value).intValue()); } else if (value instanceof Boolean) { return addConstantInteger(((Boolean) value).booleanValue() ? 1 : 0);
@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); }
@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); }