astiterator.java

来自「介绍了hibernate的入门有一些基本常用的事例」· Java 代码 · 共 71 行

JAVA
71
字号
// $Id: ASTIterator.java,v 1.5 2005/03/27 00:22:10 pgmjsd Exp $package org.hibernate.hql.ast;import antlr.collections.AST;import java.util.Iterator;import java.util.LinkedList;/** * Depth first iteration of an ANTLR AST. * * @author josh Sep 25, 2004 7:44:39 AM */public class ASTIterator implements Iterator {	private AST next, current;	private LinkedList parents = new LinkedList();	public void remove() {		throw new UnsupportedOperationException( "remove() is not supported" );	}	public boolean hasNext() {		return next != null;	}	public Object next() {		return nextNode();	}	public ASTIterator(AST tree) {		next = tree;		down();	}	public AST nextNode() {		current = next;		if ( next != null ) {			AST nextSibling = next.getNextSibling();			if ( nextSibling == null ) {				next = pop();			}			else {				next = nextSibling;				down();			}		}		return current;	}	private void down() {		while ( next != null && next.getFirstChild() != null ) {			push( next );			next = next.getFirstChild();		}	}	private void push(AST parent) {		parents.addFirst( parent );	}	private AST pop() {		if ( parents.size() == 0 ) {			return null;		}		else {			return ( AST ) parents.removeFirst();		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?