Iterator getParameter(Map params, String key)
{ Object o = params.get(key);
if(o == null) returnnewNullIterator();
returnnewArrayIterator((String[])o);
}
We made both choices look like iterators.
A NullIterator. Never advances, so the body of the loop never executes. Lovely - one check for null eliminated. This is an example of a Null Object - see Fowler's Refactoring, IntroduceNullObject.
As with the ReverseIterator, none of these are particularly difficult to implement.