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 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 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(); } }
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 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(); } }
/** * 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 void onPropertyValueChanged(T data, Property prop, Object oldValue, Object newValue) { //currently only support int and long. boolean. if (prop.getType() != int.class && prop.getType() != long.class && prop.getType() != boolean.class) { return; } List<GroupProperty> list = mPropMap.get(TYPE_MUTEX); //process mutex if (!Predicates.isEmpty(list)) { if (newValue instanceof Boolean) { boolean value = Boolean.valueOf(newValue.toString()); for (GroupProperty gp : list) { if (gp.prop == prop && mutex(gp, data, value ? 1 : 0)) { break; } } } else { long value = Long.valueOf(newValue.toString()); for (GroupProperty gp : list) { if (gp.prop == prop && mutex(gp, data, value)) { break; } } } } }
private void onPropertyValueChanged(T data, Property prop, Object oldValue, Object newValue) { //currently only support int and long. boolean. if (prop.getType() != int.class && prop.getType() != long.class && prop.getType() != boolean.class) { return; } List<GroupProperty> list = mPropMap.get(TYPE_MUTEX); //process mutex if (!Predicates.isEmpty(list)) { if (newValue instanceof Boolean) { boolean value = Boolean.valueOf(newValue.toString()); for (GroupProperty gp : list) { if (gp.prop == prop && mutex(gp, data, value ? 1 : 0)) { break; } } } else { long value = Long.valueOf(newValue.toString()); for (GroupProperty gp : list) { if (gp.prop == prop && mutex(gp, data, value)) { break; } } } } }
getPrefix = realProp.getType() == boolean.class ? "is" : "get"; Object propVal = getPropertyValue(expression, parent, getPrefix, false); if(propVal == null){
getPrefix = realProp.getType() == boolean.class ? "is" : "get"; Object propVal = getPropertyValue(expression, parent, getPrefix, false); if(propVal == null){
public static Object readPrimitiveOrItsBox(JsonReader reader, Property p) throws IOException { Class<?> type = p.getType(); if (type == void.class || type == Void.class) { return null; } else if (type == boolean.class || type == Boolean.class) { return reader.nextBoolean(); } else if (type == byte.class || type == Byte.class) { return (byte)reader.nextInt(); } else if (type == short.class || type == Short.class) { return (short)reader.nextInt(); } else if (type == int.class || type == Integer.class) { return reader.nextInt(); } else if (type == long.class || type == Long.class) { return reader.nextLong(); } else if (type == char.class || type == Character.class) { return (char)reader.nextLong(); } else if (type == float.class || type == Float.class) { return (float)reader.nextDouble(); } else if (type == double.class || type == Double.class) { return reader.nextDouble(); } else { throw new IllegalStateException(); } }