本文整理汇总了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);
}
}
}
示例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();
}
示例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();
}
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
}
示例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;
}
示例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();
}
}
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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();
}
}