All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.stax2.ri.SingletonIterator Maven / Gradle / Ivy

Go to download

Stax2 API is an extension to basic Stax 1.0 API that adds significant new functionality, such as full-featured bi-direction validation interface and high-performance Typed Access API.

There is a newer version: 4.2.2
Show newest version
package org.codehaus.stax2.ri;

import java.util.Iterator;

/**
 * Simple read-only iterator that iterators over one specific item, passed
 * in as constructor argument.
 */
public class SingletonIterator implements Iterator
{
    private final T _value;
    
    private boolean _done = false;

    @Deprecated // since 4.0; use SingletonIterator.create() instead
    public SingletonIterator(T value) {
        _value = value;
    }

    public static  SingletonIterator create(T value) {
        return new SingletonIterator(value);
    }
    
    @Override
    public boolean hasNext() {
        return !_done;
    }
    
    @Override
    public T next() {
        if (_done) {
            throw new java.util.NoSuchElementException();
        }
        _done = true;
        return _value;
    }
    
    @Override
    public void remove()
    {
        throw new UnsupportedOperationException("Can not remove item from SingletonIterator.");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy