Package org.apache.commons.collections4
Class EnumerationUtils
- java.lang.Object
-
- org.apache.commons.collections4.EnumerationUtils
-
public class EnumerationUtils extends java.lang.Object
Provides utility methods forEnumeration
instances.- Since:
- 3.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
get(java.util.Enumeration<T> e, int index)
Returns theindex
-th value in theEnumeration
, throwingIndexOutOfBoundsException
if there is no such element.static <E> java.util.List<E>
toList(java.util.Enumeration<? extends E> enumeration)
Creates a list based on an enumeration.static java.util.List<java.lang.String>
toList(java.util.StringTokenizer stringTokenizer)
Override toList(Enumeration) for StringTokenizer as it implements Enumeration<Object> for the sake of backward compatibility.
-
-
-
Method Detail
-
get
public static <T> T get(java.util.Enumeration<T> e, int index)
Returns theindex
-th value in theEnumeration
, throwingIndexOutOfBoundsException
if there is no such element.The Enumeration is advanced to
index
(or to the end, ifindex
exceeds 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:
java.lang.IndexOutOfBoundsException
- if the index is invalidjava.lang.IllegalArgumentException
- if the object type is invalid- Since:
- 4.1
-
toList
public static <E> java.util.List<E> toList(java.util.Enumeration<? extends E> enumeration)
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:
java.lang.NullPointerException
- if the enumeration parameter isnull
.
-
toList
public static java.util.List<java.lang.String> toList(java.util.StringTokenizer stringTokenizer)
Override toList(Enumeration) for StringTokenizer as it implements Enumeration<Object> for the sake of backward compatibility.- Parameters:
stringTokenizer
- the tokenizer to convert to aList
<String
>- Returns:
- a list containing all tokens of the given StringTokenizer
-
-