01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2005-2007 Robert Grimm
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public License
07: * version 2.1 as published by the Free Software Foundation.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.util;
20:
21: import java.util.Iterator;
22: import java.util.NoSuchElementException;
23:
24: /**
25: * An iterator over nothing.
26: *
27: * @author Robert Grimm
28: * @version $Revision: 1.10 $
29: */
30: public class EmptyIterator<T> implements Iterator<T> {
31:
32: /** The canonical empty iterator. */
33: private static final EmptyIterator VALUE = new EmptyIterator();
34:
35: /** Create a new empty iterator. */
36: private EmptyIterator() { /* Nothing to do. */
37: }
38:
39: public boolean hasNext() {
40: return false;
41: }
42:
43: public T next() {
44: throw new NoSuchElementException();
45: }
46:
47: public void remove() {
48: throw new UnsupportedOperationException();
49: }
50:
51: /**
52: * Get the canoncial empty iterator.
53: *
54: * @return The canonical empty iterator.
55: */
56: @SuppressWarnings({"unchecked","cast"})
57: public static final <T> EmptyIterator<T> value() {
58: return (EmptyIterator<T>) VALUE;
59: }
60:
61: }
|