You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/05/14 15:42:42 UTC

[commons-vfs] branch master updated: Minor refactoring.

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-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new 4142e8a  Minor refactoring.
4142e8a is described below

commit 4142e8a689637177df65457ee3b952ffbcd85025
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu May 14 11:42:37 2020 -0400

    Minor refactoring.
---
 .../commons/vfs2/FileSystemConfigBuilder.java      | 223 +++++++++++----------
 .../provider/ftp/FtpFileSystemConfigBuilder.java   |   4 +-
 .../provider/sftp/SftpFileSystemConfigBuilder.java |   6 +-
 3 files changed, 122 insertions(+), 111 deletions(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java
index 9d8ca84..757f0ac 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java
@@ -51,99 +51,6 @@ public abstract class FileSystemConfigBuilder {
     }
 
     /**
-     * Sets the root URI of the file system.
-     *
-     * @param opts the file system options to modify
-     * @param rootURI The creator name to be associated with the file.
-     *
-     * @since 2.0
-     */
-    public void setRootURI(final FileSystemOptions opts, final String rootURI) {
-        setParam(opts, ROOTURI, rootURI);
-    }
-
-    /**
-     * Gets the root URI of the file system.
-     *
-     * @param opts file system options to work with
-     * @return The root URI
-     *
-     * @since 2.0
-     */
-    public String getRootURI(final FileSystemOptions opts) {
-        return getString(opts, ROOTURI);
-    }
-
-    /**
-     * Sets named parameter.
-     *
-     * @param opts the file system options to modify
-     * @param name set option with this name
-     * @param value boolean value to set
-     *
-     * @since 2.1
-     */
-    protected void setParam(final FileSystemOptions opts, final String name, final boolean value) {
-        setParam(opts, name, Boolean.valueOf(value));
-    }
-
-    /**
-     * Sets named parameter.
-     *
-     * @param opts the file system options to modify
-     * @param name set option with this name
-     * @param value object value to set
-     *
-     * @since 1.0
-     */
-    protected void setParam(final FileSystemOptions opts, final String name, final Object value) {
-        opts.setOption(getConfigClass(), name, value);
-    }
-
-    /**
-     * Gets named parameter.
-     *
-     * @param opts file system options to work with
-     * @param name get option with this name
-     * @return the named option or null
-     *
-     * @since 1.0
-     */
-    protected Object getParam(final FileSystemOptions opts, final String name) {
-        if (opts == null) {
-            return null;
-        }
-
-        return opts.getOption(getConfigClass(), name);
-    }
-
-    /**
-     * Checks if option exists.
-     *
-     * @param opts file system options to work with
-     * @param name the name to look up in {@code opts}
-     * @return true if opts have the named parameter
-     *
-     * @since 1.0
-     */
-    protected boolean hasParam(final FileSystemOptions opts, final String name) {
-        return opts != null && opts.hasOption(getConfigClass(), name);
-    }
-
-    /**
-     * Checks the named setting specified.
-     *
-     * @param opts file system options to work with
-     * @param name the option to check in {@code opts} or system properties
-     * @return true if option exists
-     *
-     * @since 2.0
-     */
-    protected boolean hasObject(final FileSystemOptions opts, final String name) {
-        return hasParam(opts, name) || System.getProperties().containsKey(toPropertyKey(name));
-    }
-
-    /**
      * Gets named option as boolean.
      *
      * @param opts file system options to work with
@@ -298,6 +205,15 @@ public abstract class FileSystemConfigBuilder {
     }
 
     /**
+     * Gets the target of this configuration.
+     *
+     * @return the specific file system class
+     *
+     * @since 1.0
+     */
+    protected abstract Class<? extends FileSystem> getConfigClass();
+
+    /**
      * Gets named option as double.
      *
      * @param opts file system options to work with
@@ -556,6 +472,47 @@ public abstract class FileSystemConfigBuilder {
     }
 
     /**
+     * Gets named parameter.
+     *
+     * @param opts file system options to work with
+     * @param name get option with this name
+     * @return the named option or null
+     *
+     * @since 1.0
+     */
+    protected Object getParam(final FileSystemOptions opts, final String name) {
+        if (opts == null) {
+            return null;
+        }
+
+        return opts.getOption(getConfigClass(), name);
+    }
+
+    /**
+     * Gets the system property for the given name.
+     *
+     * @param name The name to lookup combined with the prefix.
+     * @return a system property or null
+     *
+     * @since 2.1
+     */
+    private String getProperty(final String name) {
+        return System.getProperty(toPropertyKey(name));
+    }
+
+    /**
+     * Gets the root URI of the file system.
+     *
+     * @param opts file system options to work with
+     * @return The root URI
+     *
+     * @since 2.0
+     */
+    public String getRootURI(final FileSystemOptions opts) {
+        return getString(opts, ROOTURI);
+    }
+
+    /**
      * Gets named option as short.
      *
      * @param opts file system options to work with
@@ -645,36 +602,90 @@ public abstract class FileSystemConfigBuilder {
     }
 
     /**
-     * Gets the target of this configuration.
+     * Checks the named setting specified.
      *
-     * @return the specific file system class
+     * @param opts file system options to work with
+     * @param name the option to check in {@code opts} or system properties
+     * @return true if option exists
+     *
+     * @since 2.0
+     */
+    protected boolean hasObject(final FileSystemOptions opts, final String name) {
+        return hasParam(opts, name) || System.getProperties().containsKey(toPropertyKey(name));
+    }
+
+    /**
+     * Checks if option exists.
+     *
+     * @param opts file system options to work with
+     * @param name the name to look up in {@code opts}
+     * @return true if opts have the named parameter
      *
      * @since 1.0
      */
-    protected abstract Class<? extends FileSystem> getConfigClass();
+    protected boolean hasParam(final FileSystemOptions opts, final String name) {
+        return opts != null && opts.hasOption(getConfigClass(), name);
+    }
 
     /**
-     * Converts the given name into a System property key.
+     * Sets named parameter.
      *
-     * @param name a name to combine with the builder prefix
-     * @return name of system property
+     * @param opts the file system options to modify
+     * @param name set option with this name
+     * @param value boolean value to set
      *
      * @since 2.1
      */
-    private String toPropertyKey(final String name) {
-        return this.prefix + name;
+    protected void setParam(final FileSystemOptions opts, final String name, final boolean value) {
+        setParam(opts, name, Boolean.valueOf(value));
     }
 
     /**
-     * Gets the system property for the given name.
+     * Sets named parameter.
      *
-     * @param name The name to lookup combined with the prefix.
-     * @return a system property or null
+     * @param opts the file system options to modify
+     * @param name set option with this name
+     * @param value object value to set
+     *
+     * @since 1.0
+     */
+    protected void setParam(final FileSystemOptions opts, final String name, final Object value) {
+        opts.setOption(getConfigClass(), name, value);
+    }
+
+    /**
+     * Sets the root URI of the file system.
+     *
+     * @param opts the file system options to modify
+     * @param rootURI The creator name to be associated with the file.
+     *
+     * @since 2.0
+     */
+    public void setRootURI(final FileSystemOptions opts, final String rootURI) {
+        setParam(opts, ROOTURI, rootURI);
+    }
+
+    /**
+     * Converts the given primitive boolean to a Boolean object.
+     *
+     * @param value a primitive boolean.
+     * @return the given primitive boolean as Boolean object.
+     * @since 2.7.0
+     */
+    protected Boolean toBooleanObject(final boolean value) {
+        return value ? Boolean.TRUE : Boolean.FALSE;
+    }
+
+    /**
+     * Converts the given name into a System property key.
+     *
+     * @param name a name to combine with the builder prefix
+     * @return name of system property
      *
      * @since 2.1
      */
-    private String getProperty(final String name) {
-        return System.getProperty(toPropertyKey(name));
+    private String toPropertyKey(final String name) {
+        return this.prefix + name;
     }
 
 }
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java
index d60a349..fe19586 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java
@@ -374,7 +374,7 @@ public class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder {
      * @param passiveMode true if passive mode should be used.
      */
     public void setPassiveMode(final FileSystemOptions opts, final boolean passiveMode) {
-        setParam(opts, PASSIVE_MODE, passiveMode ? Boolean.TRUE : Boolean.FALSE);
+        setParam(opts, PASSIVE_MODE, toBooleanObject(passiveMode));
     }
 
     /**
@@ -469,7 +469,7 @@ public class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder {
      * @param userDirIsRoot true if the user directory should be treated as the root.
      */
     public void setUserDirIsRoot(final FileSystemOptions opts, final boolean userDirIsRoot) {
-        setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
+        setParam(opts, USER_DIR_IS_ROOT, toBooleanObject(userDirIsRoot));
     }
 
     /**
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
index 75ee172..7b4ee64 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
@@ -507,7 +507,7 @@ public final class SftpFileSystemConfigBuilder extends FileSystemConfigBuilder {
      * @since 2.7.0
      */
     public void setDisableDetectExecChannel(final FileSystemOptions opts, final boolean disableDetectExecChannel) {
-        this.setParam(opts, DISABLE_DETECT_EXEC_CHANNEL, disableDetectExecChannel ? Boolean.TRUE : Boolean.FALSE);
+        this.setParam(opts, DISABLE_DETECT_EXEC_CHANNEL, toBooleanObject(disableDetectExecChannel));
     }
 
     /**
@@ -620,7 +620,7 @@ public final class SftpFileSystemConfigBuilder extends FileSystemConfigBuilder {
      * @param loadOpenSSHConfig true if the OpenSSH config should be loaded.
      */
     public void setLoadOpenSSHConfig(final FileSystemOptions opts, final boolean loadOpenSSHConfig) {
-        this.setParam(opts, LOAD_OPENSSH_CONFIG, loadOpenSSHConfig ? Boolean.TRUE : Boolean.FALSE);
+        this.setParam(opts, LOAD_OPENSSH_CONFIG, toBooleanObject(loadOpenSSHConfig));
     }
 
     /**
@@ -780,7 +780,7 @@ public final class SftpFileSystemConfigBuilder extends FileSystemConfigBuilder {
      * @param userDirIsRoot true if the user directory is the root directory.
      */
     public void setUserDirIsRoot(final FileSystemOptions opts, final boolean userDirIsRoot) {
-        this.setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
+        this.setParam(opts, USER_DIR_IS_ROOT, toBooleanObject(userDirIsRoot));
     }
 
     /**