Search in sources :

Example 61 with WeakReference

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;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) WeakReference(java.lang.ref.WeakReference) IEditPartOperation(org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation) CreateGraphicEditPartOperation(org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation) View(org.eclipse.gmf.runtime.notation.View)

Example 62 with WeakReference

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++;
    }
}
Also used : WeakReference(java.lang.ref.WeakReference)

Example 63 with WeakReference

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;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) TypeVariable(java.lang.reflect.TypeVariable) WeakReference(java.lang.ref.WeakReference) HashMap(java.util.HashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap)

Example 64 with WeakReference

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());
}
Also used : WeakReference(java.lang.ref.WeakReference) BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Example 65 with WeakReference

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;
}
Also used : ThemeKey(android.content.res.Resources.ThemeKey) WeakReference(java.lang.ref.WeakReference) Nullable(android.annotation.Nullable)

Aggregations

WeakReference (java.lang.ref.WeakReference)291 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)24 Map (java.util.Map)24 Field (java.lang.reflect.Field)19 Activity (android.app.Activity)17 Iterator (java.util.Iterator)17 IOException (java.io.IOException)16 Method (java.lang.reflect.Method)15 File (java.io.File)14 URLClassLoader (java.net.URLClassLoader)14 Test (org.junit.Test)13 Reference (java.lang.ref.Reference)12 ReferenceQueue (java.lang.ref.ReferenceQueue)12 Resources (android.content.res.Resources)10 Handler (android.os.Handler)10 AbstractModule (com.google.inject.AbstractModule)10 Injector (com.google.inject.Injector)10 ArrayMap (android.util.ArrayMap)9 URL (java.net.URL)8