diff options
| author | Mark Wielaard <mark@klomp.org> | 2001-01-09 23:06:19 +0000 |
|---|---|---|
| committer | Mark Wielaard <mark@klomp.org> | 2001-01-09 23:06:19 +0000 |
| commit | 90fe83d282f3f12dce84e4928c8eecb34da34db3 (patch) | |
| tree | 448a7c15d4501c0ada8254fd2d879db4f334ddfa /gnu/java/util/EmptyEnumeration.java | |
| parent | 50fdebe59b7629fdb3cfbf9fe3db987f194cb250 (diff) | |
| download | classpath-90fe83d282f3f12dce84e4928c8eecb34da34db3.tar.gz | |
* gnu/java/util/DoubleEnumeration.java: new class, adapted from
java/util/DoubleEnumeration. Clears references earlier, handles null
and/or empty enumerations better.
* gnu/java/util/EmptyEnumeration.java: new class.
Diffstat (limited to 'gnu/java/util/EmptyEnumeration.java')
| -rw-r--r-- | gnu/java/util/EmptyEnumeration.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/gnu/java/util/EmptyEnumeration.java b/gnu/java/util/EmptyEnumeration.java new file mode 100644 index 000000000..5ee11d7d4 --- /dev/null +++ b/gnu/java/util/EmptyEnumeration.java @@ -0,0 +1,77 @@ +/* gnu.java.util.EmptyEnumeration + Copyright (C) 2001 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +As a special exception, if you link this library with other files to +produce an executable, this library does not by itself cause the +resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why the +executable file might be covered by the GNU General Public License. */ + +package gnu.java.util; + +import java.util.Enumeration; +import java.util.NoSuchElementException; + +/** + * This is a helper class that produces an empty Enumerations. + * There is only one instance of this class that can be used whenever one + * needs a non-null but empty enumeration. Using this class prevents multiple + * small objects and inner classes. <code>getInstance()</code> returns + * the only instance of this class. It can be shared by multiple objects and + * threads + * <p> + * <code>hasMoreElements()</code> always returns <code>false</code>. + * <code>nextElement()</code> always throws <code>NoSuchElementException</code>. + * + * @author Mark Wielaard (mark@klomp.org) + */ +public final class EmptyEnumeration implements Enumeration { + + /** The only instance of this class */ + private static final EmptyEnumeration instance = new EmptyEnumeration(); + + /** + * Private constructor that creates a new empty Enumeration. + */ + private EmptyEnumeration() { + } + + /** + * Returns the only instance of this class. + * It can be shared by multiple objects and threads. + */ + public static EmptyEnumeration getInstance() { + return instance; + } + + /** + * Always returns <code>false</code>. + */ + public boolean hasMoreElements() { + return false; + } + + /** + * Always throws <code>NoSuchElementException</code>. + */ + public Object nextElement() throws NoSuchElementException { + throw new NoSuchElementException(); + } +} |
