Package org.apache.commons.collections4

# Class EnumerationUtils

java.lang.Object
org.apache.commons.collections4.EnumerationUtils

public class EnumerationUtils extends Object
Provides utility methods for `Enumeration` instances.

Since:
  3.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> Iterable<T>`
  `asIterable(Enumeration<T> enumeration)`
  Creates an `Iterable` that wraps an `Enumeration`.
  `static <T> T`
  `get(Enumeration<T> enumeration, int index)`
  Gets the `index`-th value in the `Enumeration`, throwing `IndexOutOfBoundsException` if there is no such element.
  `static <E> List<E>`
  `toList(Enumeration<? extends E> enumeration)`
  Creates a list based on an enumeration.
  `static List<String>`
  `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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### asIterable

    public static <T> Iterable<T> asIterable(Enumeration<T> enumeration)
    Creates an `Iterable` that wraps an `Enumeration`. The returned `Iterable` can 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`.
    Throws:
      `NullPointerException` - if enumeration is null.
    Since:
      4.5.0-M1

  - ### get

    public static <T> T get(Enumeration<T> enumeration, int index)
    Gets 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:
      `enumeration` - 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.
      `NullPointerException` - if enumeration is null.
    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.

  - ### toSet

    public static <E> Set<E> toSet(Enumeration<? extends E> enumeration)
    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 be `null`.
    Returns:
      A set containing all elements of the given enumeration.
    Throws:
      `NullPointerException` - if the enumeration parameter is `null`.
    Since:
      4.5.0-M4