org.robolectric.internal.bytecode.ClassValueMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sandbox Show documentation
Show all versions of sandbox Show documentation
An alternative Android testing framework.
package org.robolectric.internal.bytecode;
import com.google.common.annotations.VisibleForTesting;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
/**
* {@link java.lang.ClassValue} doesn't exist in Android, so provide a trivial impl.
*
* Note that if T contains references to Class, this won't really be weak. That's okay.
*/
abstract class ClassValueMap {
private final Map, T> map = Collections.synchronizedMap(new WeakHashMap<>());
protected abstract T computeValue(Class> type);
@SuppressWarnings("AndroidJdkLibsChecker")
public T get(Class> type) {
return map.computeIfAbsent(type, this::computeValue);
}
@VisibleForTesting
void clear() {
map.clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy