package net.minecraft.util; import java.util.Objects; import java.util.function.Function; import org.jetbrains.annotations.Nullable; public class SingleKeyCache { private final Function computeValue; @Nullable private K cacheKey = (K)null; @Nullable private V cachedValue; public SingleKeyCache(Function computeValue) { this.computeValue = computeValue; } public V getValue(K cacheKey) { if (this.cachedValue == null || !Objects.equals(this.cacheKey, cacheKey)) { this.cachedValue = (V)this.computeValue.apply(cacheKey); this.cacheKey = cacheKey; } return this.cachedValue; } }