Ports implements Range<Port> { @Override public boolean isInRange(Port candidate) { return Optional.ofNullable(candidate) .map(Port::value) .map(port -> values().stream() .map(Port::value) .filter(port::equals) .findFirst() .map(p -> Boolean.TRUE) .orElse(Boolean.FALSE)) .orElse(Boolean.FALSE); }  @Value.Parameter abstract List<Port> values(); @Override boolean isInRange(Port candidate);  }
@Test public void in_range() throws Exception { final Range<Port> range = ImmutablePorts.builder() .addValue(ImmutablePort.of(8000)) .addValue(ImmutablePort.of(8001)) .build(); Assertions.assertThat(range.isInRange(ImmutablePort.of(8000))).isTrue(); Assertions.assertThat(range.isInRange(ImmutablePort.of(8001))).isTrue(); Assertions.assertThat(range.isInRange(ImmutablePort.of(9000))).isFalse(); }