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