List of usage examples for java.lang.ref SoftReference SoftReference
public SoftReference(T referent)
From source file:com.gdo.sql.slot.SQLSlot.java
@Override protected StencilIterator<StclContext, PStcl> getStencilsList(StclContext stclContext, StencilCondition<StclContext, PStcl> cond, PSlot<StclContext, PStcl> self) { // should be initialized before used if (!initialize(stclContext, self)) { String msg = logWarn(stclContext, "Cannot initialize slot %s", self); return StencilUtils.<StclContext, PStcl>iterator(Result.error(msg)); }/*from w ww . j a v a 2 s .c om*/ // if the list was already created for the same stencil context and // without any condition //synchronized (this) { // if ((_stencil_context_uid == stclContext.getId() || _read_only) && _stencil_context_map != null) { // return StencilUtils.<StclContext, PStcl> iterator(stclContext, _stencil_context_map.get().clone(), cond, self); // } //} // creates the stencil list SQLCursor cursor = getCursor(stclContext, self); List<IKey> keys = getKeys(stclContext, cond, self); List<PStcl> stencils = new Vector<PStcl>(keys.size()); for (IKey key : keys) { PStcl stencil = new PStcl(stclContext, self, key, cursor); stencils.add(stencil); } // returns the iterator (save for optimization on complete list) StencilIterator<StclContext, PStcl> map = new ListIterator<StclContext, PStcl>(stencils); if (cond == null) { _stencil_context_uid = stclContext.getId(); _stencil_context_map = new SoftReference<>(map); } return map; }
From source file:net.sourceforge.fenixedu.domain.Degree.java
private static void loadCache() { synchronized (degrees) { degrees.clear();/*from www.j a v a 2 s.com*/ for (final Degree degree : Degree.readNotEmptyDegrees()) { degrees.put(degree.getSigla().toLowerCase(), new SoftReference<Degree>(degree)); } } }
From source file:net.sourceforge.fenixedu.domain.Degree.java
private static void updateCache(final Degree degree, final String newLowerCaseSigla) { final String currentLowerCaseSigla = degree.getSigla() != null ? degree.getSigla().toLowerCase() : StringUtils.EMPTY;/*ww w .j a va2 s . c om*/ synchronized (degrees) { degrees.remove(currentLowerCaseSigla); degrees.put(newLowerCaseSigla, new SoftReference<Degree>(degree)); } }
From source file:org.apache.sysml.runtime.controlprogram.caching.CacheableData.java
/** * Creates a new cache soft reference to the currently * referenced cache block. // ww w. j a v a 2 s . c om */ protected void createCache() { _cache = new SoftReference<T>(_data); }
From source file:com.android.contacts.common.ContactPhotoManager.java
/** * If necessary, decodes bytes stored in the holder to Bitmap. As long as the * bitmap is held either by {@link #mBitmapCache} or by a soft reference in * the holder, it will not be necessary to decode the bitmap. *///from ww w .j ava 2 s . c om private static void inflateBitmap(BitmapHolder holder, int requestedExtent) { final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent); byte[] bytes = holder.bytes; if (bytes == null || bytes.length == 0) { return; } if (sampleSize == holder.decodedSampleSize) { // Check the soft reference. If will be retained if the bitmap is also // in the LRU cache, so we don't need to check the LRU cache explicitly. if (holder.bitmapRef != null) { holder.bitmap = holder.bitmapRef.get(); if (holder.bitmap != null) { return; } } } try { Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize); // TODO: As a temporary workaround while framework support is being added to // clip non-square bitmaps into a perfect circle, manually crop the bitmap into // into a square if it will be displayed as a thumbnail so that it can be cropped // into a circle. final int height = bitmap.getHeight(); final int width = bitmap.getWidth(); // The smaller dimension of a scaled bitmap can range from anywhere from 0 to just // below twice the length of a thumbnail image due to the way we calculate the optimal // sample size. if (height != width && Math.min(height, width) <= mThumbnailSize * 2) { final int dimension = Math.min(height, width); bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension); } // make bitmap mutable and draw size onto it if (DEBUG_SIZES) { Bitmap original = bitmap; bitmap = bitmap.copy(bitmap.getConfig(), true); original.recycle(); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setTextSize(16); paint.setColor(Color.BLUE); paint.setStyle(Style.FILL); canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint); paint.setColor(Color.WHITE); paint.setAntiAlias(true); canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint); } holder.decodedSampleSize = sampleSize; holder.bitmap = bitmap; holder.bitmapRef = new SoftReference<Bitmap>(bitmap); if (DEBUG) { Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + ", " + btk(bitmap.getByteCount())); } } catch (OutOfMemoryError e) { // Do nothing - the photo will appear to be missing } }
From source file:com.android.contacts.common.ContactPhotoManager.java
@Override public void cacheBitmap(Uri photoUri, Bitmap bitmap, byte[] photoBytes) { final int smallerExtent = Math.min(bitmap.getWidth(), bitmap.getHeight()); // We can pretend here that the extent of the photo was the size that we originally // requested/*w ww.j av a 2 s . c o m*/ Request request = Request.createFromUri(photoUri, smallerExtent, false /* darkTheme */, false /* isCircular */ , DEFAULT_AVATAR); BitmapHolder holder = new BitmapHolder(photoBytes, smallerExtent); holder.bitmapRef = new SoftReference<Bitmap>(bitmap); mBitmapHolderCache.put(request.getKey(), holder); mBitmapHolderCacheAllUnfresh = false; mBitmapCache.put(request.getKey(), bitmap); }
From source file:com.ibm.bi.dml.runtime.controlprogram.caching.MatrixObject.java
/** * */ private void createCache() { _cache = new SoftReference<MatrixBlock>(_data); }
From source file:edu.ku.brc.specify.tasks.QueryTask.java
/** * Constructs tableTree and tableTreeHash members. *///from w w w. ja v a2 s . c o m protected void bldTableTrees() { if (tableTree == null || tableTree.get() == null || needToRebuildTableTree()) { tableTreeHash = null; tableTree = new SoftReference<TableTree>(readTables()); } if (tableTreeHash == null || tableTreeHash.get() == null || needToRebuildTableTree()) { tableTreeHash = new SoftReference<Hashtable<String, TableTree>>(buildTableTreeHash(tableTree.get())); } configurationHasChanged.set(false); }
From source file:edu.ku.brc.ui.UIRegistry.java
/** * Reads in the disciplines file (is loaded when the class is loaded). * @return Reads in the disciplines file (is loaded when the class is loaded). *//*from w w w . jav a 2s .co m*/ public static BufferedImage getGlassPaneBufferedImage(final int width, final int height) { BufferedImage bufImg = null; if (glassPaneBufferedImageSR != null) { bufImg = glassPaneBufferedImageSR.get(); } if (bufImg != null) { if (bufImg.getWidth() != width && bufImg.getHeight() != height) { bufImg = null; } } if (bufImg == null) { glassPaneBufferedImageSR = new SoftReference<BufferedImage>( new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)); } return glassPaneBufferedImageSR.get(); }