/*
 * JBoss, Home of Professional Open Source
 * Copyright 2010, Red Hat Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.as.naming.util;

import java.util.EmptyStackException;
import java.util.Stack;

/**
 *
 * @author Stuart Douglas
 *
 */
public class ThreadLocalStack<E> {

    private final ThreadLocal<Stack<E>> stack = new ThreadLocal<Stack<E>>();

    public void push(E item) {
        Stack<E> st = stack.get();
        if (st == null) {
            st = new Stack<E>();
            stack.set(st);
        }
        st.push(item);
    }

    public E peek() {
        Stack<E> st = stack.get();
        if (st == null) {
            return null;
        }
        return st.peek();
    }

    public E pop() {
        Stack<E> st = stack.get();
        if (st == null) {
            throw new EmptyStackException();
        }
        E val = st.pop();
        if (st.isEmpty()) {
            stack.remove();
        }
        return val;
    }

}

@@ -1065,51 +1065,80 @@
 til.
-EmptyStackException;%0Aimport java.util.Stack
+ArrayDeque;%0Aimport java.util.Deque;%0Aimport java.util.EmptyStackException
 ;%0A%0A/
@@ -1246,23 +1246,23 @@
 cal%3C
-Stack%3CE%3E%3E stack
+Deque%3CE%3E%3E deque
  = n
@@ -1276,21 +1276,21 @@
 adLocal%3C
-Stack
+Deque
 %3CE%3E%3E();%0A
@@ -1321,37 +1321,37 @@
 item) %7B%0A        
-Stack
+Deque
 %3CE%3E st = stack.g
@@ -1335,37 +1335,37 @@
   Deque%3CE%3E st = 
-stack
+deque
 .get();%0A        
@@ -1403,21 +1403,26 @@
 t = new 
-Stack
+ArrayDeque
 %3CE%3E();%0A 
@@ -1432,21 +1432,21 @@
         
-stack
+deque
 .set(st)
@@ -1509,37 +1509,37 @@
 eek() %7B%0A        
-Stack
+Deque
 %3CE%3E st = stack.g
@@ -1523,37 +1523,37 @@
   Deque%3CE%3E st = 
-stack
+deque
 .get();%0A        
@@ -1667,21 +1667,21 @@
         
-Stack
+Deque
 %3CE%3E st =
@@ -1681,21 +1681,21 @@
 E%3E st = 
-stack
+deque
 .get();%0A
@@ -1845,13 +1845,13 @@
     
-stack
+deque
 .rem

Change ThreadLocalStack to use a deque