Sean is exactly right.

Another way to put it is that hasNext is free to have side-effects, but it
must be idempotent.  That is, repeated calls to hasNext() must not change
the next value returned by next().  This is not the same as having no
effect, it just means that it must have no *user*visible* effect if the user
can't see the precise timing of accesses to the underlying sequence.

On Sat, May 21, 2011 at 3:55 PM, Sean Owen <[email protected]> wrote:

> This just uses the Google Guava helper class to implement the Iterator and
> it does work. next() advances the iterator logically, and hasNext() can't
> advance the iteration. However, when and how the iterator accesses the
> underlying sequence is up to the iterator. It can, and must, access the
> next
> element to find out if there is a next element in a call to hasNext().
> However this doesn't violate any contract.
>
> On Sat, May 21, 2011 at 11:33 PM, Lance Norskog <[email protected]> wrote:
>
> > You're right, it can drop the first element.
> >
> > SamplingIterator.next() pulls a successor element from the delegate
> > iterator and stashes it. This works, but I think the full semantics
> > would require that the delegate iterator does not advance until
> > Sampling.next causes it to. Not sure.
> >
> > On Sat, May 21, 2011 at 3:06 PM, Sean Owen (JIRA) <[email protected]>
> wrote:
> > >
> > >    [
> >
> https://issues.apache.org/jira/browse/MAHOUT-687?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13037469#comment-13037469
> ]
> > >
> > > Sean Owen commented on MAHOUT-687:
> > > ----------------------------------
> > >
> > > I don't know what you mean -- it most definitely can drop the first
> > element.
> > > What hasNext() method are you referring to?
> > > Yes, it's easy to make a similar change elsewhere to remove static
> Random
> > instances.
> > >
> > >> Random generator objects- slight refactor
> > >> -----------------------------------------
> > >>
> > >>                 Key: MAHOUT-687
> > >>                 URL: https://issues.apache.org/jira/browse/MAHOUT-687
> > >>             Project: Mahout
> > >>          Issue Type: Improvement
> > >>            Reporter: Lance Norskog
> > >>            Priority: Minor
> > >>         Attachments: MAHOUT-687.patch, MAHOUT-687.patch
> > >>
> > >>
> > >> Problems:
> > >> * The uncommons RepeatableRNG classes are the basis of RandomUtils.
> > >> ** These classes cheerfully ignore setSeed.
> > >> * Some people in the project want to move off Uncommons anyway.
> > >> This patch uses the org.apache.commons.math.random.RandomGenerator
> > classes instead of org.apache.uncommons.maths.RepeatableRNG classes.
> > >> .
> > >
> > > --
> > > This message is automatically generated by JIRA.
> > > For more information on JIRA, see:
> > http://www.atlassian.com/software/jira
> > >
> >
> >
> >
> > --
> > Lance Norskog
> > [email protected]
> >
>

Reply via email to