IPAddress implements Range<IPAddress> { @Value.Lazy public boolean greaterOrEqualsTo(IPAddress candidate) { return Optional.ofNullable(candidate) .map(IPAddress::value) .map(ip -> { long ipLong = (long) this.toInteger(ip) & 4294967295L; long valueLong = (long) this.toInteger(value()) & 4294967295L; return valueLong >= ipLong; }) .orElse(Boolean.FALSE); }  @Value.Parameter abstract String value(); @Override boolean isInRange(IPAddress candidate); @Value.Lazy boolean greaterOrEqualsTo(IPAddress candidate); @Value.Lazy boolean lessOrEqualsTo(IPAddress candidate);  }
@Test public void greater_than() throws Exception { assertThat(ImmutableIPAddress.of("127.0.0.1").greaterOrEqualsTo(ImmutableIPAddress.of("127.0.0.1"))).isTrue(); assertThat(ImmutableIPAddress.of("127.0.0.1").greaterOrEqualsTo(ImmutableIPAddress.of("127.0.0.0"))).isTrue(); assertThat(ImmutableIPAddress.of("127.0.0.1").greaterOrEqualsTo(ImmutableIPAddress.of("127.0.0.2"))).isFalse(); }