I don't know what your Node<T> code looks like, but it looks weird:
public Boolean MoveNext() { if (node.getNext() != null) { node = node.getNext(); return true; } return false; }
Ideally, it seems that MoveNext would look like this:
public Boolean MoveNext() { // make sure current node is not null if (node != null) { node = node.getNext(); } // simply return whether current node is null or not return node != null; }
In your original method, you get the next node twice, which may give you false results. I assume that getNext just returns a link to the current node next brother. Otherwise, I don't see any initial problems with your enumerator (or iterator) class.
For clarity, I would use currentNode instead of node and change start to startNode . Also, if node.getNext() does not return a node object, then the method should be renamed to indicate what it is doing.
I made the assumption that node.getNext() moved the internal link, but @Servy fixed me. Thank you
I can still recommend some name changes to clarify the operation. :)
source share