org.sadun.util
Class ExtensionFileFilter

java.lang.Object
  extended byorg.sadun.util.ExtensionFileFilter
All Implemented Interfaces:
java.io.FileFilter

public class ExtensionFileFilter
extends java.lang.Object
implements java.io.FileFilter

A simple FileFilter based on file extensions.

Version:
1.0
Author:
Cris Sadun

Constructor Summary
ExtensionFileFilter(java.lang.String extensions)
          Create a filter which will accept the given extension (denoted by a comma-separated string)
ExtensionFileFilter(java.lang.String[] ext)
          Create a filter which will filter the given extension (denoted by a string array)
ExtensionFileFilter(java.lang.String[] ext, boolean doAccept)
          Create a filter which will filter the given extension (denoted by a string array)
ExtensionFileFilter(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 path)
          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

ExtensionFileFilter

public ExtensionFileFilter(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

ExtensionFileFilter

public ExtensionFileFilter(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.

ExtensionFileFilter

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


ExtensionFileFilter

public ExtensionFileFilter(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 path)
Accept or refuse a file basing on its extension and the current working mode (see getAcceptsExtensions()).

Specified by:
accept in interface java.io.FileFilter

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