import java.util.Hashtable;
/**
- * Implementation of data structure remembering an Object value by thread. Its purpose is to ease
- * writing multi-threaded algorithms by providing a per thread data structure.
+ * Implementation of data structure remembering an Object value by thread. Its
+ * purpose is to ease writing multi-threaded algorithms by providing a per
+ * thread data structure.
*/
public class PerThreadObject {
private Hashtable internalMap = new Hashtable(3); // synchronized map
-
+
/**
* Answer the current map for this thread
*/
- public Object getCurrent(){
+ public Object getCurrent() {
return this.internalMap.get(Thread.currentThread());
}
-
+
/**
- * Set the map for this current thread - setting to null is equivalent to removing it
+ * Set the map for this current thread - setting to null is equivalent to
+ * removing it
*/
- public void setCurrent(Object current){
- if (current == null){
- this.internalMap.remove(Thread.currentThread());
+ public void setCurrent(Object current) {
+ if (current == null) {
+ this.internalMap.remove(Thread.currentThread());
} else {
this.internalMap.put(Thread.currentThread(), current);
}
}
}
-