DirectoryStreamFilters.newContentTypeFilter

Rémi Forax forax at univ-mlv.fr
Wed Oct 22 14:55:48 PDT 2008


Mark Thornton a écrit :
> Rémi Forax wrote:
>> Hi alan, hi all,
>> DirectoryStreamFilters.newContentTypeFilter signature can be changed
>> a little to use the method inference algorithm.
>>
>> public static DirectoryStream.Filter<FileRef> 
>> newContentTypeFilter(String type)
>> can be written:
>> public static <T extends FileRef> DirectoryStream.Filter<T> 
>> newContentTypeFilter(String type)
>>
>> In that case, the following code is legal:
>> DirectoryStream.Filter<FileRef> 
>> filter1=DirectoryStreamFilters.newContentTypeFilter("text/html");
>> DirectoryStream.Filter<Path> 
>> filter2=DirectoryStreamFilters.newContentTypeFilter("text/html");
>>
>> Rémi
> I can't see the benefit of this change. The obvious place to use 
> filters already accepts DirectoryStream.Filter<? super Path> and thus 
> a DirectoryStream.Filter<FileRef> is acceptable.
>
> Regards,
> Mark Thornton
Hi Mark,
Because
1) It's better fit with the intention of that filter, a filter that 
works on any FileRef
2) Even if in the JDK all codes use DirectoryStream.Filter<? super 
Path>, wildcards is
    on of the feature of Java that average dukes don't understand so in 
their code
    they will use DirectoryStream.Filter<Path>.

Swing has a similar API for filtering row of a JTable,
you can take a look to method RowFilter.regexFilter()
http://download.java.net/jdk7/docs/api/javax/swing/RowFilter.html#regexFilter(java.lang.String,%20int...)
which is very similar to newContentTypeFilter().

Rémi



More information about the nio-dev mailing list