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

com.github.chaosfirebolt.converter.constants.ResultCachingSupplier Maven / Gradle / Ivy

There is a newer version: 3.7.0
Show newest version
package com.github.chaosfirebolt.converter.constants;

import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

class ResultCachingSupplier implements Supplier {

  private final Supplier delegate;
  private final BooleanSupplier recalculateCondition;
  private T cachedValue;

  ResultCachingSupplier(Supplier delegate, BooleanSupplier recalculateCondition) {
    this.delegate = delegate;
    this.recalculateCondition = recalculateCondition;
  }

  @Override
  public T get() {
    if (cachedValue == null || recalculateCondition.getAsBoolean()) {
      cachedValue = delegate.get();
    }
    return cachedValue;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy