/** * Set the value of a field using reflection. This method will traverse the * super class hierarchy until a field with name <tt>fieldName</tt> is * found. * * @param object the object whose field to modify * @param fieldName the name of the field * @param value the new value of the field */ public static void setInternalState(Object object, String fieldName, Object value) { Field foundField = findFieldInHierarchy(object, fieldName); setField(object, value, foundField); }
/** * Set the value of a field using reflection at a specific location ( * <tt>where</tt>) in the class hierarchy. The <tt>value</tt> will then be * assigned to this field. * * @param object the object to modify * @param fieldType the type of the field the should be set. * @param value the new value of the field * @param where which class in the hierarchy defining the field */ public static void setInternalState(Object object, Class<?> fieldType, Object value, Class<?> where) { if (fieldType == null || where == null) { throw new IllegalArgumentException("fieldType and where cannot be null"); } setField(object, value, findFieldOrThrowException(fieldType, where)); }
/** * Set the value of a field using reflection. This method will traverse the * super class hierarchy until a field with name <tt>fieldName</tt> is * found. * * @param object * the object whose field to modify * @param fieldName * the name of the field * @param value * the new value of the field */ public static void setInternalState(Object object, String fieldName, Object value) { Field foundField = findFieldInHierarchy(object, fieldName); setField(object, value, foundField); }
/** * Set the value of a field using reflection at a specific location ( * <tt>where</tt>) in the class hierarchy. The <tt>value</tt> will then be * assigned to this field. * * @param object * the object to modify * @param fieldType * the type of the field the should be set. * @param value * the new value of the field * @param where * which class in the hierarchy defining the field */ public static void setInternalState(Object object, Class<?> fieldType, Object value, Class<?> where) { if (fieldType == null || where == null) { throw new IllegalArgumentException("fieldType and where cannot be null"); } setField(object, value, findFieldOrThrowException(fieldType, where)); }
/** * Set the value of a field using reflection. This method will traverse the * super class hierarchy until the first field of type <tt>fieldType</tt> is * found. The <tt>value</tt> will then be assigned to this field. * * @param object the object to modify * @param fieldType the type of the field * @param value the new value of the field */ public static void setInternalState(Object object, Class<?> fieldType, Object value) { setField(object, value, findFieldInHierarchy(object, new AssignableFromFieldTypeMatcherStrategy(fieldType))); }
/** * Set the value of a field using reflection. This method will traverse the * super class hierarchy until the first field of type <tt>fieldType</tt> is * found. The <tt>value</tt> will then be assigned to this field. * * @param object * the object to modify * @param fieldType * the type of the field * @param value * the new value of the field */ public static void setInternalState(Object object, Class<?> fieldType, Object value) { setField(object, value, findFieldInHierarchy(object, new AssignableFromFieldTypeMatcherStrategy(fieldType))); }
/** * Set the value of a field using reflection at at specific place in the * class hierarchy (<tt>where</tt>). This first field assignable to * <tt>object</tt> will then be set to <tt>value</tt>. * * @param object the object to modify * @param value the new value of the field * @param where the class in the hierarchy where the field is defined */ public static void setInternalState(Object object, Object value, Class<?> where) { setField(object, value, findField(object, new AssignableFromFieldTypeMatcherStrategy(getType(value)), where)); }
/** * Set the value of a field using reflection at at specific place in the * class hierarchy (<tt>where</tt>). This first field assignable to * <tt>object</tt> will then be set to <tt>value</tt>. * * @param object * the object to modify * @param value * the new value of the field * @param where * the class in the hierarchy where the field is defined */ public static void setInternalState(Object object, Object value, Class<?> where) { setField(object, value, findField(object, new AssignableFromFieldTypeMatcherStrategy(getType(value)), where)); }
/** * Set the value of a field using reflection. This method will traverse the * super class hierarchy until the first field assignable to the * <tt>value</tt> type is found. The <tt>value</tt> (or * <tt>additionaValues</tt> if present) will then be assigned to this field. * * @param object * the object to modify * @param value * the new value of the field * @param additionalValues * Additional values to set on the object */ public static void setInternalState(Object object, Object value, Object... additionalValues) { setField(object, value, findFieldInHierarchy(object, new AssignableFromFieldTypeMatcherStrategy(getType(value)))); if (additionalValues != null && additionalValues.length > 0) { for (Object additionalValue : additionalValues) { setField( object, additionalValue, findFieldInHierarchy(object, new AssignableFromFieldTypeMatcherStrategy( getType(additionalValue)))); } } }
/** * Set the value of a field using reflection. This method will traverse the * super class hierarchy until the first field assignable to the * <tt>value</tt> type is found. The <tt>value</tt> (or * <tt>additionaValues</tt> if present) will then be assigned to this field. * * @param object the object to modify * @param value the new value of the field * @param additionalValues Additional values to set on the object */ public static void setInternalState(Object object, Object value, Object... additionalValues) { setField(object, value, findFieldInHierarchy(object, new AssignableFromFieldTypeMatcherStrategy(getType(value)))); if (additionalValues != null && additionalValues.length > 0) { for (Object additionalValue : additionalValues) { setField( object, additionalValue, findFieldInHierarchy(object, new AssignableFromFieldTypeMatcherStrategy( getType(additionalValue)))); } } }