Package net.sourceforge.pmd.util.filter
Class Filters
- java.lang.Object
-
- net.sourceforge.pmd.util.filter.Filters
-
public final class Filters extends java.lang.Object
Utility class for working with Filters. Contains builder style methods, apply methods, as well as mechanisms for adapting Filters and FilenameFilters.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Filter<java.lang.String>
buildRegexFilterExcludeOverInclude(java.util.List<java.lang.String> includeRegexes, java.util.List<java.lang.String> excludeRegexes)
Construct a String Filter using set of include and exclude regular expressions.static Filter<java.lang.String>
buildRegexFilterIncludeOverExclude(java.util.List<java.lang.String> includeRegexes, java.util.List<java.lang.String> excludeRegexes)
Construct a String Filter using set of include and exclude regular expressions.static <T> java.util.List<T>
filter(Filter<T> filter, java.util.Collection<T> collection)
Filter a given Collection.static <T> Filter<T>
fromStringFilter(Filter<java.lang.String> filter)
Given a String Filter, expose as a Filter on another type.static Filter<java.io.File>
getDirectoryFilter()
Get a File Filter for directories.static Filter<java.io.File>
getFileExtensionFilter(java.lang.String... extensions)
Get a File Filter for files with the given extensions, ignoring case.static Filter<java.io.File>
getFileExtensionOrDirectoryFilter(java.lang.String... extensions)
Get a File Filter for directories or for files with the given extensions, ignoring case.static Filter<java.io.File>
toFileFilter(java.io.FilenameFilter filter)
Given a FilenameFilter, expose as a File Filter.static java.io.FilenameFilter
toFilenameFilter(Filter<java.io.File> filter)
Given a File Filter, expose as a FilenameFilter.static Filter<java.io.File>
toNormalizedFileFilter(Filter<java.lang.String> filter)
Given a String Filter, expose as a File Filter.
-
-
-
Method Detail
-
filter
public static <T> java.util.List<T> filter(Filter<T> filter, java.util.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<java.io.File> getFileExtensionFilter(java.lang.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<java.io.File> getDirectoryFilter()
Get a File Filter for directories.- Returns:
- A File Filter.
-
getFileExtensionOrDirectoryFilter
public static Filter<java.io.File> getFileExtensionOrDirectoryFilter(java.lang.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<java.io.File> toNormalizedFileFilter(Filter<java.lang.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<java.lang.String> filter)
Given a String Filter, expose as a Filter on another type. ThetoString()
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 java.io.FilenameFilter toFilenameFilter(Filter<java.io.File> filter)
Given a File Filter, expose as a FilenameFilter.- Parameters:
filter
- The File Filter.- Returns:
- A FilenameFilter.
-
toFileFilter
public static Filter<java.io.File> toFileFilter(java.io.FilenameFilter filter)
Given a FilenameFilter, expose as a File Filter.- Parameters:
filter
- The FilenameFilter.- Returns:
- A File Filter.
-
buildRegexFilterExcludeOverInclude
public static Filter<java.lang.String> buildRegexFilterExcludeOverInclude(java.util.List<java.lang.String> includeRegexes, java.util.List<java.lang.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 benull
.excludeRegexes
- The exclude regular expressions. May benull
.- Returns:
- A String Filter.
-
buildRegexFilterIncludeOverExclude
public static Filter<java.lang.String> buildRegexFilterIncludeOverExclude(java.util.List<java.lang.String> includeRegexes, java.util.List<java.lang.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 benull
.excludeRegexes
- The exclude regular expressions. May benull
.- Returns:
- A String Filter.
-
-