This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/trunk by this push:
new 25e087f More efficient comparison in FileExtensionSelector (#44)
25e087f is described below
commit 25e087f42ff0bda2568b0f38aa1c4f15d6d6e5e7
Author: Robert DeRose <[email protected]>
AuthorDate: Sun Mar 31 11:47:11 2019 -0400
More efficient comparison in FileExtensionSelector (#44)
* Removed duplication from Constructors
* Removed unneeded check for `null` `HashSet` as it is constructed during
object creation by the JVM at runtime.
* Optimized the comparison over the Constructor by converting all
extensions to lowercase and using the `contains` method of a `Set`.
---
.../apache/commons/vfs2/FileExtensionSelector.java | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileExtensionSelector.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileExtensionSelector.java
index bbcf02e..5ad9154 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileExtensionSelector.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileExtensionSelector.java
@@ -47,7 +47,11 @@ public class FileExtensionSelector implements FileSelector {
*/
public FileExtensionSelector(final Collection<String> extensions) {
if (extensions != null) {
- this.extensions.addAll(extensions);
+ for (String ext : extensions) {
+ if (ext != null) {
+ this.extensions.add(ext.toLowerCase());
+ }
+ }
}
}
@@ -57,9 +61,7 @@ public class FileExtensionSelector implements FileSelector {
* @param extensions The extensions to be included by this selector.
*/
public FileExtensionSelector(final String... extensions) {
- if (extensions != null) {
- this.extensions.addAll(Arrays.asList(extensions));
- }
+ this(Arrays.asList(extensions));
}
/**
@@ -70,15 +72,7 @@ public class FileExtensionSelector implements FileSelector {
*/
@Override
public boolean includeFile(final FileSelectInfo fileInfo) throws Exception
{
- if (this.extensions == null) {
- return false;
- }
- for (final String extension : this.extensions) {
- if
(fileInfo.getFile().getName().getExtension().equalsIgnoreCase(extension)) {
- return true;
- }
- }
- return false;
+ return
this.extensions.contains(fileInfo.getFile().getName().getExtension().toLowerCase());
}
/**