Skip to content

Commit

Permalink
Rename difference -> minus
Browse files Browse the repository at this point in the history
  • Loading branch information
ties committed Nov 28, 2022
1 parent c6420ae commit 98a3845
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/main/java/net/ripe/ipresource/ImmutableResourceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public ImmutableResourceSet remove(IpResource value) {
return new Builder(this).remove(value).build();
}

/**
* @return $this \cup that$
*/
public ImmutableResourceSet union(ImmutableResourceSet that) {
if (this.isEmpty()) {
return that;
Expand All @@ -145,6 +148,9 @@ public ImmutableResourceSet union(ImmutableResourceSet that) {
}
}

/**
* @return $this \cap that$
*/
public ImmutableResourceSet intersection(ImmutableResourceSet that) {
if (this.isEmpty()) {
return this;
Expand Down Expand Up @@ -173,7 +179,15 @@ public ImmutableResourceSet intersection(ImmutableResourceSet that) {
}
}

@Deprecated
public ImmutableResourceSet difference(ImmutableResourceSet that) {
return this.minus(that);
}

/**
* @return $this \setminus that$
*/
public ImmutableResourceSet minus(ImmutableResourceSet that) {
if (!this.intersects(that)) {
return this;
} else {
Expand Down
13 changes: 10 additions & 3 deletions src/test/java/net/ripe/ipresource/ImmutableResourceSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ public void test_difference() {
assertEquals(ImmutableResourceSet.parse("AS3333-AS3334, AS3336-AS4444, 10.0.0.0-10.4.255.255, 10.6.0.0-10.255.255.255"), difference);
}

@Test
public void test_minus() {
ImmutableResourceSet a = ImmutableResourceSet.parse("AS3333-AS4444,10.0.0.0/8");
ImmutableResourceSet difference = a.minus(ImmutableResourceSet.parse("10.5.0.0/16, AS3335"));
assertEquals(ImmutableResourceSet.parse("AS3333-AS3334, AS3336-AS4444, 10.0.0.0-10.4.255.255, 10.6.0.0-10.255.255.255"), difference);
}

@Test
public void test_intersection() {
ImmutableResourceSet empty = ImmutableResourceSet.parse("");
Expand Down Expand Up @@ -335,9 +342,9 @@ public void difference_laws() {
ImmutableResourceSet b = randomSet(i);
ImmutableResourceSet c = randomSet(i);

assertEquals(c.difference(a.intersection(b)), (c.difference(a)).union(c.difference(b)));
assertEquals(c.difference(a.union(b)), (c.difference(a)).intersection(c.difference(b)));
assertEquals(c.difference(b.difference(a)), (a.intersection(c)).union(c.difference(b)));
assertEquals(c.minus(a.intersection(b)), (c.minus(a)).union(c.minus(b)));
assertEquals(c.minus(a.union(b)), (c.minus(a)).intersection(c.minus(b)));
assertEquals(c.minus(b.minus(a)), (a.intersection(c)).union(c.minus(b)));
}

}
Expand Down

0 comments on commit 98a3845

Please sign in to comment.