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 700ec530d9ad0f9e7ee111deb492d44956203a91
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Oct 13 10:15:02 2024 -0400

    Sort members
---
 .../org/apache/commons/net/util/SubnetUtils.java   | 106 ++++++++++-----------
 .../org/apache/commons/net/SubnetUtilsTest.java    |  12 +--
 2 files changed, 58 insertions(+), 60 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 061a902f..5fec0aa1 100644
--- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java
+++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
@@ -29,6 +29,54 @@ import java.util.regex.Pattern;
  */
 public class SubnetUtils {
 
+    /**
+     * Allows an object to be the target of the "for-each loop" statement for 
a SubnetInfo.
+     *
+     * @since 3.12.0
+     */
+    public static class SubnetAddressIterable implements Iterable<String> {
+
+        private final SubnetInfo subnetInfo;
+
+        public SubnetAddressIterable(final SubnetInfo subnetInfo) {
+            this.subnetInfo = subnetInfo;
+        }
+
+        @Override
+        public Iterator<String> iterator() {
+            return new SubnetAddressIterator(subnetInfo);
+        }
+    }
+
+    /**
+     * Iterates over a SubnetInfo.
+     *
+     * @since 3.12.0
+     */
+    public static class SubnetAddressIterator implements Iterator<String> {
+
+        private final AtomicInteger currentAddress;
+
+        private final SubnetInfo subnetInfo;
+
+        public SubnetAddressIterator(final SubnetInfo subnetInfo) {
+            this.subnetInfo = subnetInfo;
+            currentAddress = new AtomicInteger(subnetInfo.low());
+        }
+
+        @Override
+        public boolean hasNext() {
+            return subnetInfo.getAddressCount() > 0 && currentAddress.get() <= 
subnetInfo.high();
+        }
+
+        @Override
+        public String next() {
+            String address = 
subnetInfo.format(subnetInfo.toArray(currentAddress.get()));
+            currentAddress.incrementAndGet();
+            return address;
+        }
+    }
+
     /**
      * Convenience container for subnet summary information.
      */
@@ -225,61 +273,11 @@ public class SubnetUtils {
         }
     }
 
-    /**
-     * Allows an object to be the target of the "for-each loop" statement for 
a SubnetInfo.
-     *
-     * @since 3.12.0
-     */
-    public static class SubnetAddressIterable implements Iterable<String> {
-
-        private final SubnetInfo subnetInfo;
-
-        public SubnetAddressIterable(final SubnetInfo subnetInfo) {
-            this.subnetInfo = subnetInfo;
-        }
-
-        @Override
-        public Iterator<String> iterator() {
-            return new SubnetAddressIterator(subnetInfo);
-        }
-    }
-
-    /**
-     * Iterates over a SubnetInfo.
-     *
-     * @since 3.12.0
-     */
-    public static class SubnetAddressIterator implements Iterator<String> {
-
-        private final SubnetInfo subnetInfo;
-
-        private final AtomicInteger currentAddress;
-
-        public SubnetAddressIterator(final SubnetInfo subnetInfo) {
-            this.subnetInfo = subnetInfo;
-            currentAddress = new AtomicInteger(subnetInfo.low());
-        }
-
-        @Override
-        public boolean hasNext() {
-            return subnetInfo.getAddressCount() > 0 && currentAddress.get() <= 
subnetInfo.high();
-        }
-
-        @Override
-        public String next() {
-            String address = 
subnetInfo.format(subnetInfo.toArray(currentAddress.get()));
-            currentAddress.incrementAndGet();
-            return address;
-        }
-    }
-
     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 ADDRESS_PATTERN = Pattern.compile(IP_ADDRESS);
     private static final Pattern CIDR_PATTERN = Pattern.compile(SLASH_FORMAT);
-
     private static final int NBITS = 32;
-
     private static final String PARSE_FAIL = "Could not parse [%s]";
 
     /*
@@ -315,17 +313,17 @@ public class SubnetUtils {
         throw new IllegalArgumentException(String.format(PARSE_FAIL, address));
     }
 
-    private final int netmask;
-
     private final int address;
 
-    private final int network;
-
     private final int broadcast;
 
     /** Whether the broadcast/network address are included in host count */
     private boolean inclusiveHostCount;
 
+    private final int netmask;
+
+    private final int network;
+
     /**
      * Constructs an instance from a CIDR-notation string, e.g. 
"192.168.0.1/16"
      *
diff --git a/src/test/java/org/apache/commons/net/SubnetUtilsTest.java 
b/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
index f1ed8000..d87ae7ae 100644
--- a/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
+++ b/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
@@ -410,6 +410,12 @@ public class SubnetUtilsTest {
         }
     }
 
+    @Test
+    public void testPrevious() {
+        final SubnetUtils utils = new SubnetUtils("192.168.0.1/29");
+        assertEquals("192.168.0.0", 
utils.getPrevious().getInfo().getAddress());
+    }
+
     @Test
     public void testSubnetAddressIterable() {
         SubnetUtils utils = new SubnetUtils("192.168.1.0/24");
@@ -425,12 +431,6 @@ public class SubnetUtilsTest {
         assertFalse(addressList.contains("192.168.1.255"));
     }
 
-    @Test
-    public void testPrevious() {
-        final SubnetUtils utils = new SubnetUtils("192.168.0.1/29");
-        assertEquals("192.168.0.0", 
utils.getPrevious().getInfo().getAddress());
-    }
-
     @Test
     public void testToString() {
         final SubnetUtils utils = new SubnetUtils("192.168.0.1/29");

Reply via email to