KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > LRUCacheEnumerator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import java.util.Enumeration JavaDoc;
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 JavaDoc {
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 JavaDoc fValue;
36         
37         /**
38          * Next element
39          */

40         public LRUEnumeratorElement fNext;
41
42         /**
43          * Constructor
44          */

45         public LRUEnumeratorElement(Object JavaDoc 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 JavaDoc nextElement() {
65     Object JavaDoc temp = fElementQueue.fValue;
66     fElementQueue = fElementQueue.fNext;
67     return temp;
68 }
69 }
70
Popular Tags