/** * Sets the value of the field indicated by the {@link Value} annotation on the given object. * * @param target object on which to set value * @param value Value field value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Value} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setValue(@Nonnull final Object target, @Nonnull @NotEmpty final String value) { final Value valueField = getAnnotation(target, Value.class); setFieldValue(target, valueField.value(), value); }
/** * Sets the value of the field indicated by the {@link Key} annotation on the given object. * * @param target Object on which to set key * @param key Key value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Key} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setKey(@Nonnull final Object target, @Nonnull @NotEmpty final String key) { final Key keyField = getAnnotation(target, Key.class); setFieldValue(target, keyField.value(), key); }
/** * Sets the value of the field indicated by the {@link Context} annotation on the given object. * * @param target Object on which to set context * @param context Context value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Context} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setContext(@Nonnull final Object target, @Nonnull @NotEmpty final String context) { final Context ctxField = getAnnotation(target, Context.class); setFieldValue(target, ctxField.value(), context); }
/** * Gets the value of the field indicated by the {@link Context} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target object from which to get context * * @return Context field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Context} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getContext(@Nonnull final Object target) { final Context ctxField = getAnnotation(target, Context.class); final Object value = getFieldValue(target, ctxField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
/** * Gets the value of the field indicated by the {@link Value} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target Object from which to get value * * @return Value field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Value} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getValue(@Nonnull final Object target) { final Value valueField = getAnnotation(target, Value.class); final Object value = getFieldValue(target, valueField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
/** * Gets the value of the field indicated by the {@link Key} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target object from which to get key * * @return Key field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Key} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getKey(@Nonnull final Object target) { final Key keyField = getAnnotation(target, Key.class); final Object value = getFieldValue(target, keyField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
final Expiration expField = getAnnotation(target, Expiration.class); final Object value = getFieldValue(target, expField.value()); if (value == null) {
final Expiration expField = getAnnotation(target, Expiration.class); if (expiration == null) { setFieldValue(target, expField.value(), null);