001package com.identityworksllc.iiq.common.iterators;
002
003import sailpoint.tools.CloseableIterator;
004
005import java.util.NoSuchElementException;
006
007/**
008 * An implementation of CloseableIterator that always contains no items.
009 *
010 * The hasNext() method will always return false and the next() method will always throw a {@link NoSuchElementException}.
011 *
012 * @param <T> The type being wrapped
013 */
014public class NullCloseableIterator<T> implements CloseableIterator<T> {
015
016    /**
017     * A blank NullCloseableIterator object
018     */
019    private static final NullCloseableIterator<?> INSTANCE = new NullCloseableIterator<>();
020
021    /**
022     * Returns a static singleton instance of NullCloseableIterator. Since
023     * this class actually does nothing, this object is thread safe.
024     *
025     * @param <S> The type expected (which is irrelevant here)
026     * @return The singleton iterator
027     */
028    @SuppressWarnings("unchecked")
029    public static <S> NullCloseableIterator<S> getInstance() {
030        return (NullCloseableIterator<S>) INSTANCE;
031    }
032
033    @Override
034    public void close() {
035
036    }
037
038    @Override
039    public boolean hasNext() {
040        return false;
041    }
042
043    @Override
044    public T next() {
045        throw new NoSuchElementException();
046    }
047}