1 11 package org.eclipse.jdt.internal.core; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.jdt.core.IBuffer; 16 import org.eclipse.jdt.internal.core.util.LRUCache; 17 18 21 public class BufferCache extends OverflowingLRUCache { 22 23 private ThreadLocal buffersToClose = new ThreadLocal (); 24 27 public BufferCache(int size) { 28 super(size); 29 } 30 33 public BufferCache(int size, int overflow) { 34 super(size, overflow); 35 } 36 43 protected boolean close(LRUCacheEntry entry) { 44 IBuffer buffer= (IBuffer) entry._fValue; 45 46 if (!((Openable)buffer.getOwner()).canBufferBeRemovedFromCache(buffer)) { 49 return false; 50 } else { 51 ArrayList buffers = (ArrayList ) this.buffersToClose.get(); 52 if (buffers == null) { 53 buffers = new ArrayList (); 54 this.buffersToClose.set(buffers); 55 } 56 buffers.add(buffer); 57 return true; 58 } 59 } 60 61 void closeBuffers() { 62 ArrayList buffers = (ArrayList ) this.buffersToClose.get(); 63 if (buffers == null) 64 return; 65 this.buffersToClose.set(null); 66 for (int i = 0, length = buffers.size(); i < length; i++) { 67 ((IBuffer) buffers.get(i)).close(); 68 } 69 } 70 73 protected LRUCache newInstance(int size, int overflow) { 74 return new BufferCache(size, overflow); 75 } 76 } 77 | Popular Tags |