net.sourceforge.pmd.util.filter

## Class Filters

- java.lang.Object
- - net.sourceforge.pmd.util.filter.Filters

-     public class Filters
      extends Object

  Utility class for working with Filters. Contains builder style methods, apply methods, as well as mechanisms for adapting Filters and FilenameFilters.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Filters()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Filter<String>` | `buildRegexFilterExcludeOverInclude(List<String> includeRegexes, List<String> excludeRegexes)` Construct a String Filter using set of include and exclude regular expressions.
    `static Filter<String>` | `buildRegexFilterIncludeOverExclude(List<String> includeRegexes, List<String> excludeRegexes)` Construct a String Filter using set of include and exclude regular expressions.
    `static <T> List<T>` | `filter(Filter<T> filter, Collection<T> collection)` Filter a given Collection.
    `static <T> Filter<T>` | `fromStringFilter(Filter<String> filter)` Given a String Filter, expose as a Filter on another type.
    `static Filter<File>` | `getDirectoryFilter()` Get a File Filter for directories.
    `static Filter<File>` | `getFileExtensionFilter(String... extensions)` Get a File Filter for files with the given extensions, ignoring case.
    `static Filter<File>` | `getFileExtensionOrDirectoryFilter(String... extensions)` Get a File Filter for directories or for files with the given extensions, ignoring case.
    `static Filter<File>` | `toFileFilter(FilenameFilter filter)` Given a FilenameFilter, expose as a File Filter.
    `static FilenameFilter` | `toFilenameFilter(Filter<File> filter)` Given a File Filter, expose as a FilenameFilter.
    `static Filter<File>` | `toNormalizedFileFilter(Filter<String> filter)` Given a String Filter, expose as a File Filter.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Filters

          public Filters()

  - ### Method Detail

    - #### filter

          public static <T> List<T> filter(Filter<T> filter,
                           Collection<T> collection)

      Filter a given Collection.
      Type Parameters:
        `T` - Type of the Collection.
      Parameters:
        `filter` - A Filter upon the Type of objects in the Collection.
        `collection` - The Collection to filter.
      Returns:
        A List containing only those objects for which the Filter returned `true`.

    - #### getFileExtensionFilter

          public static Filter<File> getFileExtensionFilter(String... extensions)

      Get a File Filter for files with the given extensions, ignoring case.
      Parameters:
        `extensions` - The extensions to filter.
      Returns:
        A File Filter.

    - #### getDirectoryFilter

          public static Filter<File> getDirectoryFilter()

      Get a File Filter for directories.
      Returns:
        A File Filter.

    - #### getFileExtensionOrDirectoryFilter

          public static Filter<File> getFileExtensionOrDirectoryFilter(String... extensions)

      Get a File Filter for directories or for files with the given extensions, ignoring case.
      Parameters:
        `extensions` - The extensions to filter.
      Returns:
        A File Filter.

    - #### toNormalizedFileFilter

          public static Filter<File> toNormalizedFileFilter(Filter<String> filter)

      Given a String Filter, expose as a File Filter. The File paths are normalized to a standard pattern using `/` as a path separator which can be used cross platform easily in a regular expression based String Filter.
      Parameters:
        `filter` - A String Filter.
      Returns:
        A File Filter.

    - #### fromStringFilter

          public static <T> Filter<T> fromStringFilter(Filter<String> filter)

      Given a String Filter, expose as a Filter on another type. The `toString()` method is called on the objects of the other type and delegated to the String Filter.
      Type Parameters:
        `T` - The desired type.
      Parameters:
        `filter` - The existing String Filter.
      Returns:
        A Filter on the desired type.

    - #### toFilenameFilter

          public static FilenameFilter toFilenameFilter(Filter<File> filter)

      Given a File Filter, expose as a FilenameFilter.
      Parameters:
        `filter` - The File Filter.
      Returns:
        A FilenameFilter.

    - #### toFileFilter

          public static Filter<File> toFileFilter(FilenameFilter filter)

      Given a FilenameFilter, expose as a File Filter.
      Parameters:
        `filter` - The FilenameFilter.
      Returns:
        A File Filter.

    - #### buildRegexFilterExcludeOverInclude

          public static Filter<String> buildRegexFilterExcludeOverInclude(List<String> includeRegexes,
                                                          List<String> excludeRegexes)

      Construct a String Filter using set of include and exclude regular expressions. If there are no include regular expressions provide, then a regular expression is added which matches every String by default. A String is included as long as it matches an include regular expression and does not match an exclude regular expression.

      In other words, exclude patterns override include patterns.

      Parameters:
        `includeRegexes` - The include regular expressions. May be `null`.
        `excludeRegexes` - The exclude regular expressions. May be `null`.
      Returns:
        A String Filter.

    - #### buildRegexFilterIncludeOverExclude

          public static Filter<String> buildRegexFilterIncludeOverExclude(List<String> includeRegexes,
                                                          List<String> excludeRegexes)

      Construct a String Filter using set of include and exclude regular expressions. If there are no include regular expressions provide, then a regular expression is added which matches every String by default. A String is included as long as the case that there is an include which matches or there is not an exclude which matches.

      In other words, include patterns override exclude patterns.

      Parameters:
        `includeRegexes` - The include regular expressions. May be `null`.
        `excludeRegexes` - The exclude regular expressions. May be `null`.
      Returns:
        A String Filter.

Copyright © 2002-2013 InfoEther. All Rights Reserved.