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

net.pincette.rs.Last Maven / Gradle / Ivy

There is a newer version: 3.7.1
Show newest version
package net.pincette.rs;

import java.util.concurrent.Flow.Processor;

/**
 * Emits the last value it receives and then completes the stream.
 *
 * @param  the value type.
 * @author Werner Donn\u00e9
 * @since 1.4
 */
public class Last extends PassThrough {
  private T lastValue;

  public static  Processor last() {
    return new Last<>();
  }

  @Override
  public void onComplete() {
    if (lastValue != null) {
      super.onNext(lastValue);
    }

    super.onComplete();
  }

  @Override
  public void onNext(final T value) {
    lastValue = value;
    more();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy