SingleKeyCache.java
net.minecraft.util.SingleKeyCache
信息
- 全限定名:net.minecraft.util.SingleKeyCache
- 类型:public class
- 包:net.minecraft.util
- 源码路径:src/main/java/net/minecraft/util/SingleKeyCache.java
- 起始行号:L7
- 职责:
TODO
字段/常量
-
computeValue- 类型:
Function<K,V> - 修饰符:
private final - 源码定位:
L8 - 说明:
TODO
- 类型:
-
cacheKey- 类型:
K - 修饰符:
private - 源码定位:
L9 - 说明:
TODO
- 类型:
-
cachedValue- 类型:
V - 修饰符:
private - 源码定位:
L10 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public SingleKeyCache(Function<K,V> computeValue) @ L12
- 构造器名:SingleKeyCache
- 源码定位:L12
- 修饰符:public
参数:
- computeValue: Function<K,V>
说明:
TODO
方法
下面的方法块按源码顺序生成。
public V getValue(K cacheKey) @ L16
- 方法名:getValue
- 源码定位:L16
- 返回类型:V
- 修饰符:public
参数:
- cacheKey: K
说明:
TODO
代码
public class SingleKeyCache<K, V> {
private final Function<K, V> computeValue;
private @Nullable K cacheKey = (K)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;
}
}引用的其他类
- 无