当前位置: 首页>>代码示例>>Java>>正文


Java Stack.isEmpty方法代码示例

本文整理汇总了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;
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:18,代码来源:TraversalIterative.java

示例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();
}
 
开发者ID:ApolloZhu,项目名称:APCSAB,代码行数:24,代码来源:ParenMatch_Shell.java

示例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));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:ExpressionParser.java

示例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);
      }
    }
  }
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:25,代码来源:SimpleCopyListing.java

示例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;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:18,代码来源:SystemLogHandler.java

示例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;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:31,代码来源:KDTree.java

示例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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:36,代码来源:FlowObjectiveCompositionUtil.java

示例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));
    }
}
 
开发者ID:remkop,项目名称:picocli,代码行数:37,代码来源:CommandLine.java

示例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;
}
 
开发者ID:dracnis,项目名称:VanillaPlus,代码行数:15,代码来源:MinecraftUtils.java

示例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;
}
 
开发者ID:MickaelAlvarez,项目名称:InfixToObject,代码行数:40,代码来源:InfixToPrefix.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:28,代码来源:ResUtil.java

示例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();

}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:34,代码来源:IKArbitrator.java

示例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;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:17,代码来源:SystemLogHandler.java

示例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("");
    }
}
 
开发者ID:nikmanG,项目名称:DailyProgrammer,代码行数:16,代码来源:TreeTest.java

示例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;
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:47,代码来源:FileUtil.java


注:本文中的java.util.Stack.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。