Class NameFileFilter

  • All Implemented Interfaces:
    java.io.Serializable, FileFilter

    public class NameFileFilter
    extends java.lang.Object
    implements FileFilter, java.io.Serializable
    Filters file names for a certain name.

    For example, to print all files and directories in the current directory whose name is Test:

     FileSystemManager fsManager = VFS.getManager();
     FileObject dir = fsManager.toFileObject(new File("."));
     FileObject[] files = dir.findFiles(new FileFilterSelector(new NameFileFilter("Test")));
     for (int i = 0; i < files.length; i++) {
         System.out.println(files[i]);
     }
     
    Since:
    2.4
    See Also:
    "http://commons.apache.org/proper/commons-io/", Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private IOCase caseSensitivity
      Whether the comparison is case sensitive.
      private java.util.List<java.lang.String> names
      The file names to search for.
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      NameFileFilter​(java.lang.String... names)
      Constructs a new case-sensitive name file filter for an array of names.
      NameFileFilter​(java.util.List<java.lang.String> names)
      Constructs a new case-sensitive name file filter for a list of names.
      NameFileFilter​(IOCase caseSensitivity, java.lang.String... names)
      Constructs a new name file filter for an array of names specifying case-sensitivity.
      NameFileFilter​(IOCase caseSensitivity, java.util.List<java.lang.String> names)
      Constructs a new name file filter for a list of names specifying case-sensitivity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(FileSelectInfo fileSelectInfo)
      Checks to see if the file name matches.
      java.lang.String toString()
      Provide a String representation of this file filter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • caseSensitivity

        private final IOCase caseSensitivity
        Whether the comparison is case sensitive.
      • names

        private final java.util.List<java.lang.String> names
        The file names to search for.
    • Constructor Detail

      • NameFileFilter

        public NameFileFilter​(java.util.List<java.lang.String> names)
        Constructs a new case-sensitive name file filter for a list of names.
        Parameters:
        names - the names to allow, must not be null
      • NameFileFilter

        public NameFileFilter​(IOCase caseSensitivity,
                              java.util.List<java.lang.String> names)
        Constructs a new name file filter for a list of names specifying case-sensitivity.
        Parameters:
        caseSensitivity - how to handle case sensitivity, null means case-sensitive
        names - the names to allow, must not be null
      • NameFileFilter

        public NameFileFilter​(java.lang.String... names)
        Constructs a new case-sensitive name file filter for an array of names.

        The array is not cloned, so could be changed after constructing the instance. This would be inadvisable however.

        Parameters:
        names - the names to allow, must not be null
      • NameFileFilter

        public NameFileFilter​(IOCase caseSensitivity,
                              java.lang.String... names)
        Constructs a new name file filter for an array of names specifying case-sensitivity.
        Parameters:
        caseSensitivity - how to handle case sensitivity, null means case-sensitive
        names - the names to allow, must not be null
    • Method Detail

      • accept

        public boolean accept​(FileSelectInfo fileSelectInfo)
        Checks to see if the file name matches.
        Specified by:
        accept in interface FileFilter
        Parameters:
        fileSelectInfo - the File to check
        Returns:
        true if the file name matches
      • toString

        public java.lang.String toString()
        Provide a String representation of this file filter.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation