org.sadun.util
Class ExtensionFilenameFilter

java.lang.Object
  extended byorg.sadun.util.ExtensionFilenameFilter
All Implemented Interfaces:
java.io.FilenameFilter

public class ExtensionFilenameFilter
extends java.lang.Object
implements java.io.FilenameFilter

A simple FilenameFilter based on file extensions.

Version:
1.1
Author:
Cris Sadun

Constructor Summary
ExtensionFilenameFilter(java.lang.String extensions)
          Create a filter which will accept the given extension (denoted by a comma-separated string)
ExtensionFilenameFilter(java.lang.String[] ext)
          Create a filter which will filter the given extension (denoted by a string array)
ExtensionFilenameFilter(java.lang.String[] ext, boolean doAccept)
          Create a filter which will filter the given extension (denoted by a string array)
ExtensionFilenameFilter(java.lang.String extensions, boolean doAccept)
          Create a filter which will accept or refuse the given extension (denoted by a comma-separated string)
 
Method Summary
 boolean accept(java.io.File dir, java.lang.String name)
          Accept or refuse a file basing on its extension and the current working mode (see getAcceptsExtensions()).
 boolean getAcceptsExtensions()
          Return true if the filter is currently set to accept files whose extension matches the extensions provided at construction.
 void invert()
          Invert the filter - after this call, files that were accepted will be refused, and vice versa (see getAcceptsExtensions()).
 java.lang.String lastMatchingExtension()
          Returns the extension that has been last matched in a call of accept(), or null if accept has never been invoked or no extension has been matched.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtensionFilenameFilter

public ExtensionFilenameFilter(java.lang.String extensions)
Create a filter which will accept the given extension (denoted by a comma-separated string)

Parameters:
extensions - a comma-separated string with the extensions

ExtensionFilenameFilter

public ExtensionFilenameFilter(java.lang.String extensions,
                               boolean doAccept)
Create a filter which will accept or refuse the given extension (denoted by a comma-separated string)

Parameters:
extensions - a comma-separated string with the extensions
doAccept - if true, the filter will accept the files with the given extensions, refuse otherwise.

ExtensionFilenameFilter

public ExtensionFilenameFilter(java.lang.String[] ext)
Create a filter which will filter the given extension (denoted by a string array)


ExtensionFilenameFilter

public ExtensionFilenameFilter(java.lang.String[] ext,
                               boolean doAccept)
Create a filter which will filter the given extension (denoted by a string array)

Parameters:
doAccept - if true, the filter will accept the files with the given extensions, refuse otherwise.
Method Detail

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Accept or refuse a file basing on its extension and the current working mode (see getAcceptsExtensions()).

Specified by:
accept in interface java.io.FilenameFilter

invert

public void invert()
Invert the filter - after this call, files that were accepted will be refused, and vice versa (see getAcceptsExtensions()).


getAcceptsExtensions

public boolean getAcceptsExtensions()
Return true if the filter is currently set to accept files whose extension matches the extensions provided at construction.

Returns:
true if the filter is currently set to accept files whose extension matches the extensions provided at construction.

lastMatchingExtension

public java.lang.String lastMatchingExtension()
Returns the extension that has been last matched in a call of accept(), or null if accept has never been invoked or no extension has been matched.

Returns:
the last matched exception