当前位置: 首页>>代码示例>>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;未经允许,请勿转载。