added a builder to parse files with eclipse's build mechanisms
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / LRUCacheEnumerator.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 java.util.Enumeration;
14
15 /**
16  *      The <code>LRUCacheEnumerator</code> returns its elements in 
17  *      the order they are found in the <code>LRUCache</code>, with the
18  *      most recent elements first.
19  *
20  *      Once the enumerator is created, elements which are later added 
21  *      to the cache are not returned by the enumerator.  However,
22  *      elements returned from the enumerator could have been closed 
23  *      by the cache.
24  */
25 public class LRUCacheEnumerator implements Enumeration {
26         /**
27          *      Current element;
28          */
29         protected LRUEnumeratorElement fElementQueue;
30
31         public static class LRUEnumeratorElement {
32                 /**
33                  *      Value returned by <code>nextElement()</code>;
34                  */
35                 public Object fValue;
36                 
37                 /**
38                  *      Next element
39                  */
40                 public LRUEnumeratorElement fNext;
41
42                 /**
43                  * Constructor
44                  */
45                 public LRUEnumeratorElement(Object value) {
46                         fValue = value;
47                 }
48         }
49 /**
50  *      Creates a CacheEnumerator on the list of <code>LRUEnumeratorElements</code>.
51  */
52 public LRUCacheEnumerator(LRUEnumeratorElement firstElement) {
53         fElementQueue = firstElement;
54 }
55 /**
56  * Returns true if more elements exist.
57  */
58 public boolean hasMoreElements() {
59         return fElementQueue != null;
60 }
61 /**
62  * Returns the next element.
63  */
64 public Object nextElement() {
65         Object temp = fElementQueue.fValue;
66         fElementQueue = fElementQueue.fNext;
67         return temp;
68 }
69 }