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 2022/11/06 13:06:09 UTC

[commons-net] branch master updated (fd1038d4 -> 69fa36b4)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


    from fd1038d4 Format tweaks
     new 8ee675ec Better SubnetUtils.SubnetInfo.format(int[])
     new d7698b92 Javadoc and format tweaks
     new d6fcef93 private static final names should be upper case
     new 69fa36b4 Format tweak

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/commons/net/util/SubnetUtils.java   | 119 +++++++++++----------
 .../apache/commons/net/util/TrustManagerUtils.java |  19 ++--
 2 files changed, 68 insertions(+), 70 deletions(-)


[commons-net] 04/04: Format tweak

Posted by gg...@apache.org.
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 69fa36b42c88ab272499bcaa8b61295388547316
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 08:05:02 2022 -0500

    Format tweak
---
 .../apache/commons/net/util/TrustManagerUtils.java    | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/util/TrustManagerUtils.java b/src/main/java/org/apache/commons/net/util/TrustManagerUtils.java
index 058b6d30..7ae108e8 100644
--- a/src/main/java/org/apache/commons/net/util/TrustManagerUtils.java
+++ b/src/main/java/org/apache/commons/net/util/TrustManagerUtils.java
@@ -30,8 +30,8 @@ import javax.net.ssl.X509TrustManager;
  *
  * @since 3.0
  */
-public final class TrustManagerUtils
-{
+public final class TrustManagerUtils {
+
     private static class TrustManager implements X509TrustManager {
 
         private final boolean checkServerValidity;
@@ -44,17 +44,13 @@ public final class TrustManagerUtils
          * Never generates a CertificateException.
          */
         @Override
-        public void checkClientTrusted(final X509Certificate[] certificates, final String authType)
-        {
+        public void checkClientTrusted(final X509Certificate[] certificates, final String authType) {
         }
 
         @Override
-        public void checkServerTrusted(final X509Certificate[] certificates, final String authType)
-            throws CertificateException
-        {
+        public void checkServerTrusted(final X509Certificate[] certificates, final String authType) throws CertificateException {
             if (checkServerValidity) {
-                for (final X509Certificate certificate : certificates)
-                {
+                for (final X509Certificate certificate : certificates) {
                     certificate.checkValidity();
                 }
             }
@@ -64,8 +60,7 @@ public final class TrustManagerUtils
          * @return an empty array of certificates
          */
         @Override
-        public X509Certificate[] getAcceptedIssuers()
-        {
+        public X509Certificate[] getAcceptedIssuers() {
             return NetConstants.EMPTY_X509_CERTIFICATE_ARRAY;
         }
     }
@@ -79,7 +74,7 @@ public final class TrustManagerUtils
      *
      * @return the TrustManager
      */
-    public static X509TrustManager getAcceptAllTrustManager(){
+    public static X509TrustManager getAcceptAllTrustManager() {
         return ACCEPT_ALL;
     }
 


[commons-net] 01/04: Better SubnetUtils.SubnetInfo.format(int[])

Posted by gg...@apache.org.
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 8ee675ec635944438b95cd02257507e8d206a125
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 07:49:55 2022 -0500

    Better SubnetUtils.SubnetInfo.format(int[])
---
 src/main/java/org/apache/commons/net/util/SubnetUtils.java | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/util/SubnetUtils.java b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
index 88bbe83c..5f84bf44 100644
--- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java
+++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
@@ -45,14 +45,15 @@ public class SubnetUtils {
         * Convert a 4-element array into dotted decimal format
         */
         private String format(final int[] octets) {
-            final StringBuilder str = new StringBuilder();
-            for (int i =0; i < octets.length; ++i){
-                str.append(octets[i]);
-                if (i != octets.length - 1) {
-                    str.append(".");
+            final int last = octets.length - 1;
+            final StringBuilder builder = new StringBuilder();
+            for (int i = 0;; i++) {
+                builder.append(octets[i]);
+                if (i == last) {
+                    return builder.toString();
                 }
+                builder.append('.');
             }
-            return str.toString();
         }
 
         public String getAddress() {


[commons-net] 03/04: private static final names should be upper case

Posted by gg...@apache.org.
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 d6fcef93b5c643b3fd230f9bfdfedd3448f94e22
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 07:58:04 2022 -0500

    private static final names should be upper case
    
    Format tweaks
---
 .../org/apache/commons/net/util/SubnetUtils.java   | 66 +++++++++++-----------
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/util/SubnetUtils.java b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
index 96bcc19a..e4c78d47 100644
--- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java
+++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
@@ -75,7 +75,7 @@ public class SubnetUtils {
                 throw new RuntimeException("Count is larger than an integer: " + countLong);
             }
             // N.B. cannot be negative
-            return (int)countLong;
+            return (int) countLong;
         }
 
         /**
@@ -194,13 +194,13 @@ public class SubnetUtils {
        /**
         * Converts a packed integer address into a 4-element array
         */
-        private int[] toArray(final int val) {
-            final int ret[] = new int[4];
-            for (int j = 3; j >= 0; --j) {
-                ret[j] |= val >>> 8*(3-j) & 0xff;
-            }
-            return ret;
-        }
+       private int[] toArray(final int val) {
+           final int ret[] = new int[4];
+           for (int j = 3; j >= 0; --j) {
+               ret[j] |= val >>> 8 * (3 - j) & 0xff;
+           }
+           return ret;
+       }
 
         /**
          * {@inheritDoc}
@@ -223,8 +223,8 @@ public class SubnetUtils {
     }
     private static final String IP_ADDRESS = "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})";
     private static final String SLASH_FORMAT = IP_ADDRESS + "/(\\d{1,2})"; // 0 -> 32
-    private static final Pattern addressPattern = Pattern.compile(IP_ADDRESS);
-    private static final Pattern cidrPattern = Pattern.compile(SLASH_FORMAT);
+    private static final Pattern ADDRESS_PATTERN = Pattern.compile(IP_ADDRESS);
+    private static final Pattern CIDR_PATTERN = Pattern.compile(SLASH_FORMAT);
 
     private static final int NBITS = 32;
 
@@ -238,7 +238,7 @@ public class SubnetUtils {
         int addr = 0;
         for (int i = 1; i <= 4; ++i) {
             final int n = rangeCheck(Integer.parseInt(matcher.group(i)), 0, 255);
-            addr |= (n & 0xff) << 8*(4-i);
+            addr |= (n & 0xff) << 8 * (4 - i);
         }
         return addr;
     }
@@ -252,14 +252,14 @@ public class SubnetUtils {
             return value;
         }
 
-        throw new IllegalArgumentException("Value [" + value + "] not in range ["+begin+","+end+"]");
+        throw new IllegalArgumentException("Value [" + value + "] not in range [" + begin + "," + end + "]");
     }
 
     /*
      * Converts a dotted decimal format address to a packed integer format
      */
     private static int toInteger(final String address) {
-        final Matcher matcher = addressPattern.matcher(address);
+        final Matcher matcher = ADDRESS_PATTERN.matcher(address);
         if (matcher.matches()) {
             return matchAddress(matcher);
         }
@@ -284,32 +284,32 @@ public class SubnetUtils {
      * i.e. does not match n.n.n.n/m where n=1-3 decimal digits, m = 1-2 decimal digits in range 0-32
      */
     public SubnetUtils(final String cidrNotation) {
-      final Matcher matcher = cidrPattern.matcher(cidrNotation);
+        final Matcher matcher = CIDR_PATTERN.matcher(cidrNotation);
 
-      if (!matcher.matches()) {
-          throw new IllegalArgumentException(String.format(PARSE_FAIL, cidrNotation));
-      }
-      this.address = matchAddress(matcher);
+        if (!matcher.matches()) {
+            throw new IllegalArgumentException(String.format(PARSE_FAIL, cidrNotation));
+        }
+        this.address = matchAddress(matcher);
 
-      // Create a binary netmask from the number of bits specification /x
+        // Create a binary netmask from the number of bits specification /x
 
-      final int trailingZeroes = NBITS - rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
+        final int trailingZeroes = NBITS - rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
 
-      //
-      // An IPv4 netmask consists of 32 bits, a contiguous sequence
-      // of the specified number of ones followed by all zeros.
-      // So, it can be obtained by shifting an unsigned integer (32 bits) to the left by
-      // the number of trailing zeros which is (32 - the # bits specification).
-      // Note that there is no unsigned left shift operator, so we have to use
-      // a long to ensure that the left-most bit is shifted out correctly.
-      //
-      this.netmask = (int) (0x0FFFFFFFFL << trailingZeroes );
+        //
+        // An IPv4 netmask consists of 32 bits, a contiguous sequence
+        // of the specified number of ones followed by all zeros.
+        // So, it can be obtained by shifting an unsigned integer (32 bits) to the left by
+        // the number of trailing zeros which is (32 - the # bits specification).
+        // Note that there is no unsigned left shift operator, so we have to use
+        // a long to ensure that the left-most bit is shifted out correctly.
+        //
+        this.netmask = (int) (0x0FFFFFFFFL << trailingZeroes);
 
-      // Calculate base network address
-      this.network = address & netmask;
+        // Calculate base network address
+        this.network = address & netmask;
 
-      // Calculate broadcast address
-      this.broadcast = network | ~netmask;
+        // Calculate broadcast address
+        this.broadcast = network | ~netmask;
     }
 
     /**


[commons-net] 02/04: Javadoc and format tweaks

Posted by gg...@apache.org.
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 d7698b92cddc341f64df6f07fb3b13ae7e91711f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 07:52:49 2022 -0500

    Javadoc and format tweaks
---
 .../org/apache/commons/net/util/SubnetUtils.java   | 40 ++++++++++++----------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/util/SubnetUtils.java b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
index 5f84bf44..96bcc19a 100644
--- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java
+++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
@@ -20,7 +20,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
- * A class that performs some subnet calculations given a network address and a subnet mask.
+ * Performs some subnet calculations given a network address and a subnet mask.
  * @see "http://www.faqs.org/rfcs/rfc1519.html"
  * @since 2.0
  */
@@ -31,6 +31,7 @@ public class SubnetUtils {
      *
      */
     public final class SubnetInfo {
+
         /* Mask to convert unsigned int to a long (i.e. keep 32 bits) */
         private static final long UNSIGNED_INT_MASK = 0x0FFFFFFFFL;
 
@@ -42,7 +43,7 @@ public class SubnetUtils {
         private long broadcastLong(){ return broadcast &  UNSIGNED_INT_MASK; }
 
         /*
-        * Convert a 4-element array into dotted decimal format
+        * Converts a 4-element array into dotted decimal format
         */
         private String format(final int[] octets) {
             final int last = octets.length - 1;
@@ -61,7 +62,7 @@ public class SubnetUtils {
         }
 
         /**
-         * Get the count of available addresses.
+         * Gets the count of available addresses.
          * Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
          * @return the count of addresses, may be zero.
          * @throws RuntimeException if the correct count is greater than {@code Integer.MAX_VALUE}
@@ -78,7 +79,7 @@ public class SubnetUtils {
         }
 
         /**
-         * Get the count of available addresses.
+         * Gets the count of available addresses.
          * Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
          * @return the count of addresses, may be zero.
          * @since 3.4
@@ -111,7 +112,7 @@ public class SubnetUtils {
         }
 
         /**
-         * Return the high address as a dotted IP address.
+         * Gets the high address as a dotted IP address.
          * Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
          *
          * @return the IP address in dotted format, may be "0.0.0.0" if there is no valid address
@@ -121,7 +122,7 @@ public class SubnetUtils {
         }
 
         /**
-         * Return the low address as a dotted IP address.
+         * Gets the low address as a dotted IP address.
          * Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
          *
          * @return the IP address in dotted format, may be "0.0.0.0" if there is no valid address
@@ -152,7 +153,7 @@ public class SubnetUtils {
         }
 
         /**
-         * Returns true if the parameter <code>address</code> is in the
+         * Tests if the parameter <code>address</code> is in the
          * range of usable endpoint addresses for this subnet. This excludes the
          * network and broadcast addresses by default. Use {@link SubnetUtils#setInclusiveHostCount(boolean)}
          * to change this.
@@ -171,7 +172,7 @@ public class SubnetUtils {
         }
 
         /**
-         * Returns true if the parameter <code>address</code> is in the
+         * Tests if the parameter <code>address</code> is in the
          * range of usable endpoint addresses for this subnet. This excludes the
          * network and broadcast addresses. Use {@link SubnetUtils#setInclusiveHostCount(boolean)}
          * to change this.
@@ -190,8 +191,8 @@ public class SubnetUtils {
         // long versions of the values (as unsigned int) which are more suitable for range checking
         private long networkLong()  { return network &  UNSIGNED_INT_MASK; }
 
-        /*
-        * Convert a packed integer address into a 4-element array
+       /**
+        * Converts a packed integer address into a 4-element array
         */
         private int[] toArray(final int val) {
             final int ret[] = new int[4];
@@ -228,8 +229,9 @@ public class SubnetUtils {
     private static final int NBITS = 32;
 
     private static final String PARSE_FAIL = "Could not parse [%s]";
+
     /*
-     * Convenience method to extract the components of a dotted decimal address and
+     * Extracts the components of a dotted decimal address and
      * pack into an integer using a regex match
      */
     private static int matchAddress(final Matcher matcher) {
@@ -241,7 +243,7 @@ public class SubnetUtils {
         return addr;
     }
     /*
-     * Convenience function to check integer boundaries.
+     * Checks integer boundaries.
      * Checks if a value x is in the range [begin,end].
      * Returns x if it is in range, throws an exception otherwise.
      */
@@ -254,7 +256,7 @@ public class SubnetUtils {
     }
 
     /*
-     * Convert a dotted decimal format address to a packed integer format
+     * Converts a dotted decimal format address to a packed integer format
      */
     private static int toInteger(final String address) {
         final Matcher matcher = addressPattern.matcher(address);
@@ -276,7 +278,7 @@ public class SubnetUtils {
     private boolean inclusiveHostCount;
 
     /**
-     * Constructor that takes a CIDR-notation string, e.g. "192.168.0.1/16"
+     * Constructs an instance from a CIDR-notation string, e.g. "192.168.0.1/16"
      * @param cidrNotation A CIDR-notation string, e.g. "192.168.0.1/16"
      * @throws IllegalArgumentException if the parameter is invalid,
      * i.e. does not match n.n.n.n/m where n=1-3 decimal digits, m = 1-2 decimal digits in range 0-32
@@ -311,7 +313,7 @@ public class SubnetUtils {
     }
 
     /**
-     * Constructor that takes a dotted decimal address and a dotted decimal mask.
+     * Constructs an instance from a dotted decimal address and a dotted decimal mask.
      * @param address An IP address, e.g. "192.168.0.1"
      * @param mask A dotted decimal netmask e.g. "255.255.0.0"
      * @throws IllegalArgumentException if the address or mask is invalid,
@@ -333,7 +335,7 @@ public class SubnetUtils {
     }
 
     /**
-     * Return a {@link SubnetInfo} instance that contains subnet-specific statistics
+     * Gets a {@link SubnetInfo} instance that contains subnet-specific statistics
      * @return new instance
      */
     public final SubnetInfo getInfo() { return new SubnetInfo(); }
@@ -347,7 +349,7 @@ public class SubnetUtils {
     }
 
     /**
-     * Returns <code>true</code> if the return value of {@link SubnetInfo#getAddressCount()}
+     * Tests if the return value of {@link SubnetInfo#getAddressCount()}
      * includes the network and broadcast addresses.
      * @since 2.2
      * @return true if the host count includes the network and broadcast addresses
@@ -357,7 +359,7 @@ public class SubnetUtils {
     }
 
     /*
-     * Count the number of 1-bits in a 32-bit integer using a divide-and-conquer strategy
+     * Counts the number of 1-bits in a 32-bit integer using a divide-and-conquer strategy
      * see Hacker's Delight section 5.1
      */
     int pop(int x) {
@@ -370,7 +372,7 @@ public class SubnetUtils {
     }
 
     /**
-     * Set to <code>true</code> if you want the return value of {@link SubnetInfo#getAddressCount()}
+     * Sets to <code>true</code> if you want the return value of {@link SubnetInfo#getAddressCount()}
      * to include the network and broadcast addresses.
      * This also applies to {@link SubnetInfo#isInRange(int)}
      * @param inclusiveHostCount true if network and broadcast addresses are to be included