| 13 | import java.util.Map; |
| 14 | |
| 15 | public class ThreadLocal<T> { |
| 16 | private static final Object Null = new Object(); |
| 17 | |
| 18 | protected T initialValue() { |
| 19 | return null; |
| 20 | } |
| 21 | |
| 22 | public T get() { |
| 23 | Map<ThreadLocal, Object> map = Thread.currentThread().locals(); |
| 24 | Object o = map.get(this); |
| 25 | if (o == null) { |
| 26 | o = initialValue(); |
| 27 | if (o == null) { |
| 28 | o = Null; |
| 29 | } |
| 30 | map.put(this, o); |
| 31 | } |
| 32 | if (o == Null) { |
| 33 | o = null; |
| 34 | } |
| 35 | return (T) o; |
| 36 | } |
| 37 | |
| 38 | public void set(T value) { |
| 39 | Map<ThreadLocal, Object> map = Thread.currentThread().locals(); |
| 40 | Object o = value; |
| 41 | if (o == null) { |
| 42 | o = Null; |
| 43 | } |
| 44 | map.put(this, o); |
| 45 | } |
| 46 | } |
nothing calls this directly
no outgoing calls
no test coverage detected