public synchronized void clean() { for (Iterator<TimedCacheEntry<BufferedImage>> iterator = entries.iterator(); iterator.hasNext(); ) { TimedCacheEntry<BufferedImage> entry = iterator.next(); if (entry.isExpired()) iterator.remove(); } }
public synchronized BufferedImage acquire(Dimension dimension) { TimedCacheEntry<BufferedImage> match = null; for (TimedCacheEntry<BufferedImage> entry : entries) { BufferedImage image = entry.value(); if (image != null && image.getWidth() == dimension.width && image.getHeight() == dimension.height) { match = entry; break; } } if (match != null) { entries.remove(match); return match.value(); } else { return allocateNewBufferedImage(dimension, 3); } }