本文整理汇总了Java中java.util.Stack.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.isEmpty方法的具体用法?Java Stack.isEmpty怎么用?Java Stack.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Stack
的用法示例。
在下文中一共展示了Stack.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preorderTraversal
import java.util.Stack; //导入方法依赖的package包/类
public List<Integer> preorderTraversal(TreeNode root) {
TreeNode node = root;
List<Integer> list = new LinkedList<>();
Stack<TreeNode> st = new Stack<>();
while (node != null && !st.isEmpty()) {
while (node != null) {
st.push(node);
list.add(node.val);
node = node.left;
}
if (!st.isEmpty()) {
TreeNode popped = st.pop();
if (popped.right != null) node = popped.right;
}
}
return list;
}
示例2: check
import java.util.Stack; //导入方法依赖的package包/类
/**
* @return if LEFT and RIGHT in @param s matches.
*/
public static boolean check(String s) {
if (s == null) return true;
Stack<Character> stack = new Stack<>();
for (char c : s.toCharArray()) {
if (LEFT.indexOf(c) != -1)
stack.push(c);
else {
int rI = RIGHT.indexOf(c);
// Not a closing parenthesis
if (rI == -1) continue;
// A closing parenthesis is alone
if (stack.isEmpty()) return false;
// Closing parenthesis doesn't match
if (LEFT.indexOf(stack.pop()) != rI)
return false;
}
}
// Has unclosed parentheses
return stack.isEmpty();
}
示例3: processNOTOp
import java.util.Stack; //导入方法依赖的package包/类
private void processNOTOp(Stack<ExpressionNode> expStack, String expS, int index)
throws ParseException {
// When ! comes, the stack can be empty or top ( or top can be some exp like
// a&
// !!.., a!, a&b!, !a! are invalid
if (!expStack.isEmpty()) {
ExpressionNode top = expStack.peek();
if (top.isSingleNode() && top != LeafExpressionNode.OPEN_PARAN_NODE) {
throw new ParseException("Error parsing expression " + expS + " at column : " + index);
}
if (!top.isSingleNode() && ((NonLeafExpressionNode) top).getChildExps().size() != 1) {
throw new ParseException("Error parsing expression " + expS + " at column : " + index);
}
}
expStack.push(new NonLeafExpressionNode(Operator.NOT));
}
示例4: traverseNonEmptyDirectory
import java.util.Stack; //导入方法依赖的package包/类
private void traverseNonEmptyDirectory(
SequenceFile.Writer fileListWriter,
FileStatus sourceStatus,
Path sourcePathRoot,
S3MapReduceCpOptions options)
throws IOException {
FileSystem sourceFS = sourcePathRoot.getFileSystem(getConf());
Stack<FileStatus> pathStack = new Stack<>();
pathStack.push(sourceStatus);
while (!pathStack.isEmpty()) {
for (FileStatus child : getChildren(sourceFS, pathStack.pop())) {
if (child.isFile()) {
LOG.debug("Recording source-path: {} for copy.", sourceStatus.getPath());
CopyListingFileStatus childCopyListingStatus = new CopyListingFileStatus(child);
writeToFileListing(fileListWriter, childCopyListingStatus, sourcePathRoot, options);
}
if (isDirectoryAndNotEmpty(sourceFS, child)) {
LOG.debug("Traversing non-empty source dir: {}", sourceStatus.getPath());
pathStack.push(child);
}
}
}
}
示例5: stopCapture
import java.util.Stack; //导入方法依赖的package包/类
/**
* Stop capturing thread's output and return captured data as a String.
*/
public static String stopCapture() {
Stack<CaptureLog> stack = logs.get();
if (stack == null || stack.isEmpty()) {
return null;
}
CaptureLog log = stack.pop();
if (log == null) {
return null;
}
String capture = log.getCapture();
log.reset();
reuse.push(log);
return capture;
}
示例6: getNearestNodes
import java.util.Stack; //导入方法依赖的package包/类
private BoundedPriorityQueue<Tupel<Double, KDTreeNode<T>>> getNearestNodes(int k, double[] values) {
Stack<KDTreeNode<T>> nodeStack = new Stack<KDTreeNode<T>>();
// first doing initial search for nearest Node
nodeStack = traverseTree(nodeStack, root, values);
// creating data structure for finding k nearest values
BoundedPriorityQueue<Tupel<Double, KDTreeNode<T>>> priorityQueue = new BoundedPriorityQueue<Tupel<Double, KDTreeNode<T>>>(
k);
// now work on stack
while (!nodeStack.isEmpty()) {
// put top element into priorityQueue
KDTreeNode<T> currentNode = nodeStack.pop();
Tupel<Double, KDTreeNode<T>> currentTupel = new Tupel<Double, KDTreeNode<T>>(distance.calculateDistance(
currentNode.getValues(), values), currentNode);
priorityQueue.add(currentTupel);
// now check if far children has to be regarded
if (!priorityQueue.isFilled()
|| priorityQueue.peek().getFirst().doubleValue() > currentNode.getCompareValue()
- values[currentNode.getCompareDimension()]) {
// if needs to be checked, traverse tree to nearest leaf
if (currentNode.hasFarChild(values)) {
traverseTree(nodeStack, currentNode.getFarChild(values), values);
}
}
// go on, until stack is empty
}
return priorityQueue;
}
示例7: transformToPostfixForm
import java.util.Stack; //导入方法依赖的package包/类
private static List<FlowObjectiveCompositionTree> transformToPostfixForm(String policy) {
Stack<Character> stack = new Stack<>();
List<FlowObjectiveCompositionTree> postfix = new ArrayList<>();
for (int i = 0; i < policy.length(); i++) {
Character ch = policy.charAt(i);
if (Character.isDigit(ch)) {
int applicationId = ch - '0';
while (i + 1 < policy.length() && Character.isDigit(policy.charAt(i + 1))) {
i++;
applicationId = applicationId * 10 + policy.charAt(i) - '0';
}
postfix.add(new FlowObjectiveCompositionTree((short) applicationId));
} else if (ch == '(') {
stack.push(ch);
} else if (ch == ')') {
while (stack.peek() != '(') {
postfix.add(new FlowObjectiveCompositionTree(stack.pop()));
}
stack.pop();
} else {
while (!stack.isEmpty() && compareOperatorPriority(stack.peek(), ch)) {
postfix.add(new FlowObjectiveCompositionTree(stack.pop()));
}
stack.push(ch);
}
}
while (!stack.isEmpty()) {
postfix.add(new FlowObjectiveCompositionTree(stack.pop()));
}
return postfix;
}
示例8: assertNoMissingParameters
import java.util.Stack; //导入方法依赖的package包/类
private void assertNoMissingParameters(ArgSpec argSpec, int arity, Stack<String> args) {
if (arity > args.size()) {
if (arity == 1) {
if (argSpec.isOption()) {
throw new MissingParameterException(CommandLine.this, "Missing required parameter for " +
optionDescription("", argSpec, 0));
}
Range indexRange = ((PositionalParamSpec) argSpec).index();
String sep = "";
String names = "";
int count = 0;
List<PositionalParamSpec> positionalParameters = commandSpec.positionalParameters();
for (int i = indexRange.min; i < positionalParameters.size(); i++) {
if (positionalParameters.get(i).arity().min > 0) {
names += sep + positionalParameters.get(i).paramLabel();
sep = ", ";
count++;
}
}
String msg = "Missing required parameter";
Range paramArity = argSpec.arity();
if (paramArity.isVariable) {
msg += "s at positions " + indexRange + ": ";
} else {
msg += (count > 1 ? "s: " : ": ");
}
throw new MissingParameterException(CommandLine.this, msg + names);
}
if (args.isEmpty()) {
throw new MissingParameterException(CommandLine.this, optionDescription("", argSpec, 0) +
" requires at least " + arity + " values, but none were specified.");
}
throw new MissingParameterException(CommandLine.this, optionDescription("", argSpec, 0) +
" requires at least " + arity + " values, but only " + args.size() + " were specified: " + reverse(args));
}
}
示例9: gettoCompount
import java.util.Stack; //导入方法依赖的package包/类
private static Object gettoCompount(Object nbttag, NBTCompound comp){
Stack<String> structure = new Stack<String>();
while (comp.getParent() != null){
structure.add(comp.getName());
comp = comp.getParent();
}
while (!structure.isEmpty()){
nbttag = getSubNBTTagCompound(nbttag, (String)structure.pop());
if (nbttag == null) {
return null;
}
}
return nbttag;
}
示例10: convert
import java.util.Stack; //导入方法依赖的package包/类
public ArrayList<IElementRepresentation<V>> convert(ArrayList<IElementRepresentation<V>> infixEq) {
Stack<IElementRepresentation<V>> stack = new Stack<IElementRepresentation<V>>();
ArrayList<IElementRepresentation<V>> prefixedEq = new ArrayList<IElementRepresentation<V>>();
ArrayList<IElementRepresentation<V>> reversedInfix = new ArrayList<IElementRepresentation<V>>(infixEq);
Collections.reverse(reversedInfix);
for (IElementRepresentation<V> element : reversedInfix) {
if (!element.isOperator()) {
prefixedEq.add(element);
} else {
if (element.isBlockEnd()) {
stack.push(element);
} else if (element.isBlockStart()) {
while (!stack.lastElement().isBlockEnd()) {
prefixedEq.add(stack.pop());
}
stack.pop();
} else {
if (stack.isEmpty()) {
stack.push(element);
} else if (stack.lastElement().getPriority() <= element.getPriority()) {
stack.push(element);
} else {
while (!stack.isEmpty() && stack.lastElement().getPriority() >= element.getPriority()) {
prefixedEq.add(stack.pop());
}
stack.push(element);
}
}
}
}
while (!stack.isEmpty()) {
prefixedEq.add(stack.pop());
}
Collections.reverse(prefixedEq);
return prefixedEq;
}
示例11: dirSize
import java.util.Stack; //导入方法依赖的package包/类
private static long dirSize(File file) {
if (file == null || !file.exists() || !file.isDirectory()) {
return 0;
}
Stack stack = new Stack();
stack.clear();
stack.push(file);
long j = 0;
while (!stack.isEmpty()) {
File[] listFiles = ((File) stack.pop()).listFiles();
long j2 = j;
int i = 0;
while (i < listFiles.length) {
long j3;
if (listFiles[i].isDirectory()) {
stack.push(listFiles[i]);
j3 = j2;
} else {
j3 = listFiles[i].length() + j2;
}
i++;
j2 = j3;
}
j = j2;
}
return j;
}
示例12: judge
import java.util.Stack; //导入方法依赖的package包/类
/**
* 歧义识别
* @param lexemeCell 歧义路径链表头
* @param fullTextLength 歧义路径文本长度
* @return
*/
private LexemePath judge(QuickSortSet.Cell lexemeCell , int fullTextLength){
//候选路径集合
TreeSet<LexemePath> pathOptions = new TreeSet<LexemePath>();
//候选结果路径
LexemePath option = new LexemePath();
//对crossPath进行一次遍历,同时返回本次遍历中有冲突的Lexeme栈
Stack<QuickSortSet.Cell> lexemeStack = this.forwardPath(lexemeCell , option);
//当前词元链并非最理想的,加入候选路径集合
pathOptions.add(option.copy());
//存在歧义词,处理
QuickSortSet.Cell c = null;
while(!lexemeStack.isEmpty()){
c = lexemeStack.pop();
//回滚词元链
this.backPath(c.getLexeme() , option);
//从歧义词位置开始,递归,生成可选方案
this.forwardPath(c , option);
pathOptions.add(option.copy());
}
//返回集合中的最优方案
return pathOptions.first();
}
示例13: findStream
import java.util.Stack; //导入方法依赖的package包/类
/**
* Find PrintStream to which the output must be written to.
*/
protected PrintStream findStream() {
Stack<CaptureLog> stack = logs.get();
if (stack != null && !stack.isEmpty()) {
CaptureLog log = stack.peek();
if (log != null) {
PrintStream ps = log.getStream();
if (ps != null) {
return ps;
}
}
}
return out;
}
示例14: testTree
import java.util.Stack; //导入方法依赖的package包/类
@Test
public void testTree() {
XmasTree x1 = new XmasTree(21, "=", "+");
Stack<String[]> tree = x1.getTreeArray();
while (!tree.isEmpty()) {
String[] branch = tree.pop();
for (String s : branch)
System.out.print(s);
System.out.println("");
}
}
示例15: findJarFileByDirAndSub
import java.util.Stack; //导入方法依赖的package包/类
/**
* 寻找目录和子目录下面的jar
* @param dir 根目录
* @param sub 是否搜索子目录
* @return
*/
public static final Set<File> findJarFileByDirAndSub(File dir)
{
Set<File> files=new HashSet<File>();
if(dir==null)
{
throw new NullArgumentException("dir ==null");
}
if(dir.isFile())
{
throw new IllegalArgumentException("dir "+dir+" is not a dir");
}
if(!dir.exists())
{
throw new IllegalArgumentException("dir "+dir+" not found");
}
Stack<File> dirs = new Stack<File>();
dirs.push(dir);
while (!dirs.isEmpty())
{
File path = dirs.pop();
File[] fs = path.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname)
{
return pathname.isDirectory() || pathname.getName().endsWith(".jar");
}
});
for (File subFile : fs)
{
if (subFile.isDirectory())
{
dirs.push(subFile);
} else
{
files.add(subFile);
}
}
}
return files;
}