1. /*
  2. * Copyright 2003-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.collections;
  17. import java.util.Enumeration;
  18. import java.util.List;
  19. import org.apache.commons.collections.iterators.EnumerationIterator;
  20. /**
  21. * Provides utility methods for {@link Enumeration} instances.
  22. *
  23. * @since Commons Collections 3.0
  24. * @version $Id: EnumerationUtils.java,v 1.5 2004/02/18 01:15:42 scolebourne Exp $
  25. *
  26. * @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
  27. */
  28. public class EnumerationUtils {
  29. /**
  30. * EnumerationUtils is not normally instantiated.
  31. */
  32. public EnumerationUtils() {
  33. // no init.
  34. }
  35. /**
  36. * Creates a list based on an enumeration.
  37. *
  38. * <p>As the enumeration is traversed, an ArrayList of its values is
  39. * created. The new list is returned.</p>
  40. *
  41. * @param enumeration the enumeration to traverse, which should not be <code>null</code>.
  42. * @throws NullPointerException if the enumeration parameter is <code>null</code>.
  43. */
  44. public static List toList(Enumeration enumeration) {
  45. return IteratorUtils.toList(new EnumerationIterator(enumeration));
  46. }
  47. }