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


Java Stack.size方法代码示例

本文整理汇总了Java中java.util.Stack.size方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.size方法的具体用法?Java Stack.size怎么用?Java Stack.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Stack的用法示例。


在下文中一共展示了Stack.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addFragment

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Adds the fragment as the child of parent, and shows it. If parent already has a child (and
 * possibly sub-children), those are removed.
 *
 * @param parent The parent of the added fragment
 * @param child  The fragment to add
 */
public void addFragment(@NonNull MainFragment parent, @NonNull MainFragment child) {
    for (int tabIndex = 0; tabIndex < mFragments.length; tabIndex++) {
        Stack<MainFragment> tabStack = mFragments[tabIndex];
        for (int level = 0; level < tabStack.size(); level++) {
            MainFragment fragment = tabStack.get(level);
            if (parent.equals(fragment)) {
                int diff = tabStack.size() - tabStack.indexOf(parent) - 1;
                for (int k = 0; k < diff; k++)
                    tabStack.pop();
                tabStack.push(child);
                showFragment(tabIndex, TAB_LEVEL_LAST, false);
                return;
            }
        }
    }
}
 
开发者ID:schul-cloud,项目名称:schulcloud-mobile-android,代码行数:24,代码来源:MainPresenter.java

示例2: LCA

import java.util.Stack; //导入方法依赖的package包/类
public static BinaryTree<Integer> LCA(BinaryTree<Integer> tree, BinaryTree<Integer> node0, BinaryTree<Integer> node1) {
    Stack<BinaryTree<Integer>> zero = dfs(tree, node0, new Stack<>());
    Stack<BinaryTree<Integer>> one = dfs(tree, node1, new Stack<>());

    //ITERATE BOTH STACKS
    while (!zero.isEmpty() && !one.isEmpty()) {
        if (zero.size() > one.size()) {
            //IF STACK ZERO IS BIGGER GET TO SAME LEVEL AS ONE
            zero.pop();
        } else if (zero.size() < one.size()) {
            //IF STACK ONE IS BIGGER GET TO SAME LEVEL AS ZERO
            one.pop();
        } else {
            //IF STACKS ARE EQUAL SEE IF THEY HAVE THE SAME NODE
            if (zero.peek().equals(one.peek()))
                return zero.pop();
            zero.pop();
            one.pop();
        }
    }

    return new BinaryTree<>(0);
}
 
开发者ID:gardncl,项目名称:elements-of-programming-interviews-solutions,代码行数:24,代码来源:ComputeLowestCommonAncestor.java

示例3: pruneScrapViews

import java.util.Stack; //导入方法依赖的package包/类
private void pruneScrapViews() {
    int maxViews = this.mActiveViews.length;
    int viewTypeCount = this.mViewTypeCount;
    Stack<View>[] scrapViews = this.mScrapViews;
    for (int i = 0; i < viewTypeCount; i++) {
        Stack<View> scrapPile = scrapViews[i];
        int size = scrapPile.size();
        int extras = size - maxViews;
        int j = 0;
        int size2 = size - 1;
        while (j < extras) {
            DebugUtil.i("remove scarp views from pruneScrapViews");
            size = size2 - 1;
            PLA_AbsListView.access$1400(this.this$0, (View) scrapPile.remove(size2), false);
            j++;
            size2 = size;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:PLA_AbsListView$RecycleBin.java

示例4: runNumberCounter

import java.util.Stack; //导入方法依赖的package包/类
private void runNumberCounter() {
	long expected = 0;
	int numToCount = new Random().nextInt(1000)+1;
	
	// First do a count with a conventional loop to get the correct number
	for (int i=1; i<=numToCount; i++) { 
		expected += i;
	}
	
	// Now count them again using 'bytecode'
	Stack<Integer> stack = new Stack<Integer>();
	for (int i=1; i<=numToCount; i++) {
		bipush.execute(stack, i); // Push all numbers onto the stack
	}
	while (stack.size() > 1) { 
		iadd.execute(stack); // Add all numbers together until there is just one left
	}
	
	// Make sure the answer calculated with lambdas matches the expected answer
	assertStack(stack, (int) expected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:22,代码来源:TestLambdaMultithreaded.java

示例5: dumpMoreDiagnosticToResolveIssue162700

import java.util.Stack; //导入方法依赖的package包/类
private String dumpMoreDiagnosticToResolveIssue162700(Stack<MarkupItem> fileStack) {
    int index = fileStack.size() - 6;
    if (index < 0) {
        index = 0;
    }
    StringBuilder sb = new StringBuilder("diagnostic dump: ");
    ListIterator<MarkupItem> it = fileStack.listIterator(index);
    while (it.hasNext()) {
        MarkupItem im = it.next();
        sb.append(im.toString()).append(" ");
    }
    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:MarkupAbstractIndenter.java

示例6: getArrayFromMethodDescString

import java.util.Stack; //导入方法依赖的package包/类
private String[] getArrayFromMethodDescString(String sReadableDesc) {
    Stack ParamStack = new Stack();
    StringTokenizer stTok = new StringTokenizer(sReadableDesc, " (,)", false);
    while (stTok.hasMoreTokens()) {
        ParamStack.push(stTok.nextToken());
    }
    int iNumParams = ParamStack.size();
    if (iNumParams == 0) return null;
    String[] asDesc = new String[iNumParams];
    for (int iIndex = 0; iIndex < iNumParams; iIndex++) {
        asDesc[iNumParams - iIndex - 1] = (String) ParamStack.pop();
    }

    return asDesc;
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:16,代码来源:MethodTableModel.java

示例7: buildTree

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Builds a BXT from a postfix expression.
 *
 * @param str the postfix string to change into a tree,
 *            tokens separated by a space.
 * @apiNote Uses a helper stack of TreeNodes.
 */
public void buildTree(String str) {
    if (null == str) return;
    // Create a stack of TreeNodes, since the operator is preceded by two operands.
    Stack<TreeNode<String>> nodeStack = new Stack<>();
    // Instantiate a StringTokenizer object
    // Use StringTokenizer to tokenize the postfix expression
    StringTokenizer tokenizer = new StringTokenizer(str);
    // While the tokenizer still has token, do the following:
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if ("pi".equals(token)) token = "π";
        // If the token is an operator,
        if (isOperator(token)) {
            TreeNode<String> operand = nodeStack.pop();
            // Let the new TreeNode be the root, and
            // push the root operator onto the stack
            if (Operators.isBinary(token)) {
                // Pop two TreeNodes from the stack
                // Form a new inner TreeNode with two children.
                nodeStack.push(new TreeNode<>(token, nodeStack.pop(), operand));
            } else if (Operators.isLeftAssociateUnary(token)) {
                nodeStack.push(new TreeNode<>(token, operand, null));
            } else if (Operators.isRightAssociateUnary(token)) {
                nodeStack.push(new TreeNode<>(token, null, operand));
            } else throw new IllegalStateException(token + " can't be classified");
        } else { // If the token is an operand
            // Create a leaf TreeNode and push onto the stack
            nodeStack.push(new TreeNode<>(token, null, null));
        }
    }
    if (1 != nodeStack.size())
        throw new IllegalStateException("Unused " + toString(nodeStack));
    root = nodeStack.pop();
}
 
开发者ID:ApolloZhu,项目名称:APCSAB,代码行数:42,代码来源:BXT.java

示例8: computeFragment

import java.util.Stack; //导入方法依赖的package包/类
private boolean computeFragment(String text, Stack<Character> stack, int i, char fragment, char mirrFrag, int pos, String classCss) {
    if (text.charAt(i) == fragment) {
        stack.push(fragment);
    } else if (text.charAt(i) == mirrFrag) {
        if (stack.peek() == fragment) {
            stack.pop();

            if (stack.size() == 0) {
                if (codeArea.getStyleOfChar(pos).size() != 0) {
                    String currClass = codeArea.getStyleOfChar(pos).iterator().next();
                    if (pos != lastPosCaret && !currClass.equals(prevClass)) {
                        prevClassSaved = currClass;
                    }
                    prevClass = currClass;
                } else {
                    prevClassSaved = "empty";
                }

                Platform.runLater(() -> codeArea.setStyleClass(pos, pos + 1, classCss));
                Platform.runLater(() -> codeArea.setStyleClass(i, i + 1, classCss));

                return true;
            }
        } else {
            return true;
        }
    }

    return false;
}
 
开发者ID:MrChebik,项目名称:Coconut-IDE,代码行数:31,代码来源:CaretPosition.java

示例9: match

import java.util.Stack; //导入方法依赖的package包/类
private static List<String> match(String input) {
    List<String> list = new ArrayList<String>();
    Stack<Character> stack = new Stack<>();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < input.length(); i++) {
        char c = input.charAt(i);
        if (c == '(') {
            stack.push(c);
            if (stack.size() == 1 && buffer.length() > 0) {
                list.add(buffer.toString());
                buffer = new StringBuffer();
            }else {
                buffer.append(c);
            }
        }else if (c == ')') {
            if (stack.size() > 0) {
                stack.pop();
                if (stack.size() == 0) {
                    if (buffer.length() > 0) {
                        list.add(buffer.toString());
                        buffer = new StringBuffer();
                    }
                }else {
                    buffer.append(c);
                }
            }
        }else {
            buffer.append(c);
        }
    }
    if (buffer.length() > 0) {
        list.add(buffer.toString());
    }
    return list;
}
 
开发者ID:thebeastshop,项目名称:liteFlow,代码行数:36,代码来源:TempConvert.java

示例10: insertionSort

import java.util.Stack; //导入方法依赖的package包/类
public static Stack<Integer> insertionSort(Stack<Integer> st) {
    Stack<Integer> tempSt = new Stack<>();
    while (st.size() != 0) {
        int x = st.pop();
        while (!tempSt.empty() && x < tempSt.peek()) st.push(tempSt.pop());
        tempSt.push(x);
    }
    return tempSt;
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:10,代码来源:StackInsSort.java

示例11: addCycle

import java.util.Stack; //导入方法依赖的package包/类
public void addCycle(Stack<SootMethod> stack, SootMethod sm) {
  // check that there is a cycle with m
  if (stack.search(sm) == -1)
    throw new RuntimeException("error: method not in stack. No cycle!"+ printMethodAndStack(sm, stack));
  
  // check that there are not more than one
  if (stack.lastIndexOf(sm) != stack.indexOf(sm))
    throw new RuntimeException("error: a method cannot be more than twice in the stack! "+ printMethodAndStack(sm, stack));
  
  // two cycles with the same method is not possible since we memorize already computed methods
  //if (cycle2Methods.containsKey(sm))
  //  throw new RuntimeException("error: there already exist a cycle with the same method! "+ printMethodAndStack(sm, stack));
  
  // At this point the stack looks like this:
  // 0  1  2        n-1
  // M1|M2|M3|.....|Mn
  // sm = M3
  // sm is at depth n in the stack, but is not in the stack.
  // Methods M3, M4, ... Mn have to be saved to be later 
  // updated with the correct permission set of M3.
  Set<SootMethod> methods = new HashSet<SootMethod>();
  int startIndex = stack.indexOf(sm);
  for (int i=startIndex+1; i<stack.size(); i++)
    methods.add(stack.elementAt(i));
  
  CycleKey ck = new CycleKey(sm, stack.size()+1); // +1 since sm is not in the stack
  if (cycle2Methods.keySet().contains(ck)){
    cycle2Methods.get(ck).addAll(methods);
  }
  else{
    cycle2Methods.put(ck, methods);
  }
  cache.addAll(methods);
  System.out.println("[cycle] add at depth '"+ stack.size() +"' for method '"+ sm +"'");

}
 
开发者ID:Alexandre-Bartel,项目名称:permission-map,代码行数:37,代码来源:Cycles.java

示例12: processClusteredShortOptions

import java.util.Stack; //导入方法依赖的package包/类
private void processClusteredShortOptions(Collection<ArgSpec> required,
                                          Set<ArgSpec> initialized,
                                          String arg,
                                          Stack<String> args)
        throws Exception {
    String prefix = arg.substring(0, 1);
    String cluster = arg.substring(1);
    boolean paramAttachedToOption = true;
    do {
        if (cluster.length() > 0 && commandSpec.posixOptionsMap().containsKey(cluster.charAt(0))) {
            ArgSpec argSpec = commandSpec.posixOptionsMap().get(cluster.charAt(0));
            Range arity = argSpec.arity();
            String argDescription = "option " + prefix + cluster.charAt(0);
            if (tracer.isDebug()) {tracer.debug("Found option '%s%s' in %s: %s, arity=%s%n", prefix, cluster.charAt(0), arg,
                    argSpec, arity);}
            required.remove(argSpec);
            cluster = cluster.length() > 0 ? cluster.substring(1) : "";
            paramAttachedToOption = cluster.length() > 0;
            if (cluster.startsWith(commandSpec.separator())) {// attached with separator, like -f=FILE or -v=true
                cluster = cluster.substring(commandSpec.separator().length());
                arity = arity.min(Math.max(1, arity.min)); // if key=value, minimum arity is at least 1
            }
            if (arity.min > 0 && !empty(cluster)) {
                if (tracer.isDebug()) {tracer.debug("Trying to process '%s' as option parameter%n", cluster);}
            }
            // arity may be >= 1, or
            // arity <= 0 && !cluster.startsWith(separator)
            // e.g., boolean @Option("-v", arity=0, varargs=true); arg "-rvTRUE", remainder cluster="TRUE"
            if (!empty(cluster)) {
                args.push(cluster); // interpret remainder as option parameter (CAUTION: may be empty string!)
            }
            int argCount = args.size();
            int consumed = applyOption(argSpec, arity, args, initialized, argDescription);
            // if cluster was consumed as a parameter or if this field was the last in the cluster we're done; otherwise continue do-while loop
            if (empty(cluster) || args.isEmpty() || args.size() < argCount) {
                return;
            }
            cluster = args.pop();
        } else { // cluster is empty || cluster.charAt(0) is not a short option key
            if (cluster.length() == 0) { // we finished parsing a group of short options like -rxv
                return; // return normally and parse the next arg
            }
            // We get here when the remainder of the cluster group is neither an option,
            // nor a parameter that the last option could consume.
            if (arg.endsWith(cluster)) {
                args.push(paramAttachedToOption ? prefix + cluster : cluster);
                if (args.peek().equals(arg)) { // #149 be consistent between unmatched short and long options
                    if (tracer.isDebug()) {tracer.debug("Could not match any short options in %s, deciding whether to treat as unmatched option or positional parameter...%n", arg);}
                    if (resemblesOption(arg)) { handleUnmatchedArguments(args.pop()); return; } // #149
                    processPositionalParameter(required, initialized, args);
                    return;
                }
                // remainder was part of a clustered group that could not be completely parsed
                if (tracer.isDebug()) {tracer.debug("No option found for %s in %s%n", cluster, arg);}
                handleUnmatchedArguments(args.pop());
            } else {
                args.push(cluster);
                if (tracer.isDebug()) {tracer.debug("%s is not an option parameter for %s%n", cluster, arg);}
                processPositionalParameter(required, initialized, args);
            }
            return;
        }
    } while (true);
}
 
开发者ID:remkop,项目名称:picocli,代码行数:65,代码来源:CommandLine.java

示例13: getPathWithRelative

import java.util.Stack; //导入方法依赖的package包/类
/**
 * 根据类和相对包名获取最终的包名。
 *
 * @param pathSep   如“/”
 * @param path
 * @param relative  通过“/”分开,如“../util”。“../”表示上一级,“./”表示当前;如果以"/"开头,则结果为该路径。
 * @param separator 最终的分隔符
 * @return
 */
public static String getPathWithRelative(char pathSep, String path, String relative, String separator)
{

    if (relative.startsWith("/"))
    {
        return relative.replace("/", separator);
    }

    String[] origins = StrUtil.split(path, pathSep + "");
    Stack<String> stack = new Stack<>();
    for (String s : origins)
    {
        stack.push(s);
    }
    String[] relatives = relative.split("/");
    for (int i = 0; i < relatives.length; i++)
    {
        String str = relatives[i];
        if ("..".equals(str))
        {
            if (stack.empty())
            {
                throw new RuntimeException("no more upper path!");
            }
            stack.pop();
        } else if (!".".equals(str))
        {
            stack.push(str);
        }
    }
    if (stack.empty())
    {
        return "";
    }
    StringBuilder builder = new StringBuilder();
    int len = stack.size() - 1;
    for (int i = 0; i < len; i++)
    {
        builder.append(stack.get(i)).append(separator);
    }
    builder.append(stack.get(len));
    return builder.toString();
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:53,代码来源:PackageUtil.java

示例14: getNodeForPath

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Messages getTreeNodeForPage(path, onlyIfVisible, shouldCreate,
 * path.length) as long as path is non-null and the length is {@literal >} 0.
 * Otherwise returns null.
 */
private FHTreeStateNode getNodeForPath(TreePath path,
                                         boolean onlyIfVisible,
                                         boolean shouldCreate) {
    if(path != null) {
        FHTreeStateNode      node;

        node = getMapping(path);
        if(node != null) {
            if(onlyIfVisible && !node.isVisible())
                return null;
            return node;
        }
        if(onlyIfVisible)
            return null;

        // Check all the parent paths, until a match is found.
        Stack<TreePath> paths;

        if(tempStacks.size() == 0) {
            paths = new Stack<TreePath>();
        }
        else {
            paths = tempStacks.pop();
        }

        try {
            paths.push(path);
            path = path.getParentPath();
            node = null;
            while(path != null) {
                node = getMapping(path);
                if(node != null) {
                    // Found a match, create entries for all paths in
                    // paths.
                    while(node != null && paths.size() > 0) {
                        path = paths.pop();
                        node = node.createChildFor(path.
                                                   getLastPathComponent());
                    }
                    return node;
                }
                paths.push(path);
                path = path.getParentPath();
            }
        }
        finally {
            paths.removeAllElements();
            tempStacks.push(paths);
        }
        // If we get here it means they share a different root!
        return null;
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:60,代码来源:FixedHeightLayoutCache.java

示例15: generateMaze

import java.util.Stack; //导入方法依赖的package包/类
private void generateMaze() {
    for (int i = 0; i < size; ++i) {
        for (int j = 0; j < size; ++j) {
            array[i][j] = i % 2 != 0 && j % 2 != 0
                    && i < size - 1 && j < size - 1;
        }
    }
    Random random = new Random();
    Stack<Point> stack = new Stack<>();
    stack.push(end);
    while (stack.size() > 0) {
        Point current = stack.peek();
        List<Point> unusedNeighbors = new LinkedList<>();
        //left
        if (current.x > 2) {
            if (!isUsedCell(current.x - 2, current.y)) {
                unusedNeighbors.add(new Point(current.x - 2, current.y));
            }
        }
        //top
        if (current.y > 2) {
            if (!isUsedCell(current.x, current.y - 2)) {
                unusedNeighbors.add(new Point(current.x, current.y - 2));
            }
        }
        //right
        if (current.x < size - 2) {
            if (!isUsedCell(current.x + 2, current.y)) {
                unusedNeighbors.add(new Point(current.x + 2, current.y));
            }
        }
        //bottom
        if (current.y < size - 2) {
            if (!isUsedCell(current.x, current.y + 2)) {
                unusedNeighbors.add(new Point(current.x, current.y + 2));
            }
        }
        if (unusedNeighbors.size() > 0) {
            int rnd = random.nextInt(unusedNeighbors.size());
            Point direction = unusedNeighbors.get(rnd);
            int diffX = (direction.x - current.x) / 2;
            int diffY = (direction.y - current.y) / 2;
            array[current.y + diffY][current.x + diffX] = true;
            stack.push(direction);
        } else {
            if (bestScore < stack.size()) {
                bestScore = stack.size();
                start = current;
            }
            stack.pop();
        }
    }
}
 
开发者ID:gordinmitya,项目名称:AndroidMaze,代码行数:54,代码来源:Maze.java


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