1 17 18 package org.apache.geronimo.core.service; 19 20 import java.util.LinkedList ; 21 22 28 public class StackThreadLocal { 29 private final ThreadLocal threadLocal = new ThreadLocal () { 30 protected Object initialValue() { 31 return new LinkedList (); 32 } 33 }; 34 35 public void push(Object value) { 36 if (value == null) { 37 throw new IllegalArgumentException ("Value is null"); 38 } 39 ((LinkedList ) threadLocal.get()).addFirst(value); 40 } 41 42 public Object pop() { 43 LinkedList linkedList = ((LinkedList ) threadLocal.get()); 44 if (linkedList.isEmpty()) { 45 return null; 46 } 47 return linkedList.removeFirst(); 48 } 49 50 public Object peek() { 51 LinkedList linkedList = ((LinkedList ) threadLocal.get()); 52 if (linkedList.isEmpty()) { 53 return null; 54 } 55 return linkedList.getFirst(); 56 } 57 } 58 | Popular Tags |