當前位置: 首頁>>代碼示例>>Java>>正文


Java WeakReference.get方法代碼示例

本文整理匯總了Java中java.lang.ref.WeakReference.get方法的典型用法代碼示例。如果您正苦於以下問題:Java WeakReference.get方法的具體用法?Java WeakReference.get怎麽用?Java WeakReference.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.ref.WeakReference的用法示例。


在下文中一共展示了WeakReference.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: removePropertyChangeListener

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/**
 * Remove a PropertyChangeListener from the listener list. This removes a 
 * PropertyChangeListener that was registered for all properties. If 
 * listener was added more than once to the same event source, it will be 
 * notified one less time after being removed. If listener is null, or was 
 * never added, no exception is thrown and no action is taken.
 * 
 * @param listener The PropertyChangeListener to be rem ove
 */
public void removePropertyChangeListener(PropertyChangeListener listener)
{
    
    for(int index = listeners.size() - 1; index >= 0; index--)
    {
        WeakReference<PropertyChangeListener> ref = listeners.get(index);
        PropertyChangeListener refListener = ref.get();
        if(refListener != null)
        {
            if(refListener.equals(listener) == true)
            {
                listeners.remove(index);
            }
        }
        else
        {
            listeners.remove(index);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:ResourceTable.java

示例2: onServiceDisconnected

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
@Override
public void onServiceDisconnected(ComponentName componentName) {
    Log.i(TAG, "onServiceDisconnected disconnected!");
    mPluginManager = null;

    Iterator<WeakReference<ServiceConnection>> iterator = sServiceConnection.iterator();
    while (iterator.hasNext()) {
        WeakReference<ServiceConnection> wsc = iterator.next();
        ServiceConnection sc = wsc != null ? wsc.get() : null;
        if (sc != null) {
            sc.onServiceDisconnected(componentName);
        } else {
            iterator.remove();
        }
    }
    //服務連接斷開,需要重新連接。
    connectToService();
}
 
開發者ID:amikey,項目名稱:DroidPlugin,代碼行數:19,代碼來源:PluginManager.java

示例3: processThreadAction

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/**
 * Propagate the the thread state change information
 * to registered listeners.
 * Must be entered while synchronized on vm.state()
 */
private void processThreadAction(ThreadAction action) {
    synchronized (vm.state()) {
        Iterator<WeakReference<ThreadListener>> iter = listeners.iterator();
        while (iter.hasNext()) {
            WeakReference<ThreadListener> ref = iter.next();
            ThreadListener listener = ref.get();
            if (listener != null) {
                switch (action.id()) {
                    case ThreadAction.THREAD_RESUMABLE:
                        if (!listener.threadResumable(action)) {
                            iter.remove();
                        }
                        break;
                }
            } else {
                // Listener is unreachable; clean up
                iter.remove();
            }
        }

        // Discard our local cache
        resetLocalCache();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:ThreadReferenceImpl.java

示例4: forceFullGc

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/** No guarantees, but effective in practice. */
private static void forceFullGc() {
    CountDownLatch finalizeDone = new CountDownLatch(1);
    WeakReference<?> ref = new WeakReference<Object>(new Object() {
        protected void finalize() { finalizeDone.countDown(); }});
    try {
        for (int i = 0; i < 10; i++) {
            System.gc();
            if (finalizeDone.await(1L, SECONDS) && ref.get() == null) {
                System.runFinalization(); // try to pick up stragglers
                return;
            }
        }
    } catch (InterruptedException unexpected) {
        throw new AssertionError("unexpected InterruptedException");
    }
    throw new AssertionError("failed to do a \"full\" gc");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TimedAcquireLeak.java

示例5: getInterpPoints

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/**
 * Gets the interpolation parameters for a Bezier curve approximated
 * by the given number of vertices. 
 * 
 * @param npoints number of vertices
 * 
 * @return array of {@code InterpPoint} objects holding the parameter values
 */
private InterpPoint[] getInterpPoints(int npoints) {
    WeakReference<InterpPoint[]> ref = lookup.get(npoints);
    InterpPoint[] ip = null;
    if (ref != null) ip = ref.get();
    
    if (ip == null) {
        ip = new InterpPoint[npoints];
    
        for (int i = 0; i < npoints; i++) {
            double t = (double) i / (npoints - 1);
            double tc = 1.0 - t;

            ip[i] = new InterpPoint();
            ip[i].t[0] = tc*tc*tc;
            ip[i].t[1] = 3.0*tc*tc*t;
            ip[i].t[2] = 3.0*tc*t*t;
            ip[i].t[3] = t*t*t;
            ip[i].tsum = ip[i].t[0] + ip[i].t[1] + ip[i].t[2] + ip[i].t[3];
        }
        
        lookup.put(npoints, new WeakReference<InterpPoint[]>(ip));
    }
    
    return ip;
}
 
開發者ID:FedericoPecora,項目名稱:coordination_oru,代碼行數:34,代碼來源:GeometrySmoother.java

示例6: getAllArguments

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/**
 * Returns all arguments.
 */
public Collection<Element> getAllArguments() {
	List<Element> result = new ArrayList<Element>(arguments.size());
	for (WeakReference<Element> ref : arguments.values()) {
		Element elt = ref.get();
		if (elt != null)
			result.add(elt);
	}
	Collections.sort(result, ElementComparator.INSTANCE);
    return result;
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:14,代碼來源:Tuple.java

示例7: v

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
public <T extends View> T v(@IdRes int resId) {
    WeakReference<View> viewWeakReference = sparseArray.get(resId);
    View view;
    if (viewWeakReference == null) {
        view = itemView.findViewById(resId);
        sparseArray.put(resId, new WeakReference<>(view));
    } else {
        view = viewWeakReference.get();
        if (view == null) {
            view = itemView.findViewById(resId);
            sparseArray.put(resId, new WeakReference<>(view));
        }
    }
    return (T) view;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:16,代碼來源:RBaseViewHolder.java

示例8: notifyListeners

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/**
 */
void notifyListeners() {
    for (Enumeration e = listeners.elements(); e.hasMoreElements(); ) {
        WeakReference wr = (WeakReference) e.nextElement();
        ClassPathListener l = (ClassPathListener) wr.get();
        if (l == null)  // garbage collected
            listeners.removeElement(wr);
        else
            l.classPathChanged();
    }
}
 
開發者ID:imkiva,項目名稱:Krine,代碼行數:13,代碼來源:KrineClassPath.java

示例9: callBackErrorEventListener

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
private void callBackErrorEventListener(int eventCode, Bundle bundle) {
    if(mErrorEventListenerList==null)
        return;
    Iterator<WeakReference<OnErrorListener>> iterator = mErrorEventListenerList.iterator();
    while (iterator.hasNext()){
        WeakReference<OnErrorListener> onErrorListener = iterator.next();
        if(onErrorListener!=null){
            OnErrorListener errorListener = onErrorListener.get();
            if(errorListener!=null){
                errorListener.onError(eventCode,bundle);
            }
        }
    }
}
 
開發者ID:jiajunhui,項目名稱:PlayerBase,代碼行數:15,代碼來源:BaseBindPlayerEventReceiver.java

示例10: getItem

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
/**
 * Get a cached Item by index
 * @param index Index
 * @return Cached Item, or <code>null</code> if Item was not cached or was garbage collected according to
 *         {@link WeakReference} behaviour
 */
public ITEM getItem(int index) {
	WeakReference<ITEM> itemReference = get(index);
	if (itemReference != null) {
		return itemReference.get();
	}
	return null;
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:14,代碼來源:ItemCacheMap.java

示例11: requestNextPermissionWithListener

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
private static void requestNextPermissionWithListener(PermissionWrapper wrapper) {
    int nextCode = wrapper.getRequestCodes()[0];
    if (wrapper.getRequestCode() != nextCode) {
        WeakReference<PermissionWrapper> reference = AbstractWrapper.getWrapperMap().get(new
                AbstractWrapper.Key(wrapper.getContext(), nextCode));
        if (reference != null) {
            AbstractWrapper permissionWrapper = (AbstractWrapper) reference.get();
            if (permissionWrapper != null) {
                permissionWrapper.requestPermissionWithListener();
            }
        }
    }
}
 
開發者ID:jokermonn,項目名稱:permissions4m,代碼行數:14,代碼來源:NormalApplyPermissions.java

示例12: releaseOther

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
public static void releaseOther(QSVideoView qs) {
    for (WeakReference<QSVideoView> w : videos) {
        QSVideoView q = w.get();
        if (q != null & q != qs)
            q.release();
    }
}
 
開發者ID:tohodog,項目名稱:QSVideoPlayer,代碼行數:8,代碼來源:ConfigManage.java

示例13: fetchStack

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private static StackEntry[] fetchStack() {
    WeakReference<StackEntry[]> ref = stacks.get();
    StackEntry[] stack = ref.get();
    if (stack == null) {
        ref = new WeakReference<StackEntry[]>(stack = allocateStack());
        stacks.set(ref);
    }
    return stack;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:StackMachine.java

示例14: createImmutable

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
public static synchronized InputEdge createImmutable(char fromIndex, char toIndex, int from, int to, String label, String type) {
    InputEdge edge = new InputEdge(fromIndex, toIndex, from, to, label, type, State.IMMUTABLE);
    WeakReference<InputEdge> result = immutableCache.get(edge);
    if (result != null) {
        InputEdge edge2 = result.get();
        if (edge2 != null) {
            return edge2;
        }
    }
    immutableCache.put(edge, new WeakReference<>(edge));
    return edge;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:InputEdge.java

示例15: addVideoView

import java.lang.ref.WeakReference; //導入方法依賴的package包/類
private void addVideoView(QSVideoView q) {
    WeakReference<QSVideoView> w = new WeakReference<>(q);
    videos.add(w);
    Iterator<WeakReference<QSVideoView>> iterList = videos.iterator();//List接口實現了Iterable接口
    while (iterList.hasNext()) {
        WeakReference<QSVideoView> ww = iterList.next();
        if (ww.get() == null)
            iterList.remove();
    }
}
 
開發者ID:tohodog,項目名稱:QSVideoPlayer,代碼行數:11,代碼來源:ConfigManage.java


注:本文中的java.lang.ref.WeakReference.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。