Skip to content

Commit

Permalink
withRemoved bugfix, tests, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
maltalex committed Aug 19, 2023
1 parent 6187c20 commit bc2ecc9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'signing'

group = 'com.github.maltalex'
archivesBaseName = 'ineter'
version = '0.3.0'
version = '0.3.1'

task javadocJar(type: Jar) {
classifier = 'javadoc'
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/maltalex/ineter/range/IPv4Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public List<IPv4Range> withRemoved(Collection<IPv4Range> ranges) {
List<IPv4Range> merged = IPv4Range.merge(ranges);
ret.add(this);
for (IPv4Range toRemove : merged) {
if (ret.isEmpty()) {
break;
}
IPv4Range next = ret.remove(ret.size() - 1);
// a bit faster than calling withRemoved() one range at a time
if (toRemove.getFirst().compareTo(next.getFirst()) > 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/maltalex/ineter/range/IPv6Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public List<IPv6Range> withRemoved(Collection<IPv6Range> ranges) {
List<IPv6Range> merged = IPv6Range.merge(ranges);
ret.add(this);
for (IPv6Range toRemove : merged) {
if (ret.isEmpty()) {
break;
}
IPv6Range next = ret.remove(ret.size() - 1);
// a bit faster than calling withRemoved() one range at a time
if (toRemove.getFirst().compareTo(next.getFirst()) > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ void withRemovedCollectionEmpty() {
IPv4Range.parse("10.0.0.0/24").withRemoved(Arrays.asList(IPv4Range.parse("10.0.0.0/24"))));
assertEquals(emptyList(),
IPv4Range.parse("10.0.0.0/24").withRemoved(Arrays.asList(IPv4Range.parse("0.0.0.0/0"))));
assertEquals(emptyList(),
IPv4Range.parse("10.0.0.0/24").withRemoved(Arrays.asList(IPv4Range.parse("9.0.0.0-11.0.0.0"))));
assertEquals(emptyList(), IPv4Range.parse("10.0.0.0/24")
.withRemoved(Arrays.asList(IPv4Range.parse("9.0.0.0-11.0.0.0"), IPv4Range.parse("13.0.0.0/24"))));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ void withRemovedCollectionEmpty() {
assertEquals(emptyList(),
IPv6Range.parse("1234::/16").withRemoved(Arrays.asList(IPv6Range.parse("1234::/16"))));
assertEquals(emptyList(), IPv6Range.parse("1234::/16").withRemoved(Arrays.asList(IPv6Range.parse("::/0"))));
assertEquals(emptyList(),
IPv6Range.parse("1234::/16").withRemoved(Arrays.asList(IPv6Range.parse("1230::-1240::"))));
assertEquals(emptyList(), IPv6Range.parse("1234::/16")
.withRemoved(Arrays.asList(IPv6Range.parse("1230::-1240::"), IPv6Range.parse("2222::0/16"))));
}

@ParameterizedTest
Expand Down

0 comments on commit bc2ecc9

Please sign in to comment.