@SafeVarargs public static <T> Stream<T> ofNullables(T... array) { return ofNullable(array); }
@SafeVarargs public static <T> Stream<T> ofNullables(T... array) { return ofNullable(array); }
static Stream<String> toAddressContents(String[] headers) { return StreamUtils.ofNullable(headers) .map(Throwing.function(string -> InternetAddress.parseHeader(string, !STRICT_PARSING))) .flatMap(AddressHelper::asStringStream); }
private Stream<URL> recursiveExpand(File file) { return StreamUtils.ofNullable(file.listFiles()) .flatMap(Throwing.function(this::expandFile).sneakyThrow()); }
public static DomainListConfiguration from(HierarchicalConfiguration config) { ImmutableList<Domain> configuredDomains = StreamUtils.ofNullable(config.getStringArray(CONFIGURE_DOMAIN_NAMES)) .filter(s -> !s.isEmpty()) .map(Domain::of) .collect(Guavate.toImmutableList()); return builder() .autoDetect(Optional.ofNullable(config.getBoolean(CONFIGURE_AUTODETECT, null))) .autoDetectIp(Optional.ofNullable(config.getBoolean(CONFIGURE_AUTODETECT_IP, null))) .defaultDomain(Optional.ofNullable(config.getString(CONFIGURE_DEFAULT_DOMAIN, null)) .map(Domain::of)) .addConfiguredDomains(configuredDomains) .build(); }
@Test void ofNullableShouldReturnEmptyStreamWhenNull() { assertThat(StreamUtils.ofNullable(null) .collect(Guavate.toImmutableList())) .isEmpty(); }
@Test public void ofNullableShouldReturnEmptyStreamWhenNull() { assertThat(StreamUtils.ofNullable(null) .collect(Guavate.toImmutableList())) .isEmpty(); }
@Test void ofNullableShouldReturnAStreamWithElementsOfTheArray() { assertThat(StreamUtils.ofNullable(ImmutableList.of(1, 2).toArray()) .collect(Guavate.toImmutableList())) .containsExactly(1, 2); } }
@Test public void ofNullableShouldReturnAStreamWithElementsOfTheArray() { assertThat(StreamUtils.ofNullable(ImmutableList.of(1, 2).toArray()) .collect(Guavate.toImmutableList())) .containsExactly(1, 2); } }