use of java.lang.ref.WeakReference in project tdi-studio-se by Talend.
the class BusinessEditPartProvider method provides.
/**
* @generated
*/
public synchronized boolean provides(IOperation operation) {
if (operation instanceof CreateGraphicEditPartOperation) {
View view = ((IEditPartOperation) operation).getView();
if (!BusinessProcessEditPart.MODEL_ID.equals(BusinessVisualIDRegistry.getModelID(view))) {
return false;
}
if (isAllowCaching() && getCachedPart(view) != null) {
return true;
}
IGraphicalEditPart part = createEditPart(view);
if (part != null) {
if (isAllowCaching()) {
cachedPart = new WeakReference(part);
cachedView = new WeakReference(view);
}
return true;
}
}
return false;
}
use of java.lang.ref.WeakReference in project android_frameworks_base by ResurrectionRemix.
the class SparseWeakArray method put.
/**
* Adds a mapping from the specified key to the specified value,
* replacing the previous mapping from the specified key if there
* was one.
*/
public void put(long key, E value) {
int i = binarySearch(mKeys, 0, mSize, key);
if (i >= 0) {
mValues[i] = new WeakReference(value);
} else {
i = ~i;
if (i < mSize && (mValues[i] == DELETED || mValues[i].get() == null)) {
mKeys[i] = key;
mValues[i] = new WeakReference(value);
return;
}
if (mSize >= mKeys.length && (mGarbage || hasReclaimedRefs())) {
gc();
// Search again because indices may have changed.
i = ~binarySearch(mKeys, 0, mSize, key);
}
mKeys = GrowingArrayUtils.insert(mKeys, mSize, i, key);
mValues = GrowingArrayUtils.insert(mValues, mSize, i, new WeakReference(value));
mSize++;
}
}
use of java.lang.ref.WeakReference in project Entitas-Java by Rubentxu.
the class TypeResolver method getTypeVariableMap.
private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> targetType, Class<?> functionalInterface) {
Reference<Map<TypeVariable<?>, Type>> ref = TYPE_VARIABLE_CACHE.get(targetType);
Map<TypeVariable<?>, Type> map = ref != null ? ref.get() : null;
if (map == null) {
map = new HashMap<TypeVariable<?>, Type>();
// Populate lambdas
if (functionalInterface != null)
populateLambdaArgs(functionalInterface, targetType, map);
// Populate interfaces
populateSuperTypeArgs(targetType.getGenericInterfaces(), map, functionalInterface != null);
// Populate super classes and interfaces
Type genericType = targetType.getGenericSuperclass();
Class<?> type = targetType.getSuperclass();
while (type != null && !Object.class.equals(type)) {
if (genericType instanceof ParameterizedType)
populateTypeArgs((ParameterizedType) genericType, map, false);
populateSuperTypeArgs(type.getGenericInterfaces(), map, false);
genericType = type.getGenericSuperclass();
type = type.getSuperclass();
}
// Populate enclosing classes
type = targetType;
while (type.isMemberClass()) {
genericType = type.getGenericSuperclass();
if (genericType instanceof ParameterizedType)
populateTypeArgs((ParameterizedType) genericType, map, functionalInterface != null);
type = type.getEnclosingClass();
}
if (CACHE_ENABLED)
TYPE_VARIABLE_CACHE.put(targetType, new WeakReference<Map<TypeVariable<?>, Type>>(map));
}
return map;
}
use of java.lang.ref.WeakReference in project Presentation by StanKocken.
the class BaseAppCompatActivityTest method testShouldWeakReferenceOnPresenter.
@Test
public void testShouldWeakReferenceOnPresenter() {
BasePresenter basePresenter = new BasePresenter(null, null) {
};
final WeakReference<BasePresenter> weakReferencePresenter = new WeakReference<>(basePresenter);
BaseAppCompatActivity baseActivity = new TestBaseAppCompatActivity() {
@Override
protected BasePresenter newPresenter() {
return weakReferencePresenter.get();
}
};
baseActivity.onCreate(null);
assertEquals(basePresenter, baseActivity.getPresenter());
basePresenter = null;
for (int i = 0; i < 10 && weakReferencePresenter.get() != null; i++) {
System.gc();
}
assertNull(basePresenter);
assertNull(weakReferencePresenter.get());
assertNull(baseActivity.getPresenter());
}
use of java.lang.ref.WeakReference in project android_frameworks_base by ResurrectionRemix.
the class ThemedResourceCache method getThemedLocked.
/**
* Returns the cached data for the specified theme, optionally creating a
* new entry if one does not already exist.
*
* @param t the theme for which to return cached data
* @param create {@code true} to create an entry if one does not already
* exist, {@code false} otherwise
* @return the cached data for the theme, or {@code null} if the cache is
* empty and {@code create} was {@code false}
*/
@Nullable
private LongSparseArray<WeakReference<T>> getThemedLocked(@Nullable Theme t, boolean create) {
if (t == null) {
if (mNullThemedEntries == null && create) {
mNullThemedEntries = new LongSparseArray<>(1);
}
return mNullThemedEntries;
}
if (mThemedEntries == null) {
if (create) {
mThemedEntries = new ArrayMap<>(1);
} else {
return null;
}
}
final ThemeKey key = t.getKey();
LongSparseArray<WeakReference<T>> cache = mThemedEntries.get(key);
if (cache == null && create) {
cache = new LongSparseArray<>(1);
final ThemeKey keyClone = key.clone();
mThemedEntries.put(keyClone, cache);
}
return cache;
}
Aggregations