/** * Returns whether the given {@link PrefixSpace} has any {@link Prefix}es in common with this one. * * @param intersectSpace {@link PrefixSpace} in which to check for overlap * @return {@code true} if the given {@link PrefixSpace} has any {@link Prefix}es in common with * this one */ public boolean overlaps(PrefixSpace intersectSpace) { PrefixSpace intersection = intersection(intersectSpace); return !intersection.isEmpty(); }
PrefixSpace intersection = space1.intersection(space2); answerElement.addIntersection(node1, node2, intersection);
@Test public void intersectionAndOverlapsTest() { PrefixSpace other = new PrefixSpace(); assertThat("empty spaces don't intersect", _ps.intersection(other).isEmpty(), equalTo(true)); assertThat("no overlap for empty spaces", _ps.overlaps(other), equalTo(false)); _ps.addPrefixRange(PrefixRange.fromString("10.10.10.0/20:18-21")); assertThat("no intersection for one empty", _ps.intersection(other).isEmpty(), equalTo(true)); assertThat("no overlap for one empty", _ps.overlaps(other), equalTo(false)); other.addPrefixRange(PrefixRange.fromString("10.10.10.0/16:14-16")); assertThat("no intersection", _ps.intersection(other).isEmpty(), equalTo(true)); assertThat("no overlap", _ps.overlaps(other), equalTo(false)); other.addPrefixRange(PrefixRange.fromString("10.10.10.0/20:18-20")); PrefixSpace intersection = _ps.intersection(other); assertThat( "now intersect for length 18", intersection.containsPrefix(Prefix.parse("10.10.0.0/18")), equalTo(true)); assertThat( "now intersect for length 19", intersection.containsPrefix(Prefix.parse("10.10.0.0/19")), equalTo(true)); assertThat( "now intersect for range 18-20", intersection.containsPrefixRange(PrefixRange.fromString("10.10.0.0/20:18-20")), equalTo(true)); assertThat("don't intersect anywhere else", intersection.getPrefixRanges().size(), equalTo(3)); assertThat("has overlap", _ps.overlaps(other), equalTo(true)); }