public static <T> Stream<T> flatten(Collection<Stream<T>> streams) { return flatten(streams.stream()); }
@SafeVarargs public static <T> Stream<T> ofNullables(T... array) { return ofNullable(array); }
public static <T> Stream<T> ofNullable(T[] array) { return ofOptional(Optional.ofNullable(array)); }
public static <T> Stream<T> flatten(Collection<Stream<T>> streams) { return flatten(streams.stream()); }
@SafeVarargs public static <T> Stream<T> ofNullables(T... array) { return ofNullable(array); }
public static <T> Stream<T> ofNullable(T[] array) { return ofOptional(Optional.ofNullable(array)); }
public static <T> Stream<T> flatten(Collection<Stream<T>> streams) { return flatten(streams.stream()); }
static Stream<String> toAddressContents(String[] headers) { return StreamUtils.ofNullable(headers) .map(Throwing.function(string -> InternetAddress.parseHeader(string, !STRICT_PARSING))) .flatMap(AddressHelper::asStringStream); }
public static <T> Stream<T> ofNullable(T[] array) { return ofOptional(Optional.ofNullable(array)); }
@SafeVarargs public static <T> Stream<T> flatten(Stream<T>... streams) { return flatten(Arrays.stream(streams)); } }
private Stream<URL> recursiveExpand(File file) { return StreamUtils.ofNullable(file.listFiles()) .flatMap(Throwing.function(this::expandFile).sneakyThrow()); }
private Optional<String> retrieveSender(Mail mail) throws MessagingException { Optional<String> fromMime = StreamUtils.ofOptional( Optional.ofNullable(mail.getMessage()) .map(Throwing.function(MimeMessage::getFrom).orReturn(new Address[]{}))) .map(address -> (InternetAddress) address) .map(InternetAddress::getAddress) .findFirst(); Optional<String> fromEnvelope = mail.getMaybeSender().asOptional() .map(MailAddress::asString); return OptionalUtils.or( fromMime, fromEnvelope); } }
@SafeVarargs public static <T> Stream<T> flatten(Stream<T>... streams) { return flatten(Arrays.stream(streams)); } }
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(); }
@SafeVarargs public static <T> Stream<T> flatten(Stream<T>... streams) { return flatten(Arrays.stream(streams)); } }
@Test void ofNullableShouldReturnEmptyStreamWhenNull() { assertThat(StreamUtils.ofNullable(null) .collect(Guavate.toImmutableList())) .isEmpty(); }
public String formattedValue() { Stream<Optional<? extends Field>> definedFields = Stream.of( reportingUserAgentField, gatewayField, originalRecipientField, Optional.of(finalRecipientField), originalMessageIdField, Optional.of(dispositionField)); Stream<Optional<? extends Field>> errors = errorFields.stream().map(Optional::of); Stream<Optional<? extends Field>> extentions = extensionFields.stream().map(Optional::of); return StreamUtils.flatten( Stream.of( definedFields, errors, extentions)) .flatMap(OptionalUtils::toStream) .map(Field::formattedValue) .collect(Collectors.joining(LINE_END)) + LINE_END; }
@Test public void ofNullableShouldReturnEmptyStreamWhenNull() { assertThat(StreamUtils.ofNullable(null) .collect(Guavate.toImmutableList())) .isEmpty(); }
public Keywords asKeywords() { return Keywords.factory() .fromSet(StreamUtils .flatten( OptionalUtils.toStream(isAnswered.filter(b -> b).map(b -> Keyword.ANSWERED)), OptionalUtils.toStream(isDraft.filter(b -> b).map(b -> Keyword.DRAFT)), OptionalUtils.toStream(isForwarded.filter(b -> b).map(b -> Keyword.FORWARDED)), OptionalUtils.toStream(isFlagged.filter(b -> b).map(b -> Keyword.FLAGGED)), OptionalUtils.toStream(isUnread.filter(b -> !b).map(b -> Keyword.SEEN))) .collect(Guavate.toImmutableSet())); }
@Test void ofNullableShouldReturnAStreamWithElementsOfTheArray() { assertThat(StreamUtils.ofNullable(ImmutableList.of(1, 2).toArray()) .collect(Guavate.toImmutableList())) .containsExactly(1, 2); } }