Skip to content

Instantly share code, notes, and snippets.

@thenixan
Created December 16, 2013 20:12
Show Gist options
  • Save thenixan/7993571 to your computer and use it in GitHub Desktop.
Save thenixan/7993571 to your computer and use it in GitHub Desktop.
public class Attribute {
private final String mAttributeName;
private final Method mSetter;
public Attribute(String attributeName, Method setter) {
mAttributeName = attributeName;
mSetter = setter;
}
public void setValue(Object target, Object value)
throws InvocationTargetException, IllegalAccessException {
mSetter.invoke(target, value);
}
public String getName() {
return mAttributeName;
}
public static class CompoundAttribute extends Attribute {
private final SubParser mSubParser;
public CompoundAttribute(String attributeName, Method setter, SubParser subParser) {
super(attributeName, setter);
mSubParser = subParser;
}
@Override
public void setValue(Object target, Object value)
throws InvocationTargetException, IllegalAccessException {
super.setValue(target, mSubParser.parse(value));
}
}
public interface SubParser {
public Object parse(Object jsonObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment