blob: f06e2e03d834b94d60bbf482bf9fb29c922c7a0c [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.iterators;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.eclipse.jpt.common.utility.internal.StringTools;
/**
* An <code>EmptyIterator</code> is just that.
*
* @param <E> the type of elements (not) returned by the iterator
*
* @see org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable
*/
public final class EmptyIterator<E>
implements Iterator<E>
{
// singleton
@SuppressWarnings("rawtypes")
private static final EmptyIterator INSTANCE = new EmptyIterator();
/**
* Return the singleton.
*/
@SuppressWarnings("unchecked")
public static <T> Iterator<T> instance() {
return INSTANCE;
}
/**
* Ensure single instance.
*/
private EmptyIterator() {
super();
}
public boolean hasNext() {
return false;
}
public E next() {
throw new NoSuchElementException();
}
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public String toString() {
return StringTools.buildToStringFor(this);
}
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
return INSTANCE;
}
}