Skip to content

Commit

Permalink
Add symmetricDifference to ImmutableResourceSet
Browse files Browse the repository at this point in the history
  • Loading branch information
ties committed Nov 28, 2022
1 parent 98a3845 commit 81b98cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/net/ripe/ipresource/ImmutableResourceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ public ImmutableResourceSet minus(ImmutableResourceSet that) {
}
}

/**
* @return $this \Delta that$
*/
public ImmutableResourceSet symmetricDifference(ImmutableResourceSet that) {
// $this \Delta that = (this \setminus that) \cup (that \setminus this)$
return (this.minus(that)).union((that.minus(this)));
}

public ImmutableResourceSet complement() {
return universal().difference(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ public void test_minus() {
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_symmetricDifference() {
ImmutableResourceSet a = ImmutableResourceSet.parse("AS64512-AS64513");
ImmutableResourceSet b = ImmutableResourceSet.parse("AS64513-AS64514");
ImmutableResourceSet symDiff = a.symmetricDifference(b);
assertEquals(ImmutableResourceSet.parse("AS64512, AS64514"), symDiff);
}

@Test
public void test_intersection() {
ImmutableResourceSet empty = ImmutableResourceSet.parse("");
Expand Down

0 comments on commit 81b98cd

Please sign in to comment.