com.intellij.openapi.util.UserDataHolderBase Maven / Gradle / Ivy
package com.intellij.openapi.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
public class UserDataHolderBase implements UserDataHolder {
private final Map, Object> myMap = new HashMap<>(0);
@Override
public @Nullable T getUserData(@NotNull Key key) {
//noinspection unchecked
T value = (T) myMap.get(key);
if (value == null && key instanceof KeyWithDefaultValue kwdv) {
value = kwdv.getDefaultValue();
putUserData(key, value);
}
return value;
}
@Override
public void putUserData(@NotNull Key key, @Nullable T value) {
myMap.put(key, value);
}
}