2025-11-24 22:52:51 +03:00

31 lines
798 B
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* org.jspecify.annotations.Nullable
*/
package net.minecraft.util;
import java.util.Objects;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
public class SingleKeyCache<K, V> {
private final Function<K, V> computeValue;
private @Nullable K cacheKey = null;
private @Nullable V cachedValue;
public SingleKeyCache(Function<K, V> computeValue) {
this.computeValue = computeValue;
}
public V getValue(K cacheKey) {
if (this.cachedValue == null || !Objects.equals(this.cacheKey, cacheKey)) {
this.cachedValue = this.computeValue.apply(cacheKey);
this.cacheKey = cacheKey;
}
return this.cachedValue;
}
}