Class EnumerationUtils


  • public class EnumerationUtils
    extends Object
    Provides utility methods for Enumeration instances.
    Since:
    3.0
    • Method Detail

      • get

        public static <T> T get​(Enumeration<T> e,
                                int index)
        Returns the index-th value in the Enumeration, throwing IndexOutOfBoundsException if there is no such element.

        The Enumeration is advanced to index (or to the end, if index exceeds the number of entries) as a side effect of this method.

        Type Parameters:
        T - the type of object in the Enumeration
        Parameters:
        e - the enumeration to get a value from
        index - the index to get
        Returns:
        the object at the specified index
        Throws:
        IndexOutOfBoundsException - if the index is invalid
        IllegalArgumentException - if the object type is invalid
        Since:
        4.1
      • toList

        public static <E> List<E> toList​(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 be null.
        Returns:
        a list containing all elements of the given enumeration
        Throws:
        NullPointerException - if the enumeration parameter is null.
      • toList

        public static List<String> toList​(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 a List<String>
        Returns:
        a list containing all tokens of the given StringTokenizer