Package io.microsphere.collection
Class SingletonEnumeration<E>
- java.lang.Object
-
- io.microsphere.collection.SingletonEnumeration<E>
-
- Type Parameters:
E- The type of the element in this enumeration.
- All Implemented Interfaces:
java.util.Enumeration<E>
@Immutable public class SingletonEnumeration<E> extends java.lang.Object implements java.util.Enumeration<E>
A simple implementation of theEnumerationinterface that contains a single element.This enumeration can only return the singleton element once, after which it will return false for subsequent calls to
hasMoreElements()and throw aNoSuchElementExceptionon subsequent calls tonextElement().Example Usage
String item = "Hello"; SingletonEnumeration<String> enumeration = new SingletonEnumeration<>(item); while (enumeration.hasMoreElements()) { System.out.println(enumeration.nextElement()); }The output of the example would be:
Hello
- Since:
- 1.0.0
- Author:
- Mercy
-
-
Constructor Summary
Constructors Constructor Description SingletonEnumeration(E element)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasMoreElements()EnextElement()
-
-
-
Constructor Detail
-
SingletonEnumeration
public SingletonEnumeration(E element)
-
-