'do the work of getting the next element, making sure that it\'s
a tree node or subtree.  Deal with the optimization of single-
element list versus list of size > 1.  Throw an exception
if the stream is empty or we\'re out of elements and size>1.
protected so you can override in a subclass if necessary.'

def _next(self):

    if (len(self) == 0):
        raise RewriteEmptyStreamException(self.elementDescription)
    if (self.cursor >= len(self)):
        if (len(self) == 1):
            return self.toTree(self.singleElement)
        raise RewriteCardinalityException(self.elementDescription)
    if (self.singleElement is not None):
        self.cursor += 1
        return self.toTree(self.singleElement)
    o = self.toTree(self.elements[self.cursor])
    self.cursor += 1
    return o
