new version with WorkingCopy Management
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / BufferCache.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IBuffer;
14 import net.sourceforge.phpdt.internal.core.util.LRUCache;
15
16 /**
17  * An LRU cache of <code>IBuffers</code>.
18  */
19 public class BufferCache extends OverflowingLRUCache {
20 /**
21  * Constructs a new buffer cache of the given size.
22  */
23 public BufferCache(int size) {
24         super(size);
25 }
26 /**
27  * Constructs a new buffer cache of the given size.
28  */
29 public BufferCache(int size, int overflow) {
30         super(size, overflow);
31 }
32 /**
33  * Returns true if the buffer is successfully closed and
34  * removed from the cache, otherwise false.
35  *
36  * <p>NOTE: this triggers an external removal of this buffer
37  * by closing the buffer.
38  */
39 protected boolean close(LRUCacheEntry entry) {
40         IBuffer buffer= (IBuffer) entry._fValue;
41         if (buffer.hasUnsavedChanges()) {
42                 return false;
43         } else {
44                 buffer.close();
45                 return true;
46         }
47 }
48         /**
49          * Returns a new instance of the reciever.
50          */
51         protected LRUCache newInstance(int size, int overflow) {
52                 return new BufferCache(size, overflow);
53         }
54 }