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

com.zeroleak.throwingsupplier.LastValueFallbackSupplier Maven / Gradle / Ivy

Go to download

Guava cache supplier extension to memoize exceptions, fallback, expiration control.

The newest version!
package com.zeroleak.throwingsupplier;

public abstract class LastValueFallbackSupplier
    extends ThrowingSupplier {
  private Throwing lastValue; // last non-throwing value

  @Override
  public Throwing get() {
    Throwing value = super.get();
    if (value.getValue().isPresent()) {
      // value found => update lastValue
      this.lastValue = value;
      return value;
    } else {
      // value not found => return lastValue
      if (this.lastValue != null) {
        return lastValue;
      }
      // no lastValue => return throwing value
      return value;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy