Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
interface SingleValueExtractor<I, O> {
O extractValue(I input);
// only invoked if invalid; Property name enough as input?
Path.Node getNode(String property);
}
interface MultiValueExtractor<I, O> {
ValueAndNodeIterator<O> extractValues(I input);
public interface ValueAndNodeIterator<O> {
boolean hasNext();
O next();
TypeVariable<?> typeVariable();
// only invoked if invalid; Property name enough as input?
Path.Node getNode(String property);
}
}
class MapExtractor implements MultiValueExtractor<Map, Object> {
public ValueAndNodeIterator<Object> extractValues(Map input) {
Set<Map.Entry<?, ?>> entrySet = input.entrySet();
final Iterator<Map.Entry> iterator = input.entrySet().iterator();
final TypeVariable<Class<Map>> k = Map.class.getTypeParameters()[0];
final TypeVariable<Class<Map>> v = Map.class.getTypeParameters()[1];
return new ValueAndNodeIterator<Object>() {
private boolean atKey = true;
private Map.Entry<?, ?> current;
public boolean hasNext() {
return iterator.hasNext();
}
public Object next() {
if ( atKey ) {
current = iterator.next();
atKey = false;
return current.getKey();
}
else {
atKey = true;
return current.getValue();
}
}
public TypeVariable<?> typeVariable() {
return atKey ? k : v;
}
public Node getNode(String property) {
// TODO Auto-generated method stub
return null;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.