Class WindowsLikeFilenameFilter

java.lang.Object
com.iizix.util.WindowsLikeFilenameFilter
All Implemented Interfaces:
FilenameFilter

public class WindowsLikeFilenameFilter extends Object implements FilenameFilter
Filters file names like under Windows, with '?' being any character, '*' being any characters and '^' the escape character (the meaning of '?' and '*' becomes the actual character, and two escape characters for a single).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the instance of the file name filter that is case sensitive.
    WindowsLikeFilenameFilter(String filter, boolean isCaseSensitive)
    Creates the instance of the file name filter that is case sensitive.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    accept(File dir, String name)
    Tests if a specified file should be included in a file list with the current filter.
    boolean
    Gets the case sensitivity flag.
    Gets the current filter string.
    boolean
    Checks if a name matches a filter string like under Windows, with '?' being any character, '*' being any characters and '^' the escape character (the meaning of '?' and '*' becomes the actual character, and two escape characters for a single).
    static boolean
    isMatching(String name, int namePos, String filter, int filterPos, boolean isCaseSensitive)
    Checks for a partial match.
    static boolean
    isMatching(String name, String filter)
    Checks if a name matches a filter string like under Windows, with '?' being any character, '*' being any characters and '^' the escape character (the meaning of '?' and '*' becomes the actual character, and two escape characters for a single).
    static boolean
    isMatching(String name, String filter, boolean isCaseSensitive, boolean replaceStarDotStar)
    Checks if a name matches a filter string like under Windows, with '?' being any character, '*' being any characters and '^' the escape character (the meaning of '?' and '*' becomes the actual character, and two escape characters for a single).
    void
    setCaseSensitivity(boolean on)
    Sets the case sensitivity flag.
    void
    setFilter(String filter)
    Sets a new filter string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WindowsLikeFilenameFilter

      public WindowsLikeFilenameFilter(String filter)
      Creates the instance of the file name filter that is case sensitive. Setting the filter parameter to null will include all files.
    • WindowsLikeFilenameFilter

      public WindowsLikeFilenameFilter(String filter, boolean isCaseSensitive)
      Creates the instance of the file name filter that is case sensitive. Setting the filter parameter to null will include all files.
  • Method Details

    • setFilter

      public void setFilter(String filter)
      Sets a new filter string. Setting the filter parameter to null will include all files.
    • getFilter

      public String getFilter()
      Gets the current filter string.
      Returns:
      null if all files are included, otherwise the current filter string.
    • setCaseSensitivity

      public void setCaseSensitivity(boolean on)
      Sets the case sensitivity flag.
    • getCaseSensitivity

      public boolean getCaseSensitivity()
      Gets the case sensitivity flag.
    • accept

      public boolean accept(File dir, String name)
      Tests if a specified file should be included in a file list with the current filter.
      Specified by:
      accept in interface FilenameFilter
      Parameters:
      dir - - the directory in which the file was found.
      name - - the name of the file.
      Returns:
      true if the name should be included in the file list; false otherwise.
    • isMatching

      public boolean isMatching(String name)
      Checks if a name matches a filter string like under Windows, with '?' being any character, '*' being any characters and '^' the escape character (the meaning of '?' and '*' becomes the actual character, and two escape characters for a single).

      Note: "*.*" is replaced with "*" as filter if equal.

    • isMatching

      public static boolean isMatching(String name, String filter)
      Checks if a name matches a filter string like under Windows, with '?' being any character, '*' being any characters and '^' the escape character (the meaning of '?' and '*' becomes the actual character, and two escape characters for a single).

      Note: "*.*" is replaced with "*" as filter if equal.

    • isMatching

      public static boolean isMatching(String name, String filter, boolean isCaseSensitive, boolean replaceStarDotStar)
      Checks if a name matches a filter string like under Windows, with '?' being any character, '*' being any characters and '^' the escape character (the meaning of '?' and '*' becomes the actual character, and two escape characters for a single).
    • isMatching

      public static boolean isMatching(String name, int namePos, String filter, int filterPos, boolean isCaseSensitive)
      Checks for a partial match. This function is recursive. The parameters are the file name string and starting position in it and then the filter string with a starting filter position.
      Returns:
      true for a match; false otherwise.