All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.commercetools.sync.commons.utils.StreamUtils Maven / Gradle / Ivy

package com.commercetools.sync.commons.utils;

import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Stream;
import javax.annotation.Nonnull;

public final class StreamUtils {

  /**
   * Applies the supplied {@code mapper} function on every non-null element in the supplied {@link
   * java.util.stream.Stream} of {@code elements}.
   *
   * @param elements the stream of elements.
   * @param mapper the mapper function to apply on every element.
   * @param  the type of the elements in the stream.
   * @param  the resulting type after applying the mapper function on an element.
   * @return a stream of the resulting mapped elements.
   */
  @Nonnull
  public static  Stream filterNullAndMap(
      @Nonnull final Stream elements, @Nonnull final Function mapper) {

    return elements.filter(Objects::nonNull).map(mapper);
  }

  private StreamUtils() {}
}