List of usage examples for java.lang.ref Reference get
@HotSpotIntrinsicCandidate
public T get()
From source file:javadz.beanutils.MethodUtils.java
/** * Return the method from the cache, if present. * * @param md The method descriptor//from www . j a v a2 s . c o m * @return The cached method */ private static Method getCachedMethod(MethodDescriptor md) { if (CACHE_METHODS) { Reference methodRef = (Reference) cache.get(md); if (methodRef != null) { return (Method) methodRef.get(); } } return null; }
From source file:de.micromata.genome.util.event.SimpleEventClassRegistry.java
/** * Gets the listener.// w ww.ja v a2s .c om * * @param event the event * @return the listener */ List<Class<? extends MgcEventListener<?>>> getListener(MgcEvent event) { List<Class<? extends MgcEventListener<?>>> ret = new ArrayList<>(); for (Map.Entry<Class<? extends MgcEvent>, List<Reference<Class<? extends MgcEventListener<?>>>>> me : listenerMap .entrySet()) { if (me.getKey().isAssignableFrom(event.getClass()) == true) { for (Reference<Class<? extends MgcEventListener<?>>> ref : me.getValue()) { Class<? extends MgcEventListener<?>> listcls = ref.get(); if (listcls != null) { ret.add(listcls); } } } } return ret; }
From source file:com.slytechs.utils.memory.Malloc.java
public void free(ByteBuffer buffer) { for (Reference<? extends Buffer> r : allocated.keySet()) { if (r.get() == buffer) { free(allocated.remove(r));//from w ww. j ava2 s. c o m break; } } }
From source file:ReferenceValueMap.java
/** * Accessor for the values from the Map. * @return The Values./*www . j ava 2 s.c o m*/ **/ public Collection values() { reap(); Collection c = map.values(); Iterator i = c.iterator(); ArrayList l = new ArrayList(c.size()); while (i.hasNext()) { Reference ref = (Reference) i.next(); Object obj = ref.get(); if (obj != null) { l.add(obj); } } return Collections.unmodifiableList(l); }
From source file:ReferenceValueMap.java
/** * Accessor for whether the Map contains the specified value. * @param obj The value/*from w w w. ja v a2 s .c om*/ * @return Whether the Map contains the value. **/ public boolean containsValue(Object obj) { reap(); if (obj != null) { Iterator i = map.values().iterator(); while (i.hasNext()) { Reference ref = (Reference) i.next(); if (obj.equals(ref.get())) { return true; } } } return false; }
From source file:ReferenceValueMap.java
/** * Accessor for the entry set.// w w w . ja v a 2 s . c o m * @return The Set. **/ public Set entrySet() { reap(); Set s = map.entrySet(); Iterator i = s.iterator(); HashMap m = new HashMap(s.size()); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); Reference ref = (Reference) entry.getValue(); Object obj = ref.get(); if (obj != null) { m.put(entry.getKey(), obj); } } return Collections.unmodifiableSet(m.entrySet()); }
From source file:ReferenceValueMap.java
/** * Method to get a value for a key./*from w w w.j av a2 s . c om*/ * @param key The Key * @return The Value **/ public Object get(Object key) { reap(); Reference ref = (Reference) map.get(key); Object value = ref == null ? null : ref.get(); return value; }
From source file:WeakReferenceList.java
/** * Returns the child stored at the given index. If the child has been garbage collected, it gets restored using the * restoreChild function.//from w w w .j ava2s . c o m * * @param index the index. * @return the object. */ public Object get(final int index) { if (isMaster(index)) { return master; } else { final Reference ref = childs[getChildPos(index)]; if (ref == null) { throw new IllegalStateException("State: " + index); } Object ob = ref.get(); if (ob == null) { ob = restoreChild(index); childs[getChildPos(index)] = createReference(ob); } return ob; } }
From source file:com.datos.vfs.cache.SoftRefFilesCache.java
@Override public FileObject getFile(final FileSystem fileSystem, final FileName fileName) { final Map<FileName, Reference<FileObject>> files = getOrCreateFilesystemCache(fileSystem); lock.lock();//from w w w.j av a 2 s .c o m try { final Reference<FileObject> ref = files.get(fileName); if (ref == null) { return null; } final FileObject fo = ref.get(); if (fo == null) { removeFile(fileSystem, fileName); } return fo; } finally { lock.unlock(); } }
From source file:eu.qualityontime.commons.MethodUtils.java
/** * Return the method from the cache, if present. * * @param md// w ww . ja v a 2s . c o m * The method descriptor * @return The cached method */ private static Method getCachedMethod(final MethodDescriptor md) { if (CACHE_METHODS) { final Reference<Method> methodRef = cache.get(md); if (methodRef != null) { return methodRef.get(); } } return null; }