Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*    */ package org.jboss.ejb3;
 /*    */ 
 /*    */ import java.util.ArrayList;
 /*    */ import java.util.List;
 /*    */ 
 /*    */ public class ThreadLocalStack<T>
 /*    */ {
 /* 35 */   private ThreadLocal<ArrayList<T>> stack = new ThreadLocal();
 /*    */ 
/*    */   public void push(T obj)
/*    */   {
/* 39 */     ArrayList list = (ArrayList)this.stack.get();
/* 40 */     if (list == null)
/*    */     {
/* 42 */       list = new ArrayList(1);
/* 43 */       this.stack.set(list);
/*    */     }
/* 45 */     list.add(obj);
/*    */   }
/*    */ 
/*    */   public T pop()
/*    */   {
/* 50 */     ArrayList list = (ArrayList)this.stack.get();
/* 51 */     if (list == null)
/*    */     {
/* 53 */       return null;
/*    */     }
/* 55 */     Object rtn = list.remove(list.size() - 1);
/* 56 */     if (list.size() == 0)
/*    */     {
/* 58 */       this.stack.set(null);
/* 59 */       list.clear();
/*    */     }
/* 61 */     return rtn;
/*    */   }
/*    */ 
/*    */   public T get()
/*    */   {
/* 66 */     ArrayList list = (ArrayList)this.stack.get();
/* 67 */     if (list == null)
/*    */     {
/* 69 */       return null;
/*    */     }
/* 71 */     return list.get(list.size() - 1);
/*    */   }
/*    */ 
/*    */   public List<T> getList()
/*    */   {
/* 76 */     return (List)this.stack.get();
/*    */   }
/*    */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/jboss-embedded-all.jar
 * Qualified Name:     org.jboss.ejb3.ThreadLocalStack
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X