lojix/wam_prolog/src/main/com/thesett/aima/logic/fol/wam/optimizer/Matcher.java
public T nextInSequence()
    {
        T result = null;

        // Poll results from the buffer until no more are available, but only once the state machine has flushed
        // the buffer.
        if (flushMode)
        {
            result = buffer.poll();

            if (result != null)
            {
                return result;
            }

            flushMode = false;
        }

        // Feed input from the source into the state machine, until some results become available on the buffer.
        while (source.hasNext())
        {
            S next = source.next();
            fsm.apply(next);

            if (flushMode)
            {
                result = buffer.poll();

                if (result != null)
                {
                    return result;
                }

                flushMode = false;
            }
        }

        // Once the end of the input source is reached, inform the state machine of this, and try and poll any
        // buffered results.
        fsm.end();

        if (flushMode)
        {
            result = buffer.poll();
        }

        return result;
    }
public T nextInSequence()
    {
        T result = null;

        // Poll results from the buffer until no more are available, but only once the state machine has flushed
        // the buffer.
        if (flushMode)
        {
            result = buffer.poll();

            if (result != null)
            {
                return result;
            }

            flushMode = false;
        }

        // Feed input from the source into the state machine, until some results become available on the buffer.
        while (source.hasNext())
        {
            S next = source.next();
            fsm.apply(next);

            if (flushMode)
            {
                result = buffer.poll();

                if (result != null)
                {
                    return result;
                }

                flushMode = false;
            }
        }

        // Once the end of the input source is reached, inform the state machine of this, and try and poll any
        // buffered results.
        fsm.end();

        if (flushMode)
        {
            result = buffer.poll();
        }

        return result;
    }
{@inheritDoc}