List of usage examples for java.lang.ref SoftReference SoftReference
public SoftReference(T referent)
From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java
@Override public Array getScanAcquisitionTime() { init();//from www.j ava 2s .c o m Array sat = null; if (satReference == null || satReference.get() == null) { sat = scanAcquisitionTimeVariable.getArray(); satReference = new SoftReference<>(sat); } else { sat = satReference.get(); if (sat == null) { sat = scanAcquisitionTimeVariable.getArray(); satReference = new SoftReference<>(sat); } } EvalTools.notNull(sat, this); return sat; }
From source file:com.androidpi.bricks.gallery.lru.cache.ImageCache.java
/** * Initialize the cache, providing all parameters. * * @param cacheParams The cache parameters to initialize the cache *//*from www . j ava 2 s. co m*/ private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; // BEGIN_INCLUDE(init_memory_cache) // Set up memory cache if (mCacheParams.memoryCacheEnabled) { if (BuildConfig.DEBUG) { Log.d(TAG, "Memory cache created (size = " + mCacheParams.memCacheSize + ")"); } // If we're running on Honeycomb or newer, create a set of reusable // bitmaps that can be // populated into the inBitmap field of BitmapFactory.Options. Note // that the set is // of SoftReferences which will actually not be very effective due // to the garbage // collector being aggressive clearing Soft/WeakReferences. A better // approach // would be to use a strongly references bitmaps, however this would // require some // balancing of memory usage between this set and the bitmap // LruCache. It would also // require knowledge of the expected size of the bitmaps. From // Honeycomb to JellyBean // the size would need to be precise, from KitKat onward the size // would just need to // be the upper bound (due to changes in how inBitmap can re-use // bitmaps). if (AppUtil.hasHoneycomb()) { mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>()); } mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) { /** * Notify the removed entry that is no longer being cached */ @Override protected void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue, BitmapDrawable newValue) { if (RecyclingBitmapDrawable.class.isInstance(oldValue)) { // The removed entry is a recycling drawable, so notify // it // that it has been removed from the memory cache ((RecyclingBitmapDrawable) oldValue).setIsCached(false); } else { // The removed entry is a standard BitmapDrawable if (AppUtil.hasHoneycomb()) { // We're running on Honeycomb or later, so add the // bitmap // to a SoftReference set for possible use with // inBitmap later mReusableBitmaps.add(new SoftReference<Bitmap>(oldValue.getBitmap())); } } } /** * Measure item size in kilobytes rather than units which is * more practical for a bitmap cache */ @Override protected int sizeOf(String key, BitmapDrawable value) { final int bitmapSize = getBitmapSize(value) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; } // END_INCLUDE(init_memory_cache) // By default the disk cache is not initialized here as it should be // initialized // on a separate thread due to disk access. if (cacheParams.initDiskCacheOnCreate) { // Set up disk cache initDiskCache(); } }
From source file:com.silverwrist.dynamo.unistore.TextPartImpl.java
void precacheText(String txt) { m_text = new SoftReference(txt); }
From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java
protected double[] getSatArray() { double[] satArray = null; if (satArrayReference == null || satArrayReference.get() == null) { satArray = (double[]) getScanAcquisitionTime().get1DJavaArray(double.class); satArrayReference = new SoftReference<>(satArray); } else {/* w w w. j a v a 2s . c om*/ satArray = satArrayReference.get(); } if (satArray == null) { throw new ResourceNotAvailableException("Could not retrieve scan acquisition time array!"); } return satArray; }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
public static Contact getContact(Context context, long contactId) { SoftReference<Contact> entry = g_contacts.get(contactId); if (entry != null) { Contact c = entry.get();/* ww w .j av a 2 s . co m*/ if (c != null) return c; } Contact c = forceGetContact(context, contactId); g_contacts.put(contactId, new SoftReference<Contact>(c)); return c; }
From source file:org.kuali.coeus.propdev.impl.budget.subaward.BudgetSubAwards.java
@Override public byte[] getSubAwardXfdFileData() { if (subAwardXfdFileData != null) { byte[] existingData = subAwardXfdFileData.get(); if (existingData != null) { return existingData; }/*from w w w. ja va2 s . c om*/ } //if we didn't have a softreference, grab the data from the db byte[] newData = getKcAttachmentDao().getData(fileDataId); subAwardXfdFileData = new SoftReference<byte[]>(newData); return newData; }
From source file:com.ndn.menurandom.ImageDownloader.java
/** * Adds this bitmap to the cache.//from w w w .j a v a 2 s .co m * @param bitmap The newly downloaded bitmap. */ private void addBitmapToCache(String url, Bitmap bitmap) { mMemoryCache.put(url, new SoftReference<Bitmap>(bitmap)); }
From source file:org.kuali.coeus.propdev.impl.budget.subaward.BudgetSubAwards.java
public void setSubAwardXfdFileData(byte[] subAwardXfdFileData) { if (subAwardXfdFileData == null) { getKcAttachmentDao().removeData(fileDataId); fileDataId = null;// w w w. jav a 2 s. c om } else { fileDataId = getKcAttachmentDao().saveData(subAwardXfdFileData, fileDataId); } this.subAwardXfdFileData = new SoftReference<byte[]>(subAwardXfdFileData); }
From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram2D.java
@Override public Array getScanAcquisitionTime() { init();//from ww w. java2 s . c o m Array sat = null; if (satReference == null || satReference.get() == null) { sat = scanAcquisitionTimeVariable.getArray(); satReference = new SoftReference<>(sat); } else { sat = satReference.get(); if (sat == null) { sat = scanAcquisitionTimeVariable.getArray(); satReference = new SoftReference<>(sat); } } return sat; }
From source file:org.kuali.coeus.propdev.impl.budget.subaward.BudgetSubAwards.java
@Override public String getSubAwardXmlFileData() { if (subAwardXmlFileData != null) { return subAwardXmlFileData.get(); }/* w ww .j a v a 2 s .com*/ //if we didn't have a softreference, grab the data from the db byte[] newData = getKcAttachmentDao().getData(xmlDataId); String newString = newData != null ? new String(newData) : null; subAwardXmlFileData = new SoftReference<String>(newString); return newString; }