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/12/17 19:35:31 UTC

[commons-net] 02/02: Javadoc. Format to line length 120. Sort methods in AB order. Consistent formatting.

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

commit 2167ad810893e6d19aa6bc4b5d3edbf0f065189f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 17 14:35:24 2020 -0500

    Javadoc.
    Format to line length 120.
    Sort methods in AB order.
    Consistent formatting.
---
 .../java/org/apache/commons/net/ftp/FTPFile.java   | 434 +++++++++------------
 1 file changed, 182 insertions(+), 252 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTPFile.java b/src/main/java/org/apache/commons/net/ftp/FTPFile.java
index 87f374d..0692610 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPFile.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPFile.java
@@ -16,6 +16,7 @@
  */
 
 package org.apache.commons.net.ftp;
+
 import java.io.Serializable;
 import java.util.Calendar;
 import java.util.Date;
@@ -23,15 +24,13 @@ import java.util.Formatter;
 import java.util.TimeZone;
 
 /**
- * The FTPFile class is used to represent information about files stored
- * on an FTP server.
+ * The FTPFile class is used to represent information about files stored on an FTP server.
  *
  * @see FTPFileEntryParser
  * @see FTPClient#listFiles
  */
+public class FTPFile implements Serializable {
 
-public class FTPFile implements Serializable
-{
     private static final long serialVersionUID = 9010790363003271996L;
 
     /** A constant indicating an FTPFile is a file. */
@@ -61,8 +60,7 @@ public class FTPFile implements Serializable
     /** A constant indicating file/directory write permission. */
     public static final int WRITE_PERMISSION = 1;
     /**
-     * A constant indicating file execute permission or directory listing
-     * permission.
+     * A constant indicating file execute permission or directory listing permission.
      */
     public static final int EXECUTE_PERMISSION = 2;
 
@@ -84,375 +82,330 @@ public class FTPFile implements Serializable
     private final boolean[] permissions[]; // e.g. _permissions[USER_ACCESS][READ_PERMISSION]
 
     /** Creates an empty FTPFile. */
-    public FTPFile()
-    {
+    public FTPFile() {
         permissions = new boolean[3][3];
     }
 
     /**
-     * Constructor for use by {@link FTPListParseEngine} only.
-     * Used to create FTPFile entries for failed parses
+     * Constructor for use by {@link FTPListParseEngine} only. Used to create FTPFile entries for failed parses
+     *
      * @param rawListing line that could not be parsed.
      * @since 3.4
      */
-    FTPFile(final String rawListing)
-    {
+    FTPFile(final String rawListing) {
         this.permissions = null; // flag that entry is invalid
         this.rawListing = rawListing;
     }
 
-
-    /**
-     * Set the original FTP server raw listing from which the FTPFile was
-     * created.
-     *
-     * @param rawListing  The raw FTP server listing.
-     */
-    public void setRawListing(final String rawListing)
-    {
-        this.rawListing = rawListing;
+    private char formatType() {
+        switch (type) {
+        case FILE_TYPE:
+            return '-';
+        case DIRECTORY_TYPE:
+            return 'd';
+        case SYMBOLIC_LINK_TYPE:
+            return 'l';
+        default:
+            return '?';
+        }
     }
 
     /**
-     * Get the original FTP server raw listing used to initialize the FTPFile.
+     * Gets the name of the group owning the file. Sometimes this will be a string representation of the group
+     * number.
      *
-     * @return The original FTP server raw listing used to initialize the
-     *         FTPFile.
+     * @return The name of the group owning the file.
      */
-    public String getRawListing()
-    {
-        return rawListing;
+    public String getGroup() {
+        return group;
     }
 
-
     /**
-     * Determine if the file is a directory.
+     * Gets the number of hard links to this file. This is not to be confused with symbolic links.
      *
-     * @return True if the file is of type <code>DIRECTORY_TYPE</code>, false if
-     *         not.
+     * @return The number of hard links to this file.
      */
-    public boolean isDirectory()
-    {
-        return type == DIRECTORY_TYPE;
+    public int getHardLinkCount() {
+        return hardLinkCount;
     }
 
     /**
-     * Determine if the file is a regular file.
+     * If the FTPFile is a symbolic link, this method returns the name of the file being pointed to by the symbolic
+     * link. Otherwise it returns null.
      *
-     * @return True if the file is of type <code>FILE_TYPE</code>, false if
-     *         not.
+     * @return The file pointed to by the symbolic link (null if the FTPFile is not a symbolic link).
      */
-    public boolean isFile()
-    {
-        return type == FILE_TYPE;
+    public String getLink() {
+        return link;
     }
 
     /**
-     * Determine if the file is a symbolic link.
+     * Gets the name of the file.
      *
-     * @return True if the file is of type <code>UNKNOWN_TYPE</code>, false if
-     *         not.
+     * @return The name of the file.
      */
-    public boolean isSymbolicLink()
-    {
-        return type == SYMBOLIC_LINK_TYPE;
+    public String getName() {
+        return name;
     }
 
     /**
-     * Determine if the type of the file is unknown.
+     * Gets the original FTP server raw listing used to initialize the FTPFile.
      *
-     * @return True if the file is of type <code>UNKNOWN_TYPE</code>, false if
-     *         not.
+     * @return The original FTP server raw listing used to initialize the FTPFile.
      */
-    public boolean isUnknown()
-    {
-        return type == UNKNOWN_TYPE;
+    public String getRawListing() {
+        return rawListing;
     }
 
     /**
-     * Used to indicate whether an entry is valid or not.
-     * If the entry is invalid, only the {@link #getRawListing()} method will be useful.
-     * Other methods may fail.
+     * Gets the file size in bytes.
      *
-     * Used in conjunction with list parsing that preseverves entries that failed to parse.
-     * @see FTPClientConfig#setUnparseableEntries(boolean)
-     * @return true if the entry is valid
-     * @since 3.4
+     * @return The file size in bytes.
      */
-    public boolean isValid() {
-        return permissions != null;
+    public long getSize() {
+        return size;
     }
 
     /**
-     * Set the type of the file (<code>DIRECTORY_TYPE</code>,
-     * <code>FILE_TYPE</code>, etc.).
+     * Gets the file timestamp. This usually the last modification time.
      *
-     * @param type  The integer code representing the type of the file.
+     * @return A Calendar instance representing the file timestamp.
      */
-    public void setType(final int type)
-    {
-        this.type = type;
+    public Calendar getTimestamp() {
+        return date;
     }
 
-
     /**
-     * Return the type of the file (one of the <code>_TYPE</code> constants),
-     * e.g., if it is a directory, a regular file, or a symbolic link.
+     * Gets the type of the file (one of the <code>_TYPE</code> constants), e.g., if it is a directory, a regular
+     * file, or a symbolic link.
      *
      * @return The type of the file.
      */
-    public int getType()
-    {
+    public int getType() {
         return type;
     }
 
-
     /**
-     * Set the name of the file.
+     * Gets the name of the user owning the file. Sometimes this will be a string representation of the user number.
      *
-     * @param name  The name of the file.
+     * @return The name of the user owning the file.
      */
-    public void setName(final String name)
-    {
-        this.name = name;
+    public String getUser() {
+        return user;
     }
 
     /**
-     * Return the name of the file.
+     * Tests if the given access group (one of the <code> _ACCESS </code> constants) has the given access
+     * permission (one of the <code> _PERMISSION </code> constants) to the file.
      *
-     * @return The name of the file.
+     * @param access The access group (one of the <code> _ACCESS </code> constants)
+     * @param permission The access permission (one of the <code> _PERMISSION </code> constants)
+     * @throws ArrayIndexOutOfBoundsException if either of the parameters is out of range
+     * @return true if {@link #isValid()} is {@code true &&} the associated permission is set; {@code false} otherwise.
      */
-    public String getName()
-    {
-        return name;
+    public boolean hasPermission(final int access, final int permission) {
+        if (permissions == null) {
+            return false;
+        }
+        return permissions[access][permission];
     }
 
-
     /**
-     * Set the file size in bytes.
-     * @param size The file size in bytes.
+     * Tests if the file is a directory.
+     *
+     * @return True if the file is of type <code>DIRECTORY_TYPE</code>, false if not.
      */
-    public void setSize(final long size)
-    {
-        this.size = size;
+    public boolean isDirectory() {
+        return type == DIRECTORY_TYPE;
     }
 
-
     /**
-     * Return the file size in bytes.
+     * Tests if the file is a regular file.
      *
-     * @return The file size in bytes.
+     * @return True if the file is of type <code>FILE_TYPE</code>, false if not.
      */
-    public long getSize()
-    {
-        return size;
+    public boolean isFile() {
+        return type == FILE_TYPE;
     }
 
-
     /**
-     * Set the number of hard links to this file.  This is not to be
-     * confused with symbolic links.
+     * Tests if the file is a symbolic link.
      *
-     * @param links  The number of hard links to this file.
+     * @return True if the file is of type <code>UNKNOWN_TYPE</code>, false if not.
      */
-    public void setHardLinkCount(final int links)
-    {
-        this.hardLinkCount = links;
+    public boolean isSymbolicLink() {
+        return type == SYMBOLIC_LINK_TYPE;
     }
 
-
     /**
-     * Return the number of hard links to this file.  This is not to be
-     * confused with symbolic links.
+     * Tests if the type of the file is unknown.
      *
-     * @return The number of hard links to this file.
+     * @return True if the file is of type <code>UNKNOWN_TYPE</code>, false if not.
      */
-    public int getHardLinkCount()
-    {
-        return hardLinkCount;
+    public boolean isUnknown() {
+        return type == UNKNOWN_TYPE;
     }
 
-
     /**
-     * Set the name of the group owning the file.  This may be
-     * a string representation of the group number.
+     * Tests whether an entry is valid or not. If the entry is invalid, only the {@link #getRawListing()}
+     * method will be useful. Other methods may fail.
      *
-     * @param group The name of the group owning the file.
+     * Used in conjunction with list parsing that preseverves entries that failed to parse.
+     *
+     * @see FTPClientConfig#setUnparseableEntries(boolean)
+     * @return true if the entry is valid
+     * @since 3.4
      */
-    public void setGroup(final String group)
-    {
-        this.group = group;
+    public boolean isValid() {
+        return permissions != null;
     }
 
+    private String permissionToString(final int access) {
+        final StringBuilder sb = new StringBuilder();
+        if (hasPermission(access, READ_PERMISSION)) {
+            sb.append('r');
+        } else {
+            sb.append('-');
+        }
+        if (hasPermission(access, WRITE_PERMISSION)) {
+            sb.append('w');
+        } else {
+            sb.append('-');
+        }
+        if (hasPermission(access, EXECUTE_PERMISSION)) {
+            sb.append('x');
+        } else {
+            sb.append('-');
+        }
+        return sb.toString();
+    }
 
     /**
-     * Returns the name of the group owning the file.  Sometimes this will be
-     * a string representation of the group number.
+     * Sets the name of the group owning the file. This may be a string representation of the group number.
      *
-     * @return The name of the group owning the file.
+     * @param group The name of the group owning the file.
      */
-    public String getGroup()
-    {
-        return group;
+    public void setGroup(final String group) {
+        this.group = group;
     }
 
-
     /**
-     * Set the name of the user owning the file.  This may be
-     * a string representation of the user number;
+     * Sets the number of hard links to this file. This is not to be confused with symbolic links.
      *
-     * @param user The name of the user owning the file.
+     * @param links The number of hard links to this file.
      */
-    public void setUser(final String user)
-    {
-        this.user = user;
+    public void setHardLinkCount(final int links) {
+        this.hardLinkCount = links;
     }
 
     /**
-     * Returns the name of the user owning the file.  Sometimes this will be
-     * a string representation of the user number.
+     * If the FTPFile is a symbolic link, use this method to set the name of the file being pointed to by the symbolic
+     * link.
      *
-     * @return The name of the user owning the file.
+     * @param link The file pointed to by the symbolic link.
      */
-    public String getUser()
-    {
-        return user;
+    public void setLink(final String link) {
+        this.link = link;
     }
 
-
     /**
-     * If the FTPFile is a symbolic link, use this method to set the name of the
-     * file being pointed to by the symbolic link.
+     * Sets the name of the file.
      *
-     * @param link  The file pointed to by the symbolic link.
+     * @param name The name of the file.
      */
-    public void setLink(final String link)
-    {
-        this.link = link;
+    public void setName(final String name) {
+        this.name = name;
     }
 
-
     /**
-     * If the FTPFile is a symbolic link, this method returns the name of the
-     * file being pointed to by the symbolic link.  Otherwise it returns null.
+     * Sets if the given access group (one of the <code> _ACCESS </code> constants) has the given access permission (one
+     * of the <code> _PERMISSION </code> constants) to the file.
      *
-     * @return The file pointed to by the symbolic link (null if the FTPFile
-     *         is not a symbolic link).
+     * @param access The access group (one of the <code> _ACCESS </code> constants)
+     * @param permission The access permission (one of the <code> _PERMISSION </code> constants)
+     * @param value True if permission is allowed, false if not.
+     * @throws ArrayIndexOutOfBoundsException if either of the parameters is out of range
      */
-    public String getLink()
-    {
-        return link;
+    public void setPermission(final int access, final int permission, final boolean value) {
+        permissions[access][permission] = value;
     }
 
-
     /**
-     * Set the file timestamp.  This usually the last modification time.
-     * The parameter is not cloned, so do not alter its value after calling
-     * this method.
+     * Sets the original FTP server raw listing from which the FTPFile was created.
      *
-     * @param date A Calendar instance representing the file timestamp.
+     * @param rawListing The raw FTP server listing.
      */
-    public void setTimestamp(final Calendar date)
-    {
-        this.date = date;
+    public void setRawListing(final String rawListing) {
+        this.rawListing = rawListing;
     }
 
-
     /**
-     * Returns the file timestamp.  This usually the last modification time.
+     * Sets the file size in bytes.
      *
-     * @return A Calendar instance representing the file timestamp.
+     * @param size The file size in bytes.
      */
-    public Calendar getTimestamp()
-    {
-        return date;
+    public void setSize(final long size) {
+        this.size = size;
     }
 
-
     /**
-     * Set if the given access group (one of the <code> _ACCESS </code>
-     * constants) has the given access permission (one of the
-     * <code> _PERMISSION </code> constants) to the file.
+     * Sets the file timestamp. This usually the last modification time. The parameter is not cloned, so do not alter its
+     * value after calling this method.
      *
-     * @param access The access group (one of the <code> _ACCESS </code>
-     *               constants)
-     * @param permission The access permission (one of the
-     *               <code> _PERMISSION </code> constants)
-     * @param value  True if permission is allowed, false if not.
-     * @throws ArrayIndexOutOfBoundsException if either of the parameters is out of range
+     * @param date A Calendar instance representing the file timestamp.
      */
-    public void setPermission(final int access, final int permission, final boolean value)
-    {
-        permissions[access][permission] = value;
+    public void setTimestamp(final Calendar date) {
+        this.date = date;
     }
 
-
     /**
-     * Determines if the given access group (one of the <code> _ACCESS </code>
-     * constants) has the given access permission (one of the
-     * <code> _PERMISSION </code> constants) to the file.
+     * Sets the type of the file (<code>DIRECTORY_TYPE</code>, <code>FILE_TYPE</code>, etc.).
      *
-     * @param access The access group (one of the <code> _ACCESS </code>
-     *               constants)
-     * @param permission The access permission (one of the
-     *               <code> _PERMISSION </code> constants)
-     * @throws ArrayIndexOutOfBoundsException if either of the parameters is out of range
-     * @return true if {@link #isValid()} is {@code true &&} the associated permission is set;
-     * {@code false} otherwise.
+     * @param type The integer code representing the type of the file.
      */
-    public boolean hasPermission(final int access, final int permission)
-    {
-        if (permissions == null) {
-            return false;
-        }
-        return permissions[access][permission];
+    public void setType(final int type) {
+        this.type = type;
     }
 
     /**
-     * Returns a string representation of the FTPFile information.
+     * Sets the name of the user owning the file. This may be a string representation of the user number;
      *
-     * @return A string representation of the FTPFile information.
+     * @param user The name of the user owning the file.
      */
-    @Override
-    public String toString()
-    {
-        return getRawListing();
+    public void setUser(final String user) {
+        this.user = user;
     }
 
     /**
-     * Returns a string representation of the FTPFile information.
-     * This currently mimics the Unix listing format.
-     * This method uses the timezone of the Calendar entry, which is
-     * the server time zone (if one was provided) otherwise it is
-     * the local time zone.
+     * Gets a string representation of the FTPFile information. This currently mimics the Unix listing format. This
+     * method uses the timezone of the Calendar entry, which is the server time zone (if one was provided) otherwise it
+     * is the local time zone.
      * <p>
-     * Note: if the instance is not valid {@link #isValid()}, no useful
-     * information can be returned. In this case, use {@link #getRawListing()}
-     * instead.
+     * Note: if the instance is not valid {@link #isValid()}, no useful information can be returned. In this case, use
+     * {@link #getRawListing()} instead.
+     * </p>
      *
      * @return A string representation of the FTPFile information.
      * @since 3.0
      */
-    public String toFormattedString()
-    {
+    public String toFormattedString() {
         return toFormattedString(null);
     }
 
     /**
-     * Returns a string representation of the FTPFile information.
-     * This currently mimics the Unix listing format.
-     * This method allows the Calendar time zone to be overridden.
+     * Gets a string representation of the FTPFile information. This currently mimics the Unix listing format. This
+     * method allows the Calendar time zone to be overridden.
      * <p>
-     * Note: if the instance is not valid {@link #isValid()}, no useful
-     * information can be returned. In this case, use {@link #getRawListing()}
-     * instead.
-     * @param timezone the timezone to use for displaying the time stamp
-     * If {@code null}, then use the Calendar entry timezone
+     * Note: if the instance is not valid {@link #isValid()}, no useful information can be returned. In this case, use
+     * {@link #getRawListing()} instead.
+     * </p>
+     *
+     * @param timezone the timezone to use for displaying the time stamp If {@code null}, then use the Calendar entry
+     *        timezone
      * @return A string representation of the FTPFile information.
      * @since 3.4
      */
-    public String toFormattedString(final String timezone)
-    {
+    public String toFormattedString(final String timezone) {
 
         if (!isValid()) {
             return "[Invalid: could not parse file entry]";
@@ -499,36 +452,13 @@ public class FTPFile implements Serializable
         return sb.toString();
     }
 
-    private char formatType(){
-        switch(type) {
-            case FILE_TYPE:
-                return '-';
-            case DIRECTORY_TYPE:
-                return 'd';
-            case SYMBOLIC_LINK_TYPE:
-                return 'l';
-            default:
-                return '?';
-        }
-    }
-
-    private String permissionToString(final int access ){
-        final StringBuilder sb = new StringBuilder();
-        if (hasPermission(access, READ_PERMISSION)) {
-            sb.append('r');
-        } else {
-            sb.append('-');
-        }
-        if (hasPermission(access, WRITE_PERMISSION)) {
-            sb.append('w');
-        } else {
-            sb.append('-');
-        }
-        if (hasPermission(access, EXECUTE_PERMISSION)) {
-            sb.append('x');
-        } else {
-            sb.append('-');
-        }
-        return sb.toString();
+    /**
+     * Gets a string representation of the FTPFile information.
+     *
+     * @return A string representation of the FTPFile information.
+     */
+    @Override
+    public String toString() {
+        return getRawListing();
     }
 }