IPRange implements Range<IPAddress> { @Override public boolean isInRange(IPAddress candidate) { return Optional.ofNullable(candidate) .map(ip -> from().lessOrEqualsTo(candidate) && to().greaterOrEqualsTo(candidate)) .orElse(Boolean.FALSE); }  @Override boolean isInRange(IPAddress candidate);  }
@Test public void isInRange() throws Exception { final IPRange IPRange = ImmutableIPRange.builder() .from(ImmutableIPAddress.of("127.0.0.1")) .to(ImmutableIPAddress.of("127.0.0.3")) .build(); Assertions.assertThat(IPRange.isInRange(ImmutableIPAddress.of("127.0.0.1"))).isTrue(); Assertions.assertThat(IPRange.isInRange(ImmutableIPAddress.of("127.0.0.2"))).isTrue(); Assertions.assertThat(IPRange.isInRange(ImmutableIPAddress.of("127.0.0.3"))).isTrue(); Assertions.assertThat(IPRange.isInRange(ImmutableIPAddress.of("127.0.0.0"))).isFalse(); }