Interface MessageStream.Empty<M extends Message>

Type Parameters:
M - The type of Message for the empty MessageStream.Entry of this stream.
All Superinterfaces:
MessageStream<M>, MessageStream.Single<M>
Enclosing interface:
MessageStream<M extends Message>

public static interface MessageStream.Empty<M extends Message> extends MessageStream.Single<M>
A MessageStream implementation that completes normally or with an error without returning any elements.

Any operations that would map(Function) or MessageStream.reduce(Object, BiFunction) the stream will do nothing at all for an empty MessageStream.

Since:
5.0.0
Author:
Allard Buijze, Mateusz Nowak, Mitchell Herrijgers, Steven van Beelen
See Also:
  • Method Details

    • first

      default MessageStream.Empty<M> first()
      Description copied from interface: MessageStream
      Returns a stream that includes only the first message of this stream, unless it completes without delivering any messages, in which case it completes the same way.

      When the first message is delivered, the returned stream completes normally, independently of how this stream completes. Upon consuming the first message, this stream is MessageStream.close() immediately.

      Specified by:
      first in interface MessageStream<M extends Message>
      Specified by:
      first in interface MessageStream.Single<M extends Message>
      Returns:
      A stream that includes only the first message of this stream.
    • map

      default <RM extends Message> MessageStream.Empty<RM> map(@Nonnull Function<MessageStream.Entry<M>,MessageStream.Entry<RM>> mapper)
      Description copied from interface: MessageStream
      Returns a stream that maps each entry from this stream using given mapper function into an entry carrying a MessageEntry with a Message of type RM.

      The returned stream completes the same way this stream completes.

      Specified by:
      map in interface MessageStream<M extends Message>
      Specified by:
      map in interface MessageStream.Single<M extends Message>
      Type Parameters:
      RM - The declared type of Message contained in the returned entry.
      Parameters:
      mapper - The function converting entries from this stream from entries containing message of type M to RM.
      Returns:
      A stream with all entries mapped according to the mapper function.
    • mapMessage

      default <RM extends Message> MessageStream.Empty<RM> mapMessage(@Nonnull Function<M,RM> mapper)
      Description copied from interface: MessageStream
      Returns a stream that maps each message from the entries in this stream using the given mapper function. This maps the Messages from type M to type RM.

      The returned stream completes the same way this stream completes.

      Specified by:
      mapMessage in interface MessageStream<M extends Message>
      Specified by:
      mapMessage in interface MessageStream.Single<M extends Message>
      Type Parameters:
      RM - The declared type of Message contained in the returned entry.
      Parameters:
      mapper - The function converting message from the entries in this stream from type M to RM.
      Returns:
      A stream with all entries mapped according to the mapper function.
    • onNext

      default MessageStream.Empty<M> onNext(@Nonnull Consumer<MessageStream.Entry<M>> onNext)
      Description copied from interface: MessageStream
      Invokes the given onNext each time an entry is consumed from this stream.

      Depending on the stream's implementation, the function may be invoked when the entry is provided to the Consumer, or at the moment it's available for reading on the stream. Subscribing multiple times to the resulting stream may cause the given onNext to be invoked more than once for an entry.

      Specified by:
      onNext in interface MessageStream<M extends Message>
      Specified by:
      onNext in interface MessageStream.Single<M extends Message>
      Parameters:
      onNext - The Consumer to invoke for each entry.
      Returns:
      A stream that will invoke the given onNext for each entry.
    • concatWith

      default MessageStream<M> concatWith(@Nonnull MessageStream<M> other)
      Description copied from interface: MessageStream
      Returns a stream that concatenates this stream with the given other stream, if this stream completes successfully. Throws an exception if this stream is unbounded.

      When this stream completes with an error, so does the returned stream.

      Specified by:
      concatWith in interface MessageStream<M extends Message>
      Parameters:
      other - The MessageStream to append to this stream.
      Returns:
      A stream concatenating this stream with given other.
    • onComplete

      default MessageStream.Empty<M> onComplete(@Nonnull Runnable completeHandler)
      Description copied from interface: MessageStream
      Returns a stream that invokes the given completeHandler when the stream completes normally. Throws an exception if this stream is unbounded.
      Specified by:
      onComplete in interface MessageStream<M extends Message>
      Specified by:
      onComplete in interface MessageStream.Single<M extends Message>
      Parameters:
      completeHandler - The Runnable to invoke when the stream completes normally.
      Returns:
      A stream that invokes the completeHandler upon normal completion.
    • cast

      default <T extends Message> MessageStream.Empty<T> cast()
      Description copied from interface: MessageStream
      Casts this stream to the given type. This method is provided to be more flexible with generics. It is the caller's responsibility to ensure the cast is valid. Failure to do so may result in ClassCastException when reading elements.
      Specified by:
      cast in interface MessageStream<M extends Message>
      Specified by:
      cast in interface MessageStream.Single<M extends Message>
      Type Parameters:
      T - The type of Message to cast the MessageStream to.
      Returns:
      This instance, cast to the given Message of type T.