PrimitiveHashSet and toJSON ability
(cherry picked from commit d3f3346)
hasNext cleanup (according to changes in core, thanks!)