You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/10/16 21:06:52 UTC

[GitHub] [commons-vfs] garydgregory commented on a diff in pull request #318: Add active port range configuration for ftp client factory

garydgregory commented on code in PR #318:
URL: https://github.com/apache/commons-vfs/pull/318#discussion_r996494388


##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpActivePortRange.java:
##########
@@ -0,0 +1,123 @@
+package org.apache.commons.vfs2.provider.ftp;
+
+import java.io.Serializable;
+
+/**
+ * The FTP active port range.
+ */
+public final class FtpActivePortRange implements Serializable {
+
+    /**
+     * Serialization version.
+     *
+     * @see java.io.Serializable
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Obtains FTP active port range with the specified minimum and maximum values (both inclusive).
+     *
+     * @param minimum the minimum port (inclusive)
+     * @param maximum the maximum port (inclusive)
+     * @throws IllegalArgumentException if minimum value is greater than maximum one
+     */
+    public static FtpActivePortRange of(final int minimum, final int maximum) {
+        return new FtpActivePortRange(minimum, maximum);
+    }
+
+    /**
+     * The minimum value in this range (inclusive).
+     */
+    private final int minimum;

Review Comment:
   Reuse Commons Lang Range class.



##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpActivePortRange.java:
##########
@@ -0,0 +1,123 @@
+package org.apache.commons.vfs2.provider.ftp;
+
+import java.io.Serializable;
+
+/**
+ * The FTP active port range.
+ */
+public final class FtpActivePortRange implements Serializable {
+
+    /**
+     * Serialization version.
+     *
+     * @see java.io.Serializable
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Obtains FTP active port range with the specified minimum and maximum values (both inclusive).
+     *
+     * @param minimum the minimum port (inclusive)
+     * @param maximum the maximum port (inclusive)
+     * @throws IllegalArgumentException if minimum value is greater than maximum one
+     */
+    public static FtpActivePortRange of(final int minimum, final int maximum) {
+        return new FtpActivePortRange(minimum, maximum);
+    }
+
+    /**
+     * The minimum value in this range (inclusive).
+     */
+    private final int minimum;
+
+    /**
+     * The maximum value in this range (inclusive).
+     */
+    private final int maximum;
+
+    /**
+     * Creates an instance.
+     *
+     * @param minimum the minimum port (inclusive)
+     * @param maximum the maximum port (inclusive)
+     */
+    private FtpActivePortRange(final int minimum, final int maximum) {
+        if (minimum > maximum) {
+            throw new IllegalArgumentException("The maximum value must be greater or equal minimum one: maximum=" +
+                    maximum + ", minimum=" + minimum);
+        }
+        this.minimum = minimum;
+        this.maximum = maximum;
+    }
+
+    public int getMinimum() {
+        return minimum;
+    }
+
+    public int getMaximum() {
+        return maximum;
+    }
+
+    /**
+     * <p>Compares this range to another object to test if they are equal.</p>.
+     *
+     * <p>To be equal, the minimum and maximum values must be equal</p>
+     *
+     * @param obj the reference object with which to compare
+     * @return true if this object is equal
+     */
+    @Override
+    public boolean equals(final Object obj) {
+        if (obj == this) {
+            return true;
+        } else if (obj == null || obj.getClass() != getClass()) {
+            return false;
+        } else {
+            final FtpActivePortRange range = (FtpActivePortRange) obj;
+            return (minimum == range.minimum) && (maximum == range.maximum);
+        }
+    }
+
+    /**
+     * Cached output hashCode (class is immutable).
+     */
+    private transient int hashCode;

Review Comment:
   Caching is not needed.



##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java:
##########
@@ -244,6 +245,16 @@ public Boolean getPassiveMode(final FileSystemOptions options) {
         return getBoolean(options, PASSIVE_MODE);
     }
 
+    /**
+     * Gets the active port range.
+     *
+     * @param options The FileSystemOptions.
+     * @return the FTP active port range

Review Comment:
   New public methods need a 'since' tag.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org