if (reference == null) {
if (listData != null) {
List<Object> foreachList = (List<Object>)listData.evaluate();
return foreachList.iterator();
} else {
return new MapListAdapter((Map)mapDataRef.evaluate()).iterator();
}
}
Object ref = reference.evaluate();
Iterator<Object> iterator;
if (ref == null) {
iterator = Collections.emptyList().iterator();
} else if (ref instanceof Iterator) {
iterator = (Iterator)ref;
} else if (ref instanceof Iterable) {
iterator = ((Iterable)ref).iterator();
} else if (ref.getClass().isArray()) {
iterator = new ArrayListAdapter(ref).iterator();
} else if (ref instanceof Map) {
iterator = new MapListAdapter((Map)ref).iterator();
} else {
throw new InterpretationException(source, indexInSource, "Can not iterate over a " + ref.getClass().getCanonicalName());
}
return iterator;
}