Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/EmptyIterator.java')
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/EmptyIterator.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/EmptyIterator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/EmptyIterator.java
new file mode 100644
index 0000000000..f06e2e03d8
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/EmptyIterator.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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;
+ }
+
+}

Back to the top