Skip to content

Instantly share code, notes, and snippets.

@jcteague
Last active August 29, 2015 13:58
Show Gist options
  • Save jcteague/10138297 to your computer and use it in GitHub Desktop.
Save jcteague/10138297 to your computer and use it in GitHub Desktop.
using anonymous object as a closure
public class UCDObjectToInformationRequirementConverter {
public MyObject ConvertFrom(KeyValueObject kvObject){
final MyObject result = new MyObject();
Set<KeyValueNode<?,?>> nodes = kvObject.getNodes();
for(UCDNode node : nodes){
getFieldValue(node,"_id", new FieldValueSetter() {@Override public void setField(String value) {result.setId(value);}});
}
return result;
}
private void getFieldValue(KeyValueNode<?,?>node,String fieldName, FieldValueSetter setter) {
String fieldNameInKV = util.getFieldName(node);
if(fieldNameInKV == fieldName){
String value = new String(util.getNodeSubjectValue(node));
setter.setField(value);
}
}
private interface FieldValueSetter{
public abstract void setField(String value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment