diff --git a/src/main/java/net/ripe/ipresource/ImmutableResourceSet.java b/src/main/java/net/ripe/ipresource/ImmutableResourceSet.java index 63584dc..a050f34 100644 --- a/src/main/java/net/ripe/ipresource/ImmutableResourceSet.java +++ b/src/main/java/net/ripe/ipresource/ImmutableResourceSet.java @@ -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); } diff --git a/src/test/java/net/ripe/ipresource/ImmutableResourceSetTest.java b/src/test/java/net/ripe/ipresource/ImmutableResourceSetTest.java index bb93816..a953578 100644 --- a/src/test/java/net/ripe/ipresource/ImmutableResourceSetTest.java +++ b/src/test/java/net/ripe/ipresource/ImmutableResourceSetTest.java @@ -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("");