A massive organize imports and formatting of the sources using default Eclipse code...
[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         /**
28          * Constructs a new buffer cache of the given size.
29          */
30         public BufferCache(int size, int overflow) {
31                 super(size, overflow);
32         }
33
34         /**
35          * Returns true if the buffer is successfully closed and removed from the
36          * cache, otherwise false.
37          * 
38          * <p>
39          * NOTE: this triggers an external removal of this buffer by closing the
40          * buffer.
41          */
42         protected boolean close(LRUCacheEntry entry) {
43                 IBuffer buffer = (IBuffer) entry._fValue;
44                 if (buffer.hasUnsavedChanges()) {
45                         return false;
46                 } else {
47                         buffer.close();
48                         return true;
49                 }
50         }
51
52         /**
53          * Returns a new instance of the reciever.
54          */
55         protected LRUCache newInstance(int size, int overflow) {
56                 return new BufferCache(size, overflow);
57         }
58 }