You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by "Harmeet Bedi[yahoo]" <hb...@yahoo.com> on 2001/03/12 19:41:08 UTC
possible bug in DirectroryFileFilter
possible bug in org.apache.avalon.util.io.DirectoryFileFilter
I think it should be
------------------------------
public class DirectoryFileFilter
implements FilenameFilter
{
public boolean accept( final File file, final String name )
{
return new File(file,name).isDirectory();
}
}
instead of
--------------------------------------------------
public class DirectoryFileFilter
implements FilenameFilter
{
public boolean accept( final File file, final String name )
{
return file.isDirectory();
}
}
Harmeet
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: possible bug in DirectroryFileFilter
Posted by Berin Loritsch <bl...@apache.org>.
"Harmeet Bedi[yahoo]" wrote:
>
> The originnal <DirectoryFileFilter> returned all the files, not the
> subdirectories from parent directory. The problem is that the
> DirectoryFileFilter, is checking the parent directory not the child node.
> Well anyway, the modified code is working for me and the originnal did not.
>
> Hers is a JUnit like test
> File directory = ....
> File[] subdir = directory.listFiles(new DirectoryFileFilter());
> for ( int i = 0 ; i < subdir.length ; i++ ) {
> // assert( <string>, <assertion check>);
> assert(subdir[i].getAbsolutePath(),subdir[i].isDirectory());
> }
>
> Have I got the test wrong ?
> If you point to a directory that has subdirectories and files, the test
> would fail with originnal code.
You know what, I looked at the thing backwards. I appologize for that.
I am so used to seeing the current version first and the modified version
second, that I didn't even pay attention to the titles above the code
snippets.
>
> Harmeet
>
> ----- Original Message -----
> From: "Berin Loritsch" <bl...@apache.org>
> To: "Avalon Development" <av...@jakarta.apache.org>
> Sent: Monday, March 12, 2001 10:51 AM
> Subject: Re: possible bug in DirectroryFileFilter
>
> > "Harmeet Bedi[yahoo]" wrote:
> > >
> > > possible bug in org.apache.avalon.util.io.DirectoryFileFilter
> > >
> > > I think it should be
> > > ------------------------------
> > > public class DirectoryFileFilter
> > > implements FilenameFilter
> > > {
> > > public boolean accept( final File file, final String name )
> > > {
> > > return new File(file,name).isDirectory();
> > > }
> > > }
> > >
> > > instead of
> > > --------------------------------------------------
> > > public class DirectoryFileFilter
> > > implements FilenameFilter
> > > {
> > > public boolean accept( final File file, final String name )
> > > {
> > > return file.isDirectory();
> > > }
> > > }
> >
> > The purpose of the FileFilter is to list all directories that are
> > subdirectories of a File. So if you only want to list the directories,
> > you don't test against the parent (which is almost always a directory).
> > Otherwise, you will get a true value for all children. Not what we
> > want.
> >
> > The DirectoryFileFilter is correct.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: possible bug in DirectroryFileFilter
Posted by Berin Loritsch <bl...@apache.org>.
"Harmeet Bedi[yahoo]" wrote:
>
> possible bug in org.apache.avalon.util.io.DirectoryFileFilter
>
> I think it should be
> ------------------------------
> public class DirectoryFileFilter
> implements FilenameFilter
> {
> public boolean accept( final File file, final String name )
> {
> return new File(file,name).isDirectory();
> }
> }
>
> instead of
> --------------------------------------------------
> public class DirectoryFileFilter
> implements FilenameFilter
> {
> public boolean accept( final File file, final String name )
> {
> return file.isDirectory();
> }
> }
The purpose of the FileFilter is to list all directories that are
subdirectories of a File. So if you only want to list the directories,
you don't test against the parent (which is almost always a directory).
Otherwise, you will get a true value for all children. Not what we
want.
The DirectoryFileFilter is correct.
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org