Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6966608

public static <T> Iterable<T> Collections.iterable(Enumeration<T>)

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 6u10
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      A DESCRIPTION OF THE REQUEST :
      There shall be a factory method in the Collections method allowing to wrap an Enumeration without allocating an ArrayList and copying the complete content.

      An example (outside of Collections, implemented as standalone utility class) can be found here:

      http://headcrashing.eu/code/eu/headcrashing/java/util/Enumerations.java


      JUSTIFICATION :
      Unnecessary consumption of RAM and CPU time.

      As described in this blog entry, the implementation could be five times faster and consume virtually no heap space, when returning a thin Iterable instead of an ArrayList:

      http://weblogs.java.net/blog/mkarg/archive/2010/07/04/using-enumerations-each-statements-five-times-faster-jre-without-ram-l


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      public static final <T> Iterable<T> iterable(final Enumeration<T> enumeration) {
        return new Iterable<T>() {
          public final Iterator<T> iterator() {
            return new Iterator<T>() {
              public final boolean hasNext() {
                return enumeration.hasMoreElements();
              }
              public final T next() {
                return enumeration.nextElement();
              }
              public final void remove() {
                throw new UnsupportedOperationException();
              }
            };
          }
        };
      }
      ACTUAL -
      Collections.list() allocated an ArrayList on the heap that holds a complete copy of the content of the enumeration, what needs time and space.

      ---------- BEGIN SOURCE ----------
      see above
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Download above class from my web site.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mduigou Mike Duigou
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: