Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / util / PerThreadObject.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.util;
12
13 import java.util.Hashtable;
14
15 /**
16  * Implementation of data structure remembering an Object value by thread. Its purpose is to ease
17  * writing multi-threaded algorithms by providing a per thread data structure.
18  */
19 public class PerThreadObject {
20
21         private Hashtable internalMap = new Hashtable(3); // synchronized map
22         
23         /**
24          * Answer the current map for this thread
25          */
26         public Object getCurrent(){
27                 return this.internalMap.get(Thread.currentThread());
28         }
29         
30         /**
31          * Set the map for this current thread - setting to null is equivalent to removing it
32          */
33         public void setCurrent(Object current){
34                 if (current == null){
35                         this.internalMap.remove(Thread.currentThread());                        
36                 } else {
37                         this.internalMap.put(Thread.currentThread(), current);
38                 }
39         }
40 }
41