Stack peek - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Stack peek method.

This code example shows how to use the following methods:peek
    public static void exitTag() { 
        currentStack.get().pop();
    } 
     
    public static TagContext current() { 
        return currentStack.get().peek();
    } 
     
    public static TagContext parent() { 
        if(currentStack.get().size() < 2) {
            return null; 
        } 
        return currentStack.get().get(currentStack.get().size()-2);
    } 
     
    public static boolean hasParentTag(String name) {
        for(int i=currentStack.get().size()-1; i>=0; i--) {
            if(name.equals(currentStack.get().get(i).tagName)) {
                return true; 
            } 
9
CodeRank
This code example shows how to use the following methods:peek
 
        return variable;
    } 
 
    public static Expression getInstance() { 
        return instance.get().peek();
    } 
 
    private void pushInstance() { 
        Stack<Expression> foo = instance.get();
        if (foo == null) {
            instance.set(foo = new Stack<Expression>());
        } 
 
        foo.push(this);
    } 
 
    private void popInstance() { 
        Stack<Expression> foo = instance.get();
 
9
CodeRank
This code example shows how to use the following methods:peek, pop
  public void characters(char[] chars, int start, int length) throws SAXException {
    charBuffer.append(chars, start, length);
  } 
 
  public void endElement(String uri, String localName, String qName) throws SAXException {
    Node previousNode = ((Node)nodesStack.peek());
    previousNode.setValue(charBuffer.toString());
    charBuffer.setLength(0);
    Node node = (Node)nodesStack.pop();
    node.complete();
  } 
} 
8
CodeRank
This code example shows how to use the following methods:peek, pop, push, size
  } 
 
  /** Tests pop and peek. */ 
  public void testPopAndPeek() { 
    Stack<String> testStack = createStack();
    int x = testStack.size();
    Object item = testStack.peek();
    assertTrue(testStack.pop() == item);
    assertEquals(x - 1, testStack.size());
  } 
 
  /** Tests push and peek. */ 
  public void testPushAndPeek() { 
    Stack<String> testStack = createStack();
    int x = testStack.size();
    String item = "4";
    testStack.push(item);
    assertEquals(x + 1, testStack.size());
    assertTrue(testStack.peek() == item);
  } 

8
CodeRank
This code example shows how to use the following methods:empty, peek, push
  private void closeIndent() { 
    indent--;
  } 
     
  private void printBeginEnvelope(String tag) {
    if (!compoundStack.empty()) {
      String s = compoundStack.peek();
      if ("struct".equals(s)) {
        putIndent(); 
        stream.print("<member>\n");
        addIndent(); 
        putIndent(); 
        stream.print("<name>"+tag+"</name>\n");
        putIndent(); 
        stream.print("<value>");
      } else if ("vector".equals(s)) {
        stream.print("<value>");
      } else if ("map".equals(s)) {
        stream.print("<value>");
      } 

8
CodeRank
This code example shows how to use the following methods:peek, size
 * 
 * <p>NOTE: nodes are added to the JDOM via the method #basicAddChild such that 
 * the nodes in the newly created JDOM are not fragmented. 
 */ 
protected void addChild(IDOMNode child) {
	if (this.fStack.size() > 0) {
		DOMNode parent = (DOMNode) this.fStack.peek();
		if (this.fBuildingCU || this.fBuildingType) {
			parent.basicAddChild(child);
		} 
	} 
} 
/** 
 * @see IDOMFactory#createCompilationUnit(String, String) 
 */ 
public IDOMCompilationUnit createCompilationUnit(char[] contents, char[] name) {
	return createCompilationUnit(new CompilationUnit(contents, name));
} 
/** 
 * @see IDOMFactory#createCompilationUnit(String, String) 
8
CodeRank
This code example shows how to use the following methods:peek
  } 
 
  protected void manageTypes(final String iFieldName, final Object iFieldValue) {
    if (settings.keepTypes) {
      if (iFieldValue instanceof Long)
        appendType(typesStack.peek(), iFieldName, 'l');
      else if (iFieldValue instanceof Float)
        appendType(typesStack.peek(), iFieldName, 'f');
      else if (iFieldValue instanceof Short)
        appendType(typesStack.peek(), iFieldName, 's');
      else if (iFieldValue instanceof Double)
        appendType(typesStack.peek(), iFieldName, 'd');
      else if (iFieldValue instanceof Date)
        appendType(typesStack.peek(), iFieldName, 't');
      else if (iFieldValue instanceof Byte || iFieldValue instanceof byte[])
        appendType(typesStack.peek(), iFieldName, 'b');
      else if (iFieldValue instanceof BigDecimal)
        appendType(typesStack.peek(), iFieldName, 'c');
      else if (iFieldValue instanceof Set<?>)
        appendType(typesStack.peek(), iFieldName, 'e');
9
CodeRank
This code example shows how to use the following methods:size, empty, peek, get
		screen.setParent( this );
		m_children.add( m_children.size( ), screen );
	} 
 
	private void sendPopEvent() { 
		if( m_screenStack.empty( ) )
		{ 
			return; 
		} 
 
		// Only pop and send events if the stack is not empty 
		int poppedToScreenHandle = getHandle( );
		if( m_screenStack.size( ) >= 2 )
		{ 
			// Get the previous screen before the last one. 
			poppedToScreenHandle = m_screenStack.get(m_screenStack.size()-2).getHandle();
		} 
 
		EventQueue.getDefault( ).postWidgetStackScreenPoppedEvent( 
				getHandle(), 

7
CodeRank
This code example shows how to use the following methods:peek, pop, push
 
	/** 
	 * Returns the SyndElement that comes after the top element of the tagstack. 
	 */ 
	public SyndElement getSecondTag() { 
		SyndElement top = tagstack.pop(); 
		SyndElement second = tagstack.peek(); 
		tagstack.push(top); 
		return second; 
	} 
 
	public SyndElement getThirdTag() { 
		SyndElement top = tagstack.pop(); 
		SyndElement second = tagstack.pop(); 
		SyndElement third = tagstack.peek(); 
		tagstack.push(second); 
		tagstack.push(top); 
		return third; 
	} 
 
7
CodeRank
This code example shows how to use the following methods:empty, peek
            //java -Xrs for example will throw IllegalArgumentException 
        } 
    } 
 
    public void handle(Signal signal) {
        if (handlers.empty()) {
            handlerShell.shutdown();
            Runtime.getRuntime().halt(0);
        } 
        else { 
            SIGINT handler = (SIGINT)handlers.peek();
            handler.handleSIGINT();
        } 
    } 
 
    public static void push(SIGINT handler) {
        handlers.push(handler);
    } 
 
    public static void pop() { 
7
CodeRank

Related Stack peek Questions & Answers:

peek Method Overview
Looks at the object at the top of this stack without removing it from the stack.
See Code Examples for other Java 8 Stack Methods: