KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > dtree > DataTreeLookup


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.core.internal.dtree;
12
13 import org.eclipse.core.runtime.IPath;
14
15 /**
16  * The result of doing a lookup() in a data tree. Uses an instance
17  * pool that assumes no more than POOL_SIZE instance will ever be
18  * needed concurrently. Reclaims and reuses instances on an LRU basis.
19  */

20 public class DataTreeLookup {
21     public IPath key;
22     public boolean isPresent;
23     public Object JavaDoc data;
24     public boolean foundInFirstDelta;
25     private static final int POOL_SIZE = 100;
26     /**
27      * The array of lookup instances available for use.
28      */

29     private static DataTreeLookup[] instancePool;
30     /**
31      * The index of the next available lookup instance.
32      */

33     private static int nextFree = 0;
34     static {
35         instancePool = new DataTreeLookup[POOL_SIZE];
36         //fill the pool with objects
37
for (int i = 0; i < POOL_SIZE; i++) {
38             instancePool[i] = new DataTreeLookup();
39         }
40     }
41
42     /**
43      * Constructors for internal use only. Use factory methods.
44      */

45     private DataTreeLookup() {
46         super();
47     }
48
49     /**
50      * Factory method for creating a new lookup object.
51      */

52     public static DataTreeLookup newLookup(IPath nodeKey, boolean isPresent, Object JavaDoc data) {
53         DataTreeLookup instance;
54         synchronized (instancePool) {
55             instance = instancePool[nextFree];
56             nextFree = ++nextFree % POOL_SIZE;
57         }
58         instance.key = nodeKey;
59         instance.isPresent = isPresent;
60         instance.data = data;
61         instance.foundInFirstDelta = false;
62         return instance;
63     }
64
65     /**
66      * Factory method for creating a new lookup object.
67      */

68     public static DataTreeLookup newLookup(IPath nodeKey, boolean isPresent, Object JavaDoc data, boolean foundInFirstDelta) {
69         DataTreeLookup instance;
70         synchronized (instancePool) {
71             instance = instancePool[nextFree];
72             nextFree = ++nextFree % POOL_SIZE;
73         }
74         instance.key = nodeKey;
75         instance.isPresent = isPresent;
76         instance.data = data;
77         instance.foundInFirstDelta = foundInFirstDelta;
78         return instance;
79     }
80 }
81
Popular Tags