Last active
August 29, 2015 13:58
-
-
Save jcteague/10138297 to your computer and use it in GitHub Desktop.
using anonymous object as a closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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