This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new 1e8155f Sort members. 1e8155f is described below commit 1e8155f3d0058454ce6aa82f98ffe9e77d06f1d3 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Sun Sep 27 11:23:42 2020 -0400 Sort members. --- .../io/filefilter/MagicNumberFileFilter.java | 80 +++++++++---------- .../commons/io/filefilter/NameFileFilter.java | 74 +++++++++--------- .../apache/commons/io/filefilter/OrFileFilter.java | 74 +++++++++--------- .../commons/io/filefilter/PrefixFileFilter.java | 72 ++++++++--------- .../commons/io/filefilter/RegexFileFilter.java | 34 ++++---- .../commons/io/filefilter/SuffixFileFilter.java | 74 +++++++++--------- .../commons/io/filefilter/WildcardFileFilter.java | 90 +++++++++++----------- .../commons/io/filefilter/WildcardFilter.java | 48 ++++++------ 8 files changed, 273 insertions(+), 273 deletions(-) diff --git a/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java index db8e86a..88e3347 100644 --- a/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java @@ -115,6 +115,46 @@ public class MagicNumberFileFilter extends AbstractFileFilter implements /** * <p> * Constructs a new MagicNumberFileFilter and associates it with the magic + * number to test for in files and the byte offset location in the file to + * to look for that magic number. + * </p> + * + * <pre> + * MagicNumberFileFilter tarFileFilter = + * MagicNumberFileFilter(new byte[] {0x75, 0x73, 0x74, 0x61, 0x72}, 257); + * </pre> + * + * <pre> + * MagicNumberFileFilter javaClassFileFilter = + * MagicNumberFileFilter(new byte[] {0xCA, 0xFE, 0xBA, 0xBE}, 0); + * </pre> + * + * @param magicNumber the magic number to look for in the file. + * @param offset the byte offset in the file to start comparing bytes. + * + * @throws IllegalArgumentException if <code>magicNumber</code> is + * {@code null}, or contains no bytes, or <code>offset</code> + * is a negative number. + */ + public MagicNumberFileFilter(final byte[] magicNumber, final long offset) { + if (magicNumber == null) { + throw new IllegalArgumentException("The magic number cannot be null"); + } + if (magicNumber.length == 0) { + throw new IllegalArgumentException("The magic number must contain at least one byte"); + } + if (offset < 0) { + throw new IllegalArgumentException("The offset cannot be negative"); + } + + this.magicNumbers = new byte[magicNumber.length]; + System.arraycopy(magicNumber, 0, this.magicNumbers, 0, magicNumber.length); + this.byteOffset = offset; + } + + /** + * <p> + * Constructs a new MagicNumberFileFilter and associates it with the magic * number to test for in files. This constructor assumes a starting offset * of <code>0</code>. * </p> @@ -175,46 +215,6 @@ public class MagicNumberFileFilter extends AbstractFileFilter implements /** * <p> - * Constructs a new MagicNumberFileFilter and associates it with the magic - * number to test for in files and the byte offset location in the file to - * to look for that magic number. - * </p> - * - * <pre> - * MagicNumberFileFilter tarFileFilter = - * MagicNumberFileFilter(new byte[] {0x75, 0x73, 0x74, 0x61, 0x72}, 257); - * </pre> - * - * <pre> - * MagicNumberFileFilter javaClassFileFilter = - * MagicNumberFileFilter(new byte[] {0xCA, 0xFE, 0xBA, 0xBE}, 0); - * </pre> - * - * @param magicNumber the magic number to look for in the file. - * @param offset the byte offset in the file to start comparing bytes. - * - * @throws IllegalArgumentException if <code>magicNumber</code> is - * {@code null}, or contains no bytes, or <code>offset</code> - * is a negative number. - */ - public MagicNumberFileFilter(final byte[] magicNumber, final long offset) { - if (magicNumber == null) { - throw new IllegalArgumentException("The magic number cannot be null"); - } - if (magicNumber.length == 0) { - throw new IllegalArgumentException("The magic number must contain at least one byte"); - } - if (offset < 0) { - throw new IllegalArgumentException("The offset cannot be negative"); - } - - this.magicNumbers = new byte[magicNumber.length]; - System.arraycopy(magicNumber, 0, this.magicNumbers, 0, magicNumber.length); - this.byteOffset = offset; - } - - /** - * <p> * Accepts the provided file if the file contains the file filter's magic * number at the specified offset. * </p> diff --git a/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java index 4661438..9dcde3b 100644 --- a/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java @@ -50,31 +50,43 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable { private final IOCase caseSensitivity; /** - * Constructs a new case-sensitive name file filter for a single name. + * Constructs a new case-sensitive name file filter for a list of names. * - * @param name the name to allow, must not be null - * @throws IllegalArgumentException if the name is null + * @param names the names to allow, must not be null + * @throws IllegalArgumentException if the name list is null + * @throws ClassCastException if the list does not contain Strings */ - public NameFileFilter(final String name) { - this(name, null); + public NameFileFilter(final List<String> names) { + this(names, null); } /** - * Construct a new name file filter specifying case-sensitivity. + * Constructs a new name file filter for a list of names specifying case-sensitivity. * - * @param name the name to allow, must not be null + * @param names the names to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the name is null + * @throws IllegalArgumentException if the name list is null + * @throws ClassCastException if the list does not contain Strings */ - public NameFileFilter(final String name, final IOCase caseSensitivity) { - if (name == null) { - throw new IllegalArgumentException("The wildcard must not be null"); + public NameFileFilter(final List<String> names, final IOCase caseSensitivity) { + if (names == null) { + throw new IllegalArgumentException("The list of names must not be null"); } - this.names = new String[] {name}; + this.names = names.toArray(EMPTY_STRING_ARRAY); this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } /** + * Constructs a new case-sensitive name file filter for a single name. + * + * @param name the name to allow, must not be null + * @throws IllegalArgumentException if the name is null + */ + public NameFileFilter(final String name) { + this(name, null); + } + + /** * Constructs a new case-sensitive name file filter for an array of names. * <p> * The array is not cloned, so could be changed after constructing the @@ -88,45 +100,33 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable { } /** - * Constructs a new name file filter for an array of names specifying case-sensitivity. + * Construct a new name file filter specifying case-sensitivity. * - * @param names the names to allow, must not be null + * @param name the name to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the names array is null + * @throws IllegalArgumentException if the name is null */ - public NameFileFilter(final String[] names, final IOCase caseSensitivity) { - if (names == null) { - throw new IllegalArgumentException("The array of names must not be null"); + public NameFileFilter(final String name, final IOCase caseSensitivity) { + if (name == null) { + throw new IllegalArgumentException("The wildcard must not be null"); } - this.names = new String[names.length]; - System.arraycopy(names, 0, this.names, 0, names.length); + this.names = new String[] {name}; this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } /** - * Constructs a new case-sensitive name file filter for a list of names. - * - * @param names the names to allow, must not be null - * @throws IllegalArgumentException if the name list is null - * @throws ClassCastException if the list does not contain Strings - */ - public NameFileFilter(final List<String> names) { - this(names, null); - } - - /** - * Constructs a new name file filter for a list of names specifying case-sensitivity. + * Constructs a new name file filter for an array of names specifying case-sensitivity. * * @param names the names to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the name list is null - * @throws ClassCastException if the list does not contain Strings + * @throws IllegalArgumentException if the names array is null */ - public NameFileFilter(final List<String> names, final IOCase caseSensitivity) { + public NameFileFilter(final String[] names, final IOCase caseSensitivity) { if (names == null) { - throw new IllegalArgumentException("The list of names must not be null"); + throw new IllegalArgumentException("The array of names must not be null"); } - this.names = names.toArray(EMPTY_STRING_ARRAY); + this.names = new String[names.length]; + System.arraycopy(names, 0, this.names, 0, names.length); this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } diff --git a/src/main/java/org/apache/commons/io/filefilter/OrFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/OrFileFilter.java index b79d439..8c0fac6 100644 --- a/src/main/java/org/apache/commons/io/filefilter/OrFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/OrFileFilter.java @@ -51,6 +51,22 @@ public class OrFileFilter } /** + * Constructs a new file filter that ORs the result of two other filters. + * + * @param filter1 the first filter, must not be null + * @param filter2 the second filter, must not be null + * @throws IllegalArgumentException if either filter is null + */ + public OrFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) { + if (filter1 == null || filter2 == null) { + throw new IllegalArgumentException("The filters must not be null"); + } + this.fileFilters = new ArrayList<>(2); + addFileFilter(filter1); + addFileFilter(filter2); + } + + /** * Constructs a new instance of <code>OrFileFilter</code> * with the specified filters. * @@ -66,19 +82,29 @@ public class OrFileFilter } /** - * Constructs a new file filter that ORs the result of two other filters. - * - * @param filter1 the first filter, must not be null - * @param filter2 the second filter, must not be null - * @throws IllegalArgumentException if either filter is null + * {@inheritDoc} */ - public OrFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) { - if (filter1 == null || filter2 == null) { - throw new IllegalArgumentException("The filters must not be null"); + @Override + public boolean accept(final File file) { + for (final IOFileFilter fileFilter : fileFilters) { + if (fileFilter.accept(file)) { + return true; + } } - this.fileFilters = new ArrayList<>(2); - addFileFilter(filter1); - addFileFilter(filter2); + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean accept(final File file, final String name) { + for (final IOFileFilter fileFilter : fileFilters) { + if (fileFilter.accept(file, name)) { + return true; + } + } + return false; } /** @@ -115,32 +141,6 @@ public class OrFileFilter } /** - * {@inheritDoc} - */ - @Override - public boolean accept(final File file) { - for (final IOFileFilter fileFilter : fileFilters) { - if (fileFilter.accept(file)) { - return true; - } - } - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean accept(final File file, final String name) { - for (final IOFileFilter fileFilter : fileFilters) { - if (fileFilter.accept(file, name)) { - return true; - } - } - return false; - } - - /** * Provide a String representation of this file filter. * * @return a String representation diff --git a/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java index 1a715f4..dba391b 100644 --- a/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java @@ -52,33 +52,45 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable private final IOCase caseSensitivity; /** - * Constructs a new Prefix file filter for a single prefix. + * Constructs a new Prefix file filter for a list of prefixes. * - * @param prefix the prefix to allow, must not be null - * @throws IllegalArgumentException if the prefix is null + * @param prefixes the prefixes to allow, must not be null + * @throws IllegalArgumentException if the prefix list is null + * @throws ClassCastException if the list does not contain Strings */ - public PrefixFileFilter(final String prefix) { - this(prefix, IOCase.SENSITIVE); + public PrefixFileFilter(final List<String> prefixes) { + this(prefixes, IOCase.SENSITIVE); } /** - * Constructs a new Prefix file filter for a single prefix + * Constructs a new Prefix file filter for a list of prefixes * specifying case-sensitivity. * - * @param prefix the prefix to allow, must not be null + * @param prefixes the prefixes to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the prefix is null + * @throws IllegalArgumentException if the prefix list is null + * @throws ClassCastException if the list does not contain Strings * @since 1.4 */ - public PrefixFileFilter(final String prefix, final IOCase caseSensitivity) { - if (prefix == null) { - throw new IllegalArgumentException("The prefix must not be null"); + public PrefixFileFilter(final List<String> prefixes, final IOCase caseSensitivity) { + if (prefixes == null) { + throw new IllegalArgumentException("The list of prefixes must not be null"); } - this.prefixes = new String[] {prefix}; + this.prefixes = prefixes.toArray(EMPTY_STRING_ARRAY); this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } /** + * Constructs a new Prefix file filter for a single prefix. + * + * @param prefix the prefix to allow, must not be null + * @throws IllegalArgumentException if the prefix is null + */ + public PrefixFileFilter(final String prefix) { + this(prefix, IOCase.SENSITIVE); + } + + /** * Constructs a new Prefix file filter for any of an array of prefixes. * <p> * The array is not cloned, so could be changed after constructing the @@ -92,49 +104,37 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable } /** - * Constructs a new Prefix file filter for any of an array of prefixes + * Constructs a new Prefix file filter for a single prefix * specifying case-sensitivity. * - * @param prefixes the prefixes to allow, must not be null + * @param prefix the prefix to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the prefix is null * @since 1.4 */ - public PrefixFileFilter(final String[] prefixes, final IOCase caseSensitivity) { - if (prefixes == null) { - throw new IllegalArgumentException("The array of prefixes must not be null"); + public PrefixFileFilter(final String prefix, final IOCase caseSensitivity) { + if (prefix == null) { + throw new IllegalArgumentException("The prefix must not be null"); } - this.prefixes = new String[prefixes.length]; - System.arraycopy(prefixes, 0, this.prefixes, 0, prefixes.length); + this.prefixes = new String[] {prefix}; this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } /** - * Constructs a new Prefix file filter for a list of prefixes. - * - * @param prefixes the prefixes to allow, must not be null - * @throws IllegalArgumentException if the prefix list is null - * @throws ClassCastException if the list does not contain Strings - */ - public PrefixFileFilter(final List<String> prefixes) { - this(prefixes, IOCase.SENSITIVE); - } - - /** - * Constructs a new Prefix file filter for a list of prefixes + * Constructs a new Prefix file filter for any of an array of prefixes * specifying case-sensitivity. * * @param prefixes the prefixes to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the prefix list is null - * @throws ClassCastException if the list does not contain Strings + * @throws IllegalArgumentException if the prefix is null * @since 1.4 */ - public PrefixFileFilter(final List<String> prefixes, final IOCase caseSensitivity) { + public PrefixFileFilter(final String[] prefixes, final IOCase caseSensitivity) { if (prefixes == null) { - throw new IllegalArgumentException("The list of prefixes must not be null"); + throw new IllegalArgumentException("The array of prefixes must not be null"); } - this.prefixes = prefixes.toArray(EMPTY_STRING_ARRAY); + this.prefixes = new String[prefixes.length]; + System.arraycopy(prefixes, 0, this.prefixes, 0, prefixes.length); this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } diff --git a/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java index 8084b79..36617dc 100644 --- a/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java @@ -48,35 +48,31 @@ public class RegexFileFilter extends AbstractFileFilter implements Serializable private final Pattern pattern; /** - * Construct a new regular expression filter. + * Construct a new regular expression filter for a compiled regular expression * - * @param pattern regular string expression to match + * @param pattern regular expression to match * @throws IllegalArgumentException if the pattern is null */ - public RegexFileFilter(final String pattern) { + public RegexFileFilter(final Pattern pattern) { if (pattern == null) { throw new IllegalArgumentException("Pattern is missing"); } - this.pattern = Pattern.compile(pattern); + this.pattern = pattern; } /** - * Construct a new regular expression filter with the specified flags case sensitivity. + * Construct a new regular expression filter. * * @param pattern regular string expression to match - * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern is null */ - public RegexFileFilter(final String pattern, final IOCase caseSensitivity) { + public RegexFileFilter(final String pattern) { if (pattern == null) { throw new IllegalArgumentException("Pattern is missing"); } - int flags = 0; - if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) { - flags = Pattern.CASE_INSENSITIVE; - } - this.pattern = Pattern.compile(pattern, flags); + + this.pattern = Pattern.compile(pattern); } /** @@ -94,17 +90,21 @@ public class RegexFileFilter extends AbstractFileFilter implements Serializable } /** - * Construct a new regular expression filter for a compiled regular expression + * Construct a new regular expression filter with the specified flags case sensitivity. * - * @param pattern regular expression to match + * @param pattern regular string expression to match + * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern is null */ - public RegexFileFilter(final Pattern pattern) { + public RegexFileFilter(final String pattern, final IOCase caseSensitivity) { if (pattern == null) { throw new IllegalArgumentException("Pattern is missing"); } - - this.pattern = pattern; + int flags = 0; + if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) { + flags = Pattern.CASE_INSENSITIVE; + } + this.pattern = Pattern.compile(pattern, flags); } /** diff --git a/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java index ff3c153..42533f8 100644 --- a/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java @@ -53,33 +53,45 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable private final IOCase caseSensitivity; /** - * Constructs a new Suffix file filter for a single extension. + * Constructs a new Suffix file filter for a list of suffixes. * - * @param suffix the suffix to allow, must not be null - * @throws IllegalArgumentException if the suffix is null + * @param suffixes the suffixes to allow, must not be null + * @throws IllegalArgumentException if the suffix list is null + * @throws ClassCastException if the list does not contain Strings */ - public SuffixFileFilter(final String suffix) { - this(suffix, IOCase.SENSITIVE); + public SuffixFileFilter(final List<String> suffixes) { + this(suffixes, IOCase.SENSITIVE); } /** - * Constructs a new Suffix file filter for a single extension + * Constructs a new Suffix file filter for a list of suffixes * specifying case-sensitivity. * - * @param suffix the suffix to allow, must not be null + * @param suffixes the suffixes to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the suffix is null + * @throws IllegalArgumentException if the suffix list is null + * @throws ClassCastException if the list does not contain Strings * @since 1.4 */ - public SuffixFileFilter(final String suffix, final IOCase caseSensitivity) { - if (suffix == null) { - throw new IllegalArgumentException("The suffix must not be null"); + public SuffixFileFilter(final List<String> suffixes, final IOCase caseSensitivity) { + if (suffixes == null) { + throw new IllegalArgumentException("The list of suffixes must not be null"); } - this.suffixes = new String[] {suffix}; + this.suffixes = suffixes.toArray(EMPTY_STRING_ARRAY); this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } /** + * Constructs a new Suffix file filter for a single extension. + * + * @param suffix the suffix to allow, must not be null + * @throws IllegalArgumentException if the suffix is null + */ + public SuffixFileFilter(final String suffix) { + this(suffix, IOCase.SENSITIVE); + } + + /** * Constructs a new Suffix file filter for an array of suffixes. * <p> * The array is not cloned, so could be changed after constructing the @@ -93,49 +105,37 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable } /** - * Constructs a new Suffix file filter for an array of suffixes + * Constructs a new Suffix file filter for a single extension * specifying case-sensitivity. * - * @param suffixes the suffixes to allow, must not be null + * @param suffix the suffix to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the suffix array is null + * @throws IllegalArgumentException if the suffix is null * @since 1.4 */ - public SuffixFileFilter(final String[] suffixes, final IOCase caseSensitivity) { - if (suffixes == null) { - throw new IllegalArgumentException("The array of suffixes must not be null"); + public SuffixFileFilter(final String suffix, final IOCase caseSensitivity) { + if (suffix == null) { + throw new IllegalArgumentException("The suffix must not be null"); } - this.suffixes = new String[suffixes.length]; - System.arraycopy(suffixes, 0, this.suffixes, 0, suffixes.length); + this.suffixes = new String[] {suffix}; this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } /** - * Constructs a new Suffix file filter for a list of suffixes. - * - * @param suffixes the suffixes to allow, must not be null - * @throws IllegalArgumentException if the suffix list is null - * @throws ClassCastException if the list does not contain Strings - */ - public SuffixFileFilter(final List<String> suffixes) { - this(suffixes, IOCase.SENSITIVE); - } - - /** - * Constructs a new Suffix file filter for a list of suffixes + * Constructs a new Suffix file filter for an array of suffixes * specifying case-sensitivity. * * @param suffixes the suffixes to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the suffix list is null - * @throws ClassCastException if the list does not contain Strings + * @throws IllegalArgumentException if the suffix array is null * @since 1.4 */ - public SuffixFileFilter(final List<String> suffixes, final IOCase caseSensitivity) { + public SuffixFileFilter(final String[] suffixes, final IOCase caseSensitivity) { if (suffixes == null) { - throw new IllegalArgumentException("The list of suffixes must not be null"); + throw new IllegalArgumentException("The array of suffixes must not be null"); } - this.suffixes = suffixes.toArray(EMPTY_STRING_ARRAY); + this.suffixes = new String[suffixes.length]; + System.arraycopy(suffixes, 0, this.suffixes, 0, suffixes.length); this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; } diff --git a/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java index d5b6cee..8f8e8e3 100644 --- a/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java @@ -59,6 +59,33 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab private final IOCase caseSensitivity; /** + * Construct a new case-sensitive wildcard filter for a list of wildcards. + * + * @param wildcards the list of wildcards to match, not null + * @throws IllegalArgumentException if the pattern list is null + * @throws ClassCastException if the list does not contain Strings + */ + public WildcardFileFilter(final List<String> wildcards) { + this(wildcards, IOCase.SENSITIVE); + } + + /** + * Construct a new wildcard filter for a list of wildcards specifying case-sensitivity. + * + * @param wildcards the list of wildcards to match, not null + * @param caseSensitivity how to handle case sensitivity, null means case-sensitive + * @throws IllegalArgumentException if the pattern list is null + * @throws ClassCastException if the list does not contain Strings + */ + public WildcardFileFilter(final List<String> wildcards, final IOCase caseSensitivity) { + if (wildcards == null) { + throw new IllegalArgumentException("The wildcard list must not be null"); + } + this.wildcards = wildcards.toArray(EMPTY_STRING_ARRAY); + this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; + } + + /** * Construct a new case-sensitive wildcard filter for a single wildcard. * * @param wildcard the wildcard to match @@ -69,6 +96,17 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab } /** + * Construct a new case-sensitive wildcard filter for an array of wildcards. + * <p> + * + * @param wildcards the array of wildcards to match + * @throws IllegalArgumentException if the pattern array is null + */ + public WildcardFileFilter(final String... wildcards) { + this(wildcards, IOCase.SENSITIVE); + } + + /** * Construct a new wildcard filter for a single wildcard specifying case-sensitivity. * * @param wildcard the wildcard to match, not null @@ -84,17 +122,6 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab } /** - * Construct a new case-sensitive wildcard filter for an array of wildcards. - * <p> - * - * @param wildcards the array of wildcards to match - * @throws IllegalArgumentException if the pattern array is null - */ - public WildcardFileFilter(final String... wildcards) { - this(wildcards, IOCase.SENSITIVE); - } - - /** * Construct a new wildcard filter for an array of wildcards specifying case-sensitivity. * <p> * @@ -112,42 +139,14 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab } /** - * Construct a new case-sensitive wildcard filter for a list of wildcards. - * - * @param wildcards the list of wildcards to match, not null - * @throws IllegalArgumentException if the pattern list is null - * @throws ClassCastException if the list does not contain Strings - */ - public WildcardFileFilter(final List<String> wildcards) { - this(wildcards, IOCase.SENSITIVE); - } - - /** - * Construct a new wildcard filter for a list of wildcards specifying case-sensitivity. - * - * @param wildcards the list of wildcards to match, not null - * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @throws IllegalArgumentException if the pattern list is null - * @throws ClassCastException if the list does not contain Strings - */ - public WildcardFileFilter(final List<String> wildcards, final IOCase caseSensitivity) { - if (wildcards == null) { - throw new IllegalArgumentException("The wildcard list must not be null"); - } - this.wildcards = wildcards.toArray(EMPTY_STRING_ARRAY); - this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; - } - - //----------------------------------------------------------------------- - /** * Checks to see if the file name matches one of the wildcards. * - * @param dir the file directory (ignored) - * @param name the file name + * @param file the file to check * @return true if the file name matches one of the wildcards */ @Override - public boolean accept(final File dir, final String name) { + public boolean accept(final File file) { + final String name = file.getName(); for (final String wildcard : wildcards) { if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) { return true; @@ -156,15 +155,16 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab return false; } + //----------------------------------------------------------------------- /** * Checks to see if the file name matches one of the wildcards. * - * @param file the file to check + * @param dir the file directory (ignored) + * @param name the file name * @return true if the file name matches one of the wildcards */ @Override - public boolean accept(final File file) { - final String name = file.getName(); + public boolean accept(final File dir, final String name) { for (final String wildcard : wildcards) { if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) { return true; diff --git a/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java b/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java index 3be0d3e..7658398 100644 --- a/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java @@ -56,6 +56,20 @@ public class WildcardFilter extends AbstractFileFilter implements Serializable { private final String[] wildcards; /** + * Construct a new case-sensitive wildcard filter for a list of wildcards. + * + * @param wildcards the list of wildcards to match + * @throws IllegalArgumentException if the pattern list is null + * @throws ClassCastException if the list does not contain Strings + */ + public WildcardFilter(final List<String> wildcards) { + if (wildcards == null) { + throw new IllegalArgumentException("The wildcard list must not be null"); + } + this.wildcards = wildcards.toArray(EMPTY_STRING_ARRAY); + } + + /** * Construct a new case-sensitive wildcard filter for a single wildcard. * * @param wildcard the wildcard to match @@ -83,35 +97,19 @@ public class WildcardFilter extends AbstractFileFilter implements Serializable { } /** - * Construct a new case-sensitive wildcard filter for a list of wildcards. - * - * @param wildcards the list of wildcards to match - * @throws IllegalArgumentException if the pattern list is null - * @throws ClassCastException if the list does not contain Strings - */ - public WildcardFilter(final List<String> wildcards) { - if (wildcards == null) { - throw new IllegalArgumentException("The wildcard list must not be null"); - } - this.wildcards = wildcards.toArray(EMPTY_STRING_ARRAY); - } - - //----------------------------------------------------------------------- - /** * Checks to see if the file name matches one of the wildcards. * - * @param dir the file directory - * @param name the file name + * @param file the file to check * @return true if the file name matches one of the wildcards */ @Override - public boolean accept(final File dir, final String name) { - if (dir != null && new File(dir, name).isDirectory()) { + public boolean accept(final File file) { + if (file.isDirectory()) { return false; } for (final String wildcard : wildcards) { - if (FilenameUtils.wildcardMatch(name, wildcard)) { + if (FilenameUtils.wildcardMatch(file.getName(), wildcard)) { return true; } } @@ -119,20 +117,22 @@ public class WildcardFilter extends AbstractFileFilter implements Serializable { return false; } + //----------------------------------------------------------------------- /** * Checks to see if the file name matches one of the wildcards. * - * @param file the file to check + * @param dir the file directory + * @param name the file name * @return true if the file name matches one of the wildcards */ @Override - public boolean accept(final File file) { - if (file.isDirectory()) { + public boolean accept(final File dir, final String name) { + if (dir != null && new File(dir, name).isDirectory()) { return false; } for (final String wildcard : wildcards) { - if (FilenameUtils.wildcardMatch(file.getName(), wildcard)) { + if (FilenameUtils.wildcardMatch(name, wildcard)) { return true; } }