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: 6350345
Votes 3
Synopsis Add filter class to java.util
Category java:classes_util
Reported Against
Release Fixed
State 6-Fix Understood, request for enhancement
Priority: 4-Low
Related Bugs 6406800
Submit Date 15-NOV-2005
Description
A DESCRIPTION OF THE REQUEST :
I think that it would be nice if the java util classes had this:

new interface

public interface java.util.Filter<Object T> {
    public boolean accept(T item);
}

new methods on java.util.Collection<Object T>
    public void addAll(Iterable<T> src, Filter<T> filter);
    public void addAll(Iterator<T> iterator); // if it isn't already there
    public Iterator iterator(Filter<T> filter);

new method on java.util.Collections
    public static <T> Iterator<T> filter(Iterator<T> iterator, Filter<T> filter) // not 100% sure about the generics syntax

new methods on java.io.File
    String[] list(Filter<String> filter);
    File[] listFiles(Filter<File> filter);

Deprecate classes FileFilter and FileNameFilter, but have the deprecated classes implement Filter<File> and Filter<String> for now. Deprecate list(FileNameFilter ) and listFiles(FileFilter).

JUSTIFICATION :
This would provide a standard interface for a common programming task. I'm sure there are other places in the APIs where this would be appropriate.

I note that bug 5053833 has been marked not fixed because the standard libraties should not be doing set theory.

Might I however suggest a new Method on java.util.Collections:

    public static Iterator concatenate(Iterable a, Iterable b)

 


CUSTOMER SUBMITTED WORKAROUND :
Roll your own class
Posted Date : 2005-11-15 11:30:13.0
Work Around
N/A
Evaluation
A reasonable request.

Note that Java has no special support for first-class functions,
and so such features as the one proposed here are less compelling.
Posted Date : 2006-02-03 05:04:46.0
Comments
  
  Include a link with my name & email   

Submitted On 24-MAY-2006
jedws
Support for first class functions would be compelling...



PLEASE NOTE: JDK6 is formerly known as Project Mustang