1 |
/* gnu.java.util.EmptyEnumeration |
/* EmptyEnumeration.java -- a constant empty enumeration |
2 |
Copyright (C) 2001 Free Software Foundation, Inc. |
Copyright (C) 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
8 |
the Free Software Foundation; either version 2, or (at your option) |
the Free Software Foundation; either version 2, or (at your option) |
9 |
any later version. |
any later version. |
10 |
|
|
11 |
GNU Classpath is distributed in the hope that it will be useful, but |
GNU Classpath is distributed in the hope that it will be useful, but |
12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
37 |
|
|
38 |
package gnu.java.util; |
package gnu.java.util; |
39 |
|
|
40 |
|
import java.io.Serializable; |
41 |
import java.util.Enumeration; |
import java.util.Enumeration; |
42 |
import java.util.NoSuchElementException; |
import java.util.NoSuchElementException; |
43 |
|
|
44 |
/** |
/** |
45 |
* This is a helper class that produces an empty Enumerations. |
* This is a helper class that produces an empty Enumerations. There is only |
46 |
* There is only one instance of this class that can be used whenever one |
* one instance of this class that can be used whenever one needs a |
47 |
* needs a non-null but empty enumeration. Using this class prevents multiple |
* non-null but empty enumeration. Using this class prevents multiple |
48 |
* small objects and inner classes. <code>getInstance()</code> returns |
* small objects and inner classes. <code>getInstance()</code> returns |
49 |
* the only instance of this class. It can be shared by multiple objects and |
* the only instance of this class. It can be shared by multiple objects and |
50 |
* threads |
* threads. |
51 |
* <p> |
* |
|
* <code>hasMoreElements()</code> always returns <code>false</code>. |
|
|
* <code>nextElement()</code> always throws <code>NoSuchElementException</code>. |
|
|
* |
|
52 |
* @author Mark Wielaard (mark@klomp.org) |
* @author Mark Wielaard (mark@klomp.org) |
53 |
*/ |
*/ |
54 |
public final class EmptyEnumeration implements Enumeration { |
public final class EmptyEnumeration implements Enumeration, Serializable |
55 |
|
{ |
56 |
/** The only instance of this class */ |
/** The only instance of this class */ |
57 |
private static final EmptyEnumeration instance = new EmptyEnumeration(); |
private static final EmptyEnumeration instance = new EmptyEnumeration(); |
58 |
|
|
59 |
/** |
/** |
60 |
* Private constructor that creates a new empty Enumeration. |
* Private constructor that creates a new empty Enumeration. |
61 |
*/ |
*/ |
62 |
private EmptyEnumeration() { |
private EmptyEnumeration() |
63 |
} |
{ |
64 |
|
} |
65 |
/** |
|
66 |
* Returns the only instance of this class. |
/** |
67 |
* It can be shared by multiple objects and threads. |
* Returns the only instance of this class. |
68 |
*/ |
* It can be shared by multiple objects and threads. |
69 |
public static EmptyEnumeration getInstance() { |
* |
70 |
return instance; |
* @return the common empty enumeration |
71 |
} |
*/ |
72 |
|
public static EmptyEnumeration getInstance() |
73 |
/** |
{ |
74 |
* Always returns <code>false</code>. |
return instance; |
75 |
*/ |
} |
76 |
public boolean hasMoreElements() { |
|
77 |
return false; |
/** |
78 |
} |
* Returns false, since there are no elements. |
79 |
|
* |
80 |
/** |
* @return false |
81 |
* Always throws <code>NoSuchElementException</code>. |
*/ |
82 |
*/ |
public boolean hasMoreElements() |
83 |
public Object nextElement() throws NoSuchElementException { |
{ |
84 |
throw new NoSuchElementException(); |
return false; |
85 |
} |
} |
86 |
|
|
87 |
|
/** |
88 |
|
* Always throws <code>NoSuchElementException</code>, since it is empty. |
89 |
|
* |
90 |
|
* @throws NoSuchElementException this is empty |
91 |
|
*/ |
92 |
|
public Object nextElement() |
93 |
|
{ |
94 |
|
throw new NoSuchElementException(); |
95 |
|
} |
96 |
} |
} |