All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.internal.bytecode.ClassValueMap Maven / Gradle / Ivy

There is a newer version: 4.14.1
Show newest version
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