Java 类java.util.EmptyStackException 实例源码

项目:alfresco-repository    文件:ResetPasswordServiceImplTest.java   
@AfterClass
public static void cleanUp()
{
    resetPasswordService.setSendEmailAsynchronously(Boolean.valueOf(
                globalProperties.getProperty("system.reset-password.sendEmailAsynchronously")));
    resetPasswordService.setDefaultEmailSender((String) globalProperties.get("system.email.sender.default"));

    AuthenticationUtil.setRunAsUserSystem();
    transactionHelper.doInTransaction(() ->
    {
        personService.deletePerson(testPerson.userName);
        return null;
    });

    // Restore authentication to pre-test state.
    try
    {
        AuthenticationUtil.popAuthentication();
    }
    catch(EmptyStackException e)
    {
        // Nothing to do.
    }
}
项目:xmlpullparserutil    文件:PairStack.java   
public synchronized boolean popIfFrist(T t) {

        if (tStack.peek().equals(t)) {
            T temp = tStack.pop();
            try {
                rStack.pop();

                return true;
            } catch (EmptyStackException e) {
                tStack.push(temp);
                return false;
            }
        }

        return false;
    }
项目:tomcat7    文件:SystemLogHandler.java   
/**
 * Start capturing thread's output.
 */
public static void startCapture() {
    CaptureLog log = null;
    if (!reuse.isEmpty()) {
        try {
            log = reuse.pop();
        } catch (EmptyStackException e) {
            log = new CaptureLog();
        }
    } else {
        log = new CaptureLog();
    }
    Stack<CaptureLog> stack = logs.get();
    if (stack == null) {
        stack = new Stack<CaptureLog>();
        logs.set(stack);
    }
    stack.push(log);
}
项目:tomcat7    文件:Digester.java   
/**
 * Process notification that a namespace prefix is going out of scope.
 *
 * @param prefix Prefix that is going out of scope
 *
 * @exception SAXException if a parsing error is to be reported
 */
@Override
public void endPrefixMapping(String prefix) throws SAXException {

    if (saxLog.isDebugEnabled()) {
        saxLog.debug("endPrefixMapping(" + prefix + ")");
    }

    // Deregister this prefix mapping
    ArrayStack<String> stack = namespaces.get(prefix);
    if (stack == null) {
        return;
    }
    try {
        stack.pop();
        if (stack.empty())
            namespaces.remove(prefix);
    } catch (EmptyStackException e) {
        throw createSAXException("endPrefixMapping popped too many times");
    }

}
项目:tomcat7    文件:Digester.java   
/**
 * <p>Pops (gets and removes) the top object from the stack with the given name.</p>
 *
 * <p><strong>Note:</strong> a stack is considered empty
 * if no objects have been pushed onto it yet.</p>
 * 
 * @param stackName the name of the stack from which the top value is to be popped
 * @return the top <code>Object</code> on the stack or or null if the stack is either 
 * empty or has not been created yet
 * @throws EmptyStackException if the named stack is empty
 *
 * @since 1.6
 */
public Object pop(String stackName) {
    Object result = null;
    ArrayStack<Object> namedStack = stacksByName.get(stackName);
    if (namedStack == null) {
        if (log.isDebugEnabled()) {
            log.debug("Stack '" + stackName + "' is empty");
        }
        throw new EmptyStackException();

    } else {

        result = namedStack.pop();
    }
    return result;
}
项目:Phoenicia    文件:HUDManager.java   
/**
 * Hide the currently displayed HUD, and show the one below it on the stack
 */
public synchronized void pop() {
    Debug.d("Popping one off the HUD stack");
    try {
        PhoeniciaHUD previousHUD = this.hudStack.pop();
        if (previousHUD != null) {
            this.currentHUD.hide();
            this.currentHUD.close();
            this.setHudLayer(previousHUD);
            this.currentHUD = previousHUD;
            previousHUD.show();
        }
    } catch (EmptyStackException e) {
        Debug.d("Nothing to pop off the stack");
        return;
    }
}
项目:lams    文件:Digester.java   
/**
 * <p>Gets the top object from the stack with the given name.
 * This method does not remove the object from the stack.
 * </p>
 * <p><strong>Note:</strong> a stack is considered empty
 * if no objects have been pushed onto it yet.</p>
 *
 * @param stackName the name of the stack to be peeked
 * @return the top <code>Object</code> on the stack or null if the stack is either 
 * empty or has not been created yet
 * @throws EmptyStackException if the named stack is empty 
 *
 * @since 1.6
 */
public Object peek(String stackName) {
    Object result = null;
    ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName);
    if (namedStack == null ) {
        if (log.isDebugEnabled()) {
            log.debug("Stack '" + stackName + "' is empty");
        }        
        throw new EmptyStackException();

    } else {

        result = namedStack.peek();
    }
    return result;
}
项目:cci    文件:SetOfStacksFull.java   
@Override
public T popAt(final int stackNumber) {
    if (stacks.isEmpty()) {
        throw new EmptyStackException();
    }

    if (stacks.size() <= stackNumber - 1) {
        throw new IllegalArgumentException(
                "Stack #" + stackNumber + " does not exists"
        );
    }

    T item = stacks.get(stackNumber).pop();

    if (stacks.get(stackNumber).isEmpty()) {
        stacks.remove(stackNumber);
    }

    return item;
}
项目:openjdk-jdk10    文件:DelegateImpl.java   
public POA poa(Servant self)
{
    try {
        return (POA)orb.peekInvocationInfo().oa();
    } catch (EmptyStackException exception){
        POA returnValue = factory.lookupPOA(self);
        if (returnValue != null) {
            return returnValue;
        }

        throw wrapper.noContext( exception ) ;
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ArrayStack.java   
/**
 * Returns the top item off of this stack without removing it.
 *
 * @return the top item on the stack
 * @throws EmptyStackException  if the stack is empty
 */
public E peek() throws EmptyStackException {
    int n = size();
    if (n <= 0) {
        throw new EmptyStackException();
    } else {
        return get(n - 1);
    }
}
项目:manifold    文件:Stack.java   
public T pop()
{
  if( isEmpty() )
  {
    throw new EmptyStackException();
  }
  return _list.remove( size() - 1 );
}
项目:incubator-netbeans    文件:ArrayListStack.java   
public Object peek() {
int len = size();

if (len == 0)
    throw new EmptyStackException();
return get(len - 1);
   }
项目:Java-Algorithms-Learning    文件:BagsQueuesStacks.java   
/**
* 从该Queue中取出元素, 并把该元素删除
* @return 最早进Queue的元素
*/
Item dequeue() throws EmptyStackException {
    if (sizeFirstQ == 0) {
        if (sizeSecondQ > 0) {
            //如果firstQ空而secondQ非空, 就将这两个Stack互换
            Stack<Item> tmpQ = firstQ;
            firstQ = secondQ;
            secondQ = tmpQ;
            sizeFirstQ = sizeSecondQ;
            sizeSecondQ = 0;
        } else if (sizeS > 0 && sizeS < maxCapacity) {
            //如果s中元素不足maxCapacity, 就把所以的元素移进firstQ
            while (!s.isEmpty()) {
                sizeS--;
                firstQ.push(s.pop());
                sizeFirstQ++;
            }
        } else if(sizeS >= maxCapacity) {
            //如果s中元素大于maxCapacity, 就把maxCapacity个元素移进firstQ
            for (int i = 0; i < maxCapacity; i++) {
                sizeS--;
                firstQ.push(s.pop());
                sizeFirstQ++;
            }
        } else {
            throw new EmptyStackException();
        }

    } 

    //如果firstQ有元素那就从firstQ中取元素出来
    sizeFirstQ--;
    return firstQ.pop();
}
项目:EatDubbo    文件:Stack.java   
/**
 * pop.
 * 
 * @return the last element.
 */
public E pop()
{
    if( mSize == 0 )
        throw new EmptyStackException();
    return mElements.set(--mSize, null);
}
项目:openjdk-jdk10    文件:ObjectStack.java   
/**
 * Sets an object at a the top of the statck
 *
 *
 * @param val object to set at the top
 * @throws  EmptyStackException  if this stack is empty.
 */
public void setTop(Object val)
{
  try {
    m_map[m_firstFree - 1] = val;
  }
  catch (ArrayIndexOutOfBoundsException e)
  {
    throw new EmptyStackException();
  }
}
项目:apache-tomcat-7.0.73-with-comment    文件:Digester.java   
/**
 * <p>Pop the top object off of the parameters stack, and return it.  If there are
 * no objects on the stack, return <code>null</code>.</p>
 *
 * <p>The parameters stack is used to store <code>CallMethodRule</code> parameters. 
 * See {@link #params}.</p>
 */
public Object popParams() {

    try {
        if (log.isTraceEnabled()) {
            log.trace("Popping params");
        }
        return (params.pop());
    } catch (EmptyStackException e) {
        log.warn("Empty stack (returning null)");
        return (null);
    }

}
项目:cljbuck    文件:LexFile.java   
public StateFunc func(final Lexable l) {
    if (l.accept(Symbols.WHITESPACE)) {
        l.acceptRun(Symbols.WHITESPACE);
        l.ignore();
    }

    final char ch = l.next();

    try {
        if ('(' == ch) {
            l.push(ch);
            l.emit(itemLeftParen);
            return lexForm;
        } else if (')' == ch) {
            final char last = l.pop();

            if ('(' != last) {
                l.errorf("want (, got %s", last);
                return null;
            }

            return this;
        } else if (';' == ch) {
            return lexComment;
        } else if (EOF == ch) {
            l.close();
            l.emit(itemEOF);
            return null;
        }

        l.errorf("unexpected character found %s", ch);
        return null;
    } catch (EmptyStackException esex) {
        l.errorf("unmatched paren found %s", ch);
        return null;
    }
}
项目:tomcat7    文件:ArrayStack.java   
/**
 * Returns the top item off of this stack without removing it.
 *
 * @return the top item on the stack
 * @throws EmptyStackException  if the stack is empty
 */
public E peek() throws EmptyStackException {
    int n = size();
    if (n <= 0) {
        throw new EmptyStackException();
    } else {
        return get(n - 1);
    }
}
项目:tomcat7    文件:ArrayStack.java   
/**
 * Pops the top item off of this stack and return it.
 *
 * @return the top item on the stack
 * @throws EmptyStackException  if the stack is empty
 */
public E pop() throws EmptyStackException {
    int n = size();
    if (n <= 0) {
        throw new EmptyStackException();
    } else {
        return remove(n - 1);
    }
}
项目:tomcat7    文件:Digester.java   
/**
 * Return the currently mapped namespace URI for the specified prefix,
 * if any; otherwise return <code>null</code>.  These mappings come and
 * go dynamically as the document is parsed.
 *
 * @param prefix Prefix to look up
 */
public String findNamespaceURI(String prefix) {

    ArrayStack<String> stack = namespaces.get(prefix);
    if (stack == null) {
        return (null);
    }
    try {
        return stack.peek();
    } catch (EmptyStackException e) {
        return (null);
    }

}
项目:tomcat7    文件:Digester.java   
/**
 * Return the top object on the stack without removing it.  If there are
 * no objects on the stack, return <code>null</code>.
 */
public Object peek() {

    try {
        return (stack.peek());
    } catch (EmptyStackException e) {
        log.warn("Empty stack (returning null)");
        return (null);
    }

}
项目:tomcat7    文件:Digester.java   
/**
 * Return the n'th object down the stack, where 0 is the top element
 * and [getCount()-1] is the bottom element.  If the specified index
 * is out of range, return <code>null</code>.
 *
 * @param n Index of the desired element, where 0 is the top of the stack,
 *  1 is the next element down, and so on.
 */
public Object peek(int n) {

    try {
        return (stack.peek(n));
    } catch (EmptyStackException e) {
        log.warn("Empty stack (returning null)");
        return (null);
    }

}
项目:tomcat7    文件:Digester.java   
/**
 * Pop the top object off of the stack, and return it.  If there are
 * no objects on the stack, return <code>null</code>.
 */
public Object pop() {

    try {
        return (stack.pop());
    } catch (EmptyStackException e) {
        log.warn("Empty stack (returning null)");
        return (null);
    }

}
项目:apache-tomcat-7.0.73-with-comment    文件:Digester.java   
/**
 * Return the n'th object down the stack, where 0 is the top element
 * and [getCount()-1] is the bottom element.  If the specified index
 * is out of range, return <code>null</code>.
 *
 * @param n Index of the desired element, where 0 is the top of the stack,
 *  1 is the next element down, and so on.
 */
public Object peek(int n) {

    try {
        return (stack.peek(n));
    } catch (EmptyStackException e) {
        log.warn("Empty stack (returning null)");
        return (null);
    }

}
项目:manifold    文件:Stack.java   
public T getBase()
{
  if( isEmpty() )
  {
    throw new EmptyStackException();
  }
  return _list.get( 0 );
}
项目:lazycat    文件:Digester.java   
/**
 * <p>
 * Pop the top object off of the parameters stack, and return it. If there
 * are no objects on the stack, return <code>null</code>.
 * </p>
 *
 * <p>
 * The parameters stack is used to store <code>CallMethodRule</code>
 * parameters. See {@link #params}.
 * </p>
 */
public Object popParams() {

    try {
        if (log.isTraceEnabled()) {
            log.trace("Popping params");
        }
        return (params.pop());
    } catch (EmptyStackException e) {
        log.warn("Empty stack (returning null)");
        return (null);
    }

}
项目:tomcat7    文件:Digester.java   
/**
 * <p>Pop the top object off of the parameters stack, and return it.  If there are
 * no objects on the stack, return <code>null</code>.</p>
 *
 * <p>The parameters stack is used to store <code>CallMethodRule</code> parameters. 
 * See {@link #params}.</p>
 */
public Object popParams() {

    try {
        if (log.isTraceEnabled()) {
            log.trace("Popping params");
        }
        return (params.pop());
    } catch (EmptyStackException e) {
        log.warn("Empty stack (returning null)");
        return (null);
    }

}
项目:dubbo2    文件:Stack.java   
/**
 * pop.
 * 
 * @return the last element.
 */
public E pop()
{
    if( mSize == 0 )
        throw new EmptyStackException();
    return mElements.set(--mSize, null);
}
项目:HCFCore    文件:ArrayStack.java   
/**
 * Pops the top item off of this stack and return it.
 *
 * @return the top item on the stack
 * @throws EmptyStackException  if the stack is empty
 */
public E pop() throws EmptyStackException {
    final int n = size();
    if (n <= 0) {
        throw new EmptyStackException();
    } else {
        return remove(n - 1);
    }
}
项目:LivroJavaComoProgramar10Edicao    文件:StackTest.java   
public static void main(String[] args)
{
   Stack<Number> stack = new Stack<>(); // create a Stack

   // use push method
   stack.push(12L); // push long value 12L
   System.out.println("Pushed 12L");
   printStack(stack);
   stack.push(34567); // push int value 34567
   System.out.println("Pushed 34567");
   printStack(stack);
   stack.push(1.0F); // push float value 1.0F
   System.out.println("Pushed 1.0F");
   printStack(stack);
   stack.push(1234.5678); // push double value 1234.5678
   System.out.println("Pushed 1234.5678 ");
   printStack(stack);

   // remove items from stack
   try 
   {
      Number removedObject = null;

      // pop elements from stack
      while (true) 
      {
         removedObject = stack.pop(); // use pop method
         System.out.printf("Popped %s%n", removedObject);
         printStack(stack);
      } 
   } 
   catch (EmptyStackException emptyStackException) 
   {
      emptyStackException.printStackTrace();
   } 
}
项目:org.alloytools.alloy    文件:ArrayStack.java   
/**
 * @see kodkod.util.collections.Stack#pop()
 */
public T pop() {
    if (empty())
        throw new EmptyStackException();
    final T top = elems[--size];
    elems[size] = null;
    return top;
}
项目:lazycat    文件:ArrayStack.java   
/**
 * Pops the top item off of this stack and return it.
 *
 * @return the top item on the stack
 * @throws EmptyStackException
 *             if the stack is empty
 */
public E pop() throws EmptyStackException {
    int n = size();
    if (n <= 0) {
        throw new EmptyStackException();
    } else {
        return remove(n - 1);
    }
}
项目:openjdk-jdk10    文件:RepositoryIdCache.java   
public final synchronized RepositoryId popId() {

        try {
            return (RepositoryId)super.pop();
        }
        catch(EmptyStackException e) {
            increasePool(5);
            return (RepositoryId)super.pop();
        }

    }
项目:pzubaha    文件:StackList.java   
/**
 * Removes the object at the top of this stack and returns that.
 * @return the object at the top of this stack.
 * @throws EmptyStackException if the stack is empty.
 */
public E pop() {
    if (isEmpty()) {
        throw new EmptyStackException();
    }
    return remove(size() - 1);
}
项目:alfresco-remote-api    文件:TestPeople.java   
@After
public void tearDown()
{
    // Restore authentication to pre-test state.
    try
    {
        AuthenticationUtil.popAuthentication();
    }
    catch(EmptyStackException e)
    {
        // Nothing to do.
    }
}
项目:pzubaha    文件:StackListTest.java   
/**
 * Test pop method's.
 */
@Test(expected = EmptyStackException.class)
public void whenPopThenReturnedAndRemovedLast() {
    assertThat(testedStack.peek(), is(third));
    assertThat(testedStack.pop(), is(third));
    assertThat(testedStack.pop(), is(second));
    assertThat(testedStack.peek(), is(first));
    assertThat(testedStack.pop(), is(first));
    testedStack.pop();
}
项目:lams    文件:AbstractErrors.java   
@Override
public void popNestedPath() throws IllegalArgumentException {
    try {
        String formerNestedPath = this.nestedPathStack.pop();
        doSetNestedPath(formerNestedPath);
    }
    catch (EmptyStackException ex) {
        throw new IllegalStateException("Cannot pop nested path: no nested path on stack");
    }
}
项目:lams    文件:ArrayStack.java   
/**
 * Returns the top item off of this stack without removing it.
 *
 * @return the top item on the stack
 * @throws EmptyStackException  if the stack is empty
 */
public Object peek() throws EmptyStackException {
    int n = size();
    if (n <= 0) {
        throw new EmptyStackException();
    } else {
        return get(n - 1);
    }
}
项目:lams    文件:ArrayStack.java   
/**
 * Pops the top item off of this stack and return it.
 *
 * @return the top item on the stack
 * @throws EmptyStackException  if the stack is empty
 */
public Object pop() throws EmptyStackException {
    int n = size();
    if (n <= 0) {
        throw new EmptyStackException();
    } else {
        return remove(n - 1);
    }
}
项目:lams    文件:Digester.java   
/**
 * Return the currently mapped namespace URI for the specified prefix,
 * if any; otherwise return <code>null</code>.  These mappings come and
 * go dynamically as the document is parsed.
 *
 * @param prefix Prefix to look up
 */
public String findNamespaceURI(String prefix) {

    ArrayStack stack = (ArrayStack) namespaces.get(prefix);
    if (stack == null) {
        return (null);
    }
    try {
        return ((String) stack.peek());
    } catch (EmptyStackException e) {
        return (null);
    }

}