Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6389004
Votes 0
Synopsis (coll) Collections.list should take Iterator, not just Enumeration
Category java:classes_util
Reported Against
Release Fixed
State 5-Cause Known, request for enhancement
Priority: 4-Low
Related Bugs
Submit Date 22-FEB-2006
Description
A DESCRIPTION OF THE REQUEST :
from java.util.Collections:

public static <T> ArrayList<T> list(Enumeration<T> e)
Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration. This method provides interoperability between legacy APIs that return enumerations and new APIs that require collections.

from java.util.Enumeration:

NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

so, if i have an Iterator (but not a Collection or List) and want a List, i can't use Collections.list because i don't have a legacy Enumeration.

JUSTIFICATION :
we're told to prefer Iterator, but are penalized for having one instead of an Enumeration.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
there should be Collections.list(Iterator<T>).

alternatively, there should be a convenient way to translate an Iterator to an Enumeration, since Enumeration offers less functionality than Iterator. (but do we really want to translate to the non-preferred Enumeration class?)
ACTUAL -
there's only Collections.list(Enumeration<T>).

CUSTOMER SUBMITTED WORKAROUND :
writing the Iterator-to-List copy longhand.
Posted Date : 2006-02-22 18:07:37.0
Work Around
N/A
Evaluation
Additional adapters are worth considering.

An Iterator can have an Enumeration view,
and vice versa (with a remove method throwing
UnsupportedOperationException).
Posted Date : 2006-02-22 18:35:02.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang