@Override public Boolean visitIpWildcardIpSpace(IpWildcardIpSpace ipWildcardIpSpace) { return _ipWildcard.intersects(ipWildcardIpSpace.getIpWildcard()); }
@Override protected boolean matchesSafely(IpWildcard ipWildcard, Description mismatchDescription) { boolean matches = ipWildcard.intersects(_ipWildcard); if (!matches) { mismatchDescription.appendText(String.format("was %s", ipWildcard)); } return matches; }
@Override public Boolean visitPrefixIpSpace(PrefixIpSpace prefixIpSpace) { return new IpWildcard(prefixIpSpace.getPrefix()).intersects(_ipWildcard); }
@Test public void testNotIntersects() { /* * Since the significant regions of wc1 and wc2 overlap and are not equal, there is no * intersection between them. */ IpWildcard wc1 = new IpWildcard(Ip.create(0x00000F00L), Ip.create(0x0000FF00L).inverted()); IpWildcard wc2 = new IpWildcard(Ip.create(0x0000F000L), Ip.create(0x0000FF00L).inverted()); assertThat("wildcards should not overlap", !wc1.intersects(wc2)); }
@Test public void testIntersects() { /* * The second Ip of an IpWildcard indicates which bits of the first Ip * are significant (i.e. not wild). In this example, since the significant bits of * wc1 and wc2 don't overlap, they should intersect (i.e. their bitwise OR is included in each). */ IpWildcard wc1 = new IpWildcard(Ip.create(0x00b0000aL), Ip.create(0x00FF00FFL).inverted()); IpWildcard wc2 = new IpWildcard(Ip.create(0x000cd000L), Ip.create(0x0000FF00L).inverted()); assertThat("wildcards should overlap", wc1.intersects(wc2)); }