nit: These aren't really the semantics of an iterator -- hasNext should be idempotent and next should be allowed to be called without a prior hasNext. A minor refactoring may be useful for future maintainers of this code.