@Test public void convertsReturnedIDToNSObjectSubclass() { FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class); NSNumber number = Rococoa.create("NSNumber", NSNumber.class, "numberWithInt:", 45); Number nativeValue = new Long(number.id().longValue()); NSNumber converted = (NSNumber) converter.fromNative(nativeValue, null); assertEquals(converted.id(), number.id()); assertEquals(45, converted.intValue()); if (NativeLong.SIZE == 4) { nativeValue = new Integer(number.id().intValue()); converted = (NSNumber) converter.fromNative(nativeValue, null); assertEquals(45, converted.intValue()); } }
public T fromNative(Object nativeValue, FromNativeContext context) { Number nativeValueAsNumber = (Number) nativeValue; if (nativeValueAsNumber == null) { return null; } ID id = ID.fromLong(nativeValueAsNumber.longValue()); if (id.isNull()) { return null; } boolean shouldRetain = shouldRetainFor(context); return Rococoa.wrap(id, javaType, shouldRetain); }
ObjCObjectTypeConverter implements TypeConverter { public T fromNative(Object nativeValue, FromNativeContext context) { Number nativeValueAsNumber = (Number) nativeValue; if (nativeValueAsNumber == null) { return null; } ID id = ID.fromLong(nativeValueAsNumber.longValue()); if (id.isNull()) { return null; } boolean shouldRetain = shouldRetainFor(context); return Rococoa.wrap(id, javaType, shouldRetain); } }
ObjCObjectTypeConverter implements TypeConverter { public T fromNative(Object nativeValue, FromNativeContext context) { Number nativeValueAsNumber = (Number) nativeValue; if (nativeValueAsNumber == null) { return null; } ID id = ID.fromLong(nativeValueAsNumber.longValue()); if (id.isNull()) { return null; } boolean shouldRetain = shouldRetainFor(context); return Rococoa.wrap(id, javaType, shouldRetain); } ObjCObjectTypeConverter(Class<T> javaType); }
ObjCObjectTypeConverter implements TypeConverter { public T fromNative(Object nativeValue, FromNativeContext context) { Number nativeValueAsNumber = (Number) nativeValue; if (nativeValueAsNumber == null) { return null; } ID id = ID.fromLong(nativeValueAsNumber.longValue()); if (id.isNull()) { return null; } boolean shouldRetain = shouldRetainFor(context); return Rococoa.wrap(id, javaType, shouldRetain); } ObjCObjectTypeConverter(Class<T> javaType); Class<?> nativeType(); T fromNative(Object nativeValue, FromNativeContext context); Object toNative(Object value, ToNativeContext context); }
ObjCObjectTypeConverter implements TypeConverter { public T fromNative(Object nativeValue, FromNativeContext context) { Number nativeValueAsNumber = (Number) nativeValue; if (nativeValueAsNumber == null) { return null; } ID id = ID.fromLong(nativeValueAsNumber.longValue()); if (id.isNull()) { return null; } boolean shouldRetain = shouldRetainFor(context); return Rococoa.wrap(id, javaType, shouldRetain); } ObjCObjectTypeConverter(Class<T> javaType); Class<?> nativeType(); T fromNative(Object nativeValue, FromNativeContext context); Object toNative(Object value, ToNativeContext context);  }