Skip to content

Commit

Permalink
Simplify implementation
Browse files Browse the repository at this point in the history
Impl does not need an atomic integer
  • Loading branch information
garydgregory committed Oct 13, 2024
1 parent faab320 commit b329264
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main/java/org/apache/commons/net/util/SubnetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.commons.net.util;

import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -60,7 +59,7 @@ public Iterator<String> iterator() {
*/
public static class SubnetAddressIterator implements Iterator<String> {

private final AtomicInteger currentAddress;
private int currentAddress;

private final SubnetInfo subnetInfo;

Expand All @@ -71,18 +70,18 @@ public static class SubnetAddressIterator implements Iterator<String> {
*/
public SubnetAddressIterator(final SubnetInfo subnetInfo) {
this.subnetInfo = subnetInfo;
currentAddress = new AtomicInteger(subnetInfo.low());
currentAddress = subnetInfo.low();
}

@Override
public boolean hasNext() {
return subnetInfo.getAddressCount() > 0 && currentAddress.get() <= subnetInfo.high();
return subnetInfo.getAddressCountLong() > 0 && currentAddress <= subnetInfo.high();
}

@Override
public String next() {
final String address = subnetInfo.format(subnetInfo.toArray(currentAddress.get()));
currentAddress.incrementAndGet();
final String address = subnetInfo.format(subnetInfo.toArray(currentAddress));
currentAddress++;
return address;
}
}
Expand Down

0 comments on commit b329264

Please sign in to comment.