Class EnumerationUtils
java.lang.Object
org.apache.commons.collections4.EnumerationUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Iterable<T> asIterable(Enumeration<T> enumeration) Creates anIterablethat wraps anEnumeration.static <T> Tget(Enumeration<T> e, int index) Gets theindex-th value in theEnumeration, throwingIndexOutOfBoundsExceptionif there is no such element.static <E> List<E> toList(Enumeration<? extends E> enumeration) Creates a list based on an enumeration.toList(StringTokenizer stringTokenizer) Override toList(Enumeration) for StringTokenizer as it implements Enumeration<Object> for the sake of backward compatibility.static <E> Set<E> toSet(Enumeration<? extends E> enumeration) Creates a set based on an enumeration.
-
Method Details
-
asIterable
Creates anIterablethat wraps anEnumeration. The returnedIterablecan be used for a single iteration.- Type Parameters:
T- the element type- Parameters:
enumeration- the enumeration to use, may not be null- Returns:
- a new, single use
Iterable - Since:
- 4.5.0-M1
-
get
Gets theindex-th value in theEnumeration, throwingIndexOutOfBoundsExceptionif there is no such element.The Enumeration is advanced to
index(or to the end, ifindexexceeds the number of entries) as a side effect of this method.- Type Parameters:
T- the type of object in theEnumeration- Parameters:
e- the enumeration to get a value fromindex- the index to get- Returns:
- the object at the specified index
- Throws:
IndexOutOfBoundsException- if the index is invalidIllegalArgumentException- if the object type is invalid- Since:
- 4.1
-
toList
Creates a list based on an enumeration.As the enumeration is traversed, an ArrayList of its values is created. The new list is returned.
- Type Parameters:
E- the element type- Parameters:
enumeration- the enumeration to traverse, which should not benull.- Returns:
- a list containing all elements of the given enumeration
- Throws:
NullPointerException- if the enumeration parameter isnull.
-
toList
Override toList(Enumeration) for StringTokenizer as it implements Enumeration<Object> for the sake of backward compatibility. -
toSet
Creates a set based on an enumeration.As the enumeration is traversed, an HashSet of its values is created. The new set is returned.
- Type Parameters:
E- the element type- Parameters:
enumeration- the enumeration to traverse, which should not benull.- Returns:
- a set containing all elements of the given enumeration.
- Throws:
NullPointerException- if the enumeration parameter isnull.- Since:
- 4.5.0-M4
-