@Override public void onPropertyValueChanged(Student data, Property prop, Object oldValue, Object newValue) { Logger.w("TestPropertyChangeActivity","onPropertyValueChanged","prop = " + prop.getName() + " ,oldValue = " + oldValue + " ,newValue = " + newValue); mTv_desc.setText(String.valueOf(newValue)); } });
/** * put the parameter as {@linkplain Property} to put to the cache, * @param typeName the type name * @param propName the property name * @param complexFlag the complex flag */ public static void putToCache(String typeName, String propName, int complexFlag) { sCache.put(generateKey(typeName, propName, complexFlag), new Property(typeName, propName, complexFlag)); }
public static void setValue(Property p, Object obj, Object val) { String name = p.getName(); String setMethodName = "set" + name.substring(0, 1) .toUpperCase() .concat(name.substring(1)); try { Method setXXX = obj.getClass().getMethod(setMethodName, p.getActualType()); setXXX.invoke(obj, val); } catch (Exception e) { throw new RuntimeException(e); } } }
public static TypeHandler getTypeHandler(Property prop){ if(prop.getComplexType() == 0){ if(prop.getType().isPrimitive() || isBoxedClass(prop.getType())){ return PRIMITVE; } } return getTypeHandlerInternal(prop.getComplexType()); }
/** * wrap the normal property to {@linkplain GsonProperty} * @param prop the normal property * @param serializeName the serialize name * @return the gson property. */ public static GsonProperty of(Property prop, String serializeName){ GsonProperty gp = new GsonProperty(prop.getTypeString(), prop.getName(),prop.getComplexType()); gp.setSerializeName(serializeName); return gp; } /**
public static Object getValue(Property p, Object obj) { String name = p.getName(); final String prefix = p.getType() != boolean.class ? "get" : "is"; String getMethodName = prefix + name.substring(0, 1) .toUpperCase() .concat(name.substring(1)); try { Method getXXX = obj.getClass().getMethod(getMethodName); return getXXX.invoke(obj); } catch (Exception e) { throw new RuntimeException(e); } }
private static void setMutexValue0(GroupProperty gp, Object obj, Object preVal) { if (gp.prop.getType() == int.class) { int newVal = gp.asFlags ? (Integer) preVal & ~(int) gp.value : (int) gp.oppositeValue; ReflectUtils.setValue(gp.prop, obj, newVal); } else if (gp.prop.getType() == long.class) { long newVal = gp.asFlags ? (Long) preVal & ~gp.value : gp.oppositeValue; ReflectUtils.setValue(gp.prop, obj, newVal); } else if (gp.prop.getType() == boolean.class) { //for boolean 0, and 1 ReflectUtils.setValue(gp.prop, obj, gp.oppositeValue == 1); } else { throw new UnsupportedOperationException(); } }
/** * get base the property type. * @return the base type. * @see #getComplexType() */ public Class<?> getType() { //this object may be const, so weak reference , // even if the Class very likely exist loaded all the time. if(mWeakClass == null || mWeakClass.get() == null){ mWeakClass = new WeakReference<Class<?>>(getType0()); } return mWeakClass.get(); }
private Class<?> getType0() { switch (type){ case TYPE_int: return int.class; case TYPE_long: return long.class; case TYPE_short: return short.class; case TYPE_byte: return byte.class; case TYPE_boolean: return boolean.class; case TYPE_float: return float.class; case TYPE_double: return double.class; case TYPE_char: return char.class; } try { return bestGuessClass(type); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
while (p < classNameString.length() && Character.isLowerCase(classNameString.codePointAt(p))) { p = classNameString.indexOf('.', p) + 1; checkArgument(p != 0, "couldn't make a guess for %s", classNameString); checkArgument(!part.isEmpty() && Character.isUpperCase(part.codePointAt(0)), "couldn't make a guess for %s", classNameString); names.add(part); checkArgument(size >= 2, "couldn't make a guess for %s", classNameString);
public static Object getValue(Property p, Object obj) { String name = p.getName(); final String prefix = p.getType() != boolean.class ? "get" : "is"; String getMethodName = prefix + name.substring(0, 1) .toUpperCase() .concat(name.substring(1)); try { Method getXXX = obj.getClass().getMethod(getMethodName); return getXXX.invoke(obj); } catch (Exception e) { throw new RuntimeException(e); } }
/** * create gson property from target parameters. * @param prop the base property * @param serializeName the serialize name of gson * @param since the since of gson * @param util the until of gson * @return the gson property */ public static GsonProperty of(Property prop, String serializeName, double since, double util){ GsonProperty gp = new GsonProperty(prop.getTypeString(), prop.getName(),prop.getComplexType()); gp.setSerializeName(serializeName); gp.setSince(since); gp.setUntil(util); return gp; } /**
/** * get the actual type .no matter is array, list or primitive . * <p>if you use reflect to set property. you should care, here is a demo:</p> * <code><pre> TestBean bean = new TestBean(null); Method setArray = TestBean.class.getMethod("setArray", Array.newInstance(String.class,0).getClass()); setArray.invoke(bean, (Object)new String[]{"123", "456"}); * </pre></code> * @return the actual type. * @since 1.0.7 */ public Class<?> getActualType(){ switch (getComplexType()){ case FieldFlags.COMPLEX_ARRAY: return Array.newInstance(getType(), 0).getClass(); case FieldFlags.COMPLEX_LIST: return List.class; case FieldFlags.COMPLEX_SPARSE_ARRAY: return SparseArray.class; default: return getType(); } }
private static void setMutexValue0(GroupProperty gp, Object obj, Object preVal) { if (gp.prop.getType() == int.class) { int newVal = gp.asFlags ? (Integer) preVal & ~(int) gp.value : (int) gp.oppositeValue; ReflectUtils.setValue(gp.prop, obj, newVal); } else if (gp.prop.getType() == long.class) { long newVal = gp.asFlags ? (Long) preVal & ~gp.value : gp.oppositeValue; ReflectUtils.setValue(gp.prop, obj, newVal); } else if (gp.prop.getType() == boolean.class) { //for boolean 0, and 1 ReflectUtils.setValue(gp.prop, obj, gp.oppositeValue == 1); } else { throw new UnsupportedOperationException(); } }
/** * get base the property type. * @return the base type. * @see #getComplexType() */ public Class<?> getType() { //this object may be const, so weak reference , // even if the Class very likely exist loaded all the time. if(mWeakClass == null || mWeakClass.get() == null){ mWeakClass = new WeakReference<Class<?>>(getType0()); } return mWeakClass.get(); }
private Class<?> getType0() { switch (type){ case TYPE_int: return int.class; case TYPE_long: return long.class; case TYPE_short: return short.class; case TYPE_byte: return byte.class; case TYPE_boolean: return boolean.class; case TYPE_float: return float.class; case TYPE_double: return double.class; case TYPE_char: return char.class; } try { return bestGuessClass(type); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
while (p < classNameString.length() && Character.isLowerCase(classNameString.codePointAt(p))) { p = classNameString.indexOf('.', p) + 1; checkArgument(p != 0, "couldn't make a guess for %s", classNameString); checkArgument(!part.isEmpty() && Character.isUpperCase(part.codePointAt(0)), "couldn't make a guess for %s", classNameString); names.add(part); checkArgument(size >= 2, "couldn't make a guess for %s", classNameString);
/** * bind text size of Text view. * @param property the property * @return this. * @since 1.1.2 */ public BatchTextViewBinder<T> bindTextSize(Property property){ mBinder.bindTextSize(property.getName(), mView); return this; } /**
public static Object getValue(Property p, Object obj) { String name = p.getName(); final String prefix = p.getType() != boolean.class ? "get" : "is"; String getMethodName = prefix + name.substring(0, 1) .toUpperCase() .concat(name.substring(1)); try { Method getXXX = obj.getClass().getMethod(getMethodName); return getXXX.invoke(obj); } catch (Exception e) { throw new RuntimeException(e); } }
public static void setValue(Property p, Object obj, Object val){ String name = p.getName(); String setMethodName = "set" + name.substring(0, 1) .toUpperCase() .concat(name.substring(1)); try { Method setXXX = obj.getClass().getMethod(setMethodName, p.getActualType()); setXXX.invoke(obj, val); } catch (Exception e) { throw new RuntimeException(e); } } public static Object readPrimitiveOrItsBox(JsonReader reader, Property p) throws IOException {