Java Code Examples for java.util.Stack#push()
The following examples show how to use
java.util.Stack#push() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallGraphTest.java From vasco with GNU Lesser General Public License v2.1 | 23 votes |
public static void printCallSiteStats(PointsToAnalysis pta) throws FileNotFoundException { // Get context-transition table ContextTransitionTable<SootMethod,Unit,PointsToGraph> ctt = pta.getContextTransitionTable(); Map<Context<SootMethod,Unit,PointsToGraph>,Set<CallSite<SootMethod,Unit,PointsToGraph>>> callSitesWithinContexts = ctt.getCallSitesOfContexts(); Map<CallSite<SootMethod,Unit,PointsToGraph>,Map<SootMethod,Context<SootMethod,Unit,PointsToGraph>>> transitions = ctt.getTransitions(); Set<CallSite<SootMethod,Unit,PointsToGraph>> defaultCallSites = ctt.getDefaultCallSites(); // Initialise output stream PrintWriter csv = new PrintWriter(outputDirectory + "/sites.csv"); csv.println("FcpaEdges, SparkEdges, Context, CallSite"); // The visited set Set<Context<SootMethod,Unit,PointsToGraph>> visited = new HashSet<Context<SootMethod,Unit,PointsToGraph>>(); // Maintain a stack of contexts to process Stack<Context<SootMethod,Unit,PointsToGraph>> stack = new Stack<Context<SootMethod,Unit,PointsToGraph>>(); // Initialise it with the main context Context<SootMethod,Unit,PointsToGraph> source = pta.getContexts(Scene.v().getMainMethod()).get(0); stack.push(source); // Now recursively (using stacks) mark reachable contexts while (stack.isEmpty() == false) { // Get the next item to process source = stack.pop(); // Add successors if (callSitesWithinContexts.containsKey(source)) { // The above check is there because methods with no calls have no entry for (CallSite<SootMethod,Unit,PointsToGraph> callSite : callSitesWithinContexts.get(source)) { // My edges are -1 for "default" sites, and whatever the CTT has otherwise int myEdges = defaultCallSites.contains(callSite) ? -1 : transitions.get(callSite).size(); // Get SPARK's edges from the Soot call graph int sparkEdges = getSparkExplicitEdges(callSite.getCallNode()).size(); // Log this csv.println(myEdges + ", " + sparkEdges + ", " + source + ", " + "\"" + callSite.getCallNode() + "\""); if (myEdges > 0) { for (SootMethod method : transitions.get(callSite).keySet()) { Context<SootMethod,Unit,PointsToGraph> target = transitions.get(callSite).get(method); // Don't process the same element twice if (visited.contains(target) == false) { // Mark reachable visited.add(target); // Add it's successors also later stack.push(target); } } } else if (myEdges == -1) { // Default call-site, so mark reachable closure as "dirty" markDirty(callSite.getCallNode()); } } } } // Close the CSV file csv.close(); }
Example 2
Source File: StackUnitTest.java From tutorials with MIT License | 22 votes |
@Test public void whenRemoveAllElementsIsInvoked_thenAllElementsAreRemoved() { Stack<Integer> intStack = new Stack<>(); intStack.push(5); intStack.push(7); intStack.removeAllElements(); assertTrue(intStack.isEmpty()); }
Example 3
Source File: OperationContext.java From eventapis with Apache License 2.0 | 21 votes |
private Context getOrCreateContext() { Stack<Context> contexts = operationContext.get(); if (contexts.empty()) contexts.push(new Context()); return contexts.peek(); }
Example 4
Source File: Question5.java From offer with Apache License 2.0 | 20 votes |
/** * 创建一个新链表,每遍历一个非空节点,则在新链表一个同值的新节点 * @param head */ public void printNodePlus(Node head) { if (head == null) { return; } Stack<Node> stack = new Stack<>(); while (head != null) { stack.push(head); head = head.next; } while (stack.size()!=0) { System.out.println(stack.pop().val); } }
Example 5
Source File: CLSFractal.java From jdk8u-jdk with GNU General Public License v2.0 | 19 votes |
void render(Graphics g, String path) { Stack<CLSTurtle> turtleStack = new Stack<CLSTurtle>(); CLSTurtle turtle; if (g == null) { Xmin = 1E20f; Ymin = 1E20f; Xmax = -1E20f; Ymax = -1E20f; turtle = new CLSTurtle(startAngle, 0, 0, 0, 0, 1, 1); } else { float frwidth = Xmax - Xmin; if (frwidth == 0) { frwidth = 1; } float frheight = Ymax - Ymin; if (frheight == 0) { frheight = 1; } float xscale = (getSize().width - border * 2 - 1) / frwidth; float yscale = (getSize().height - border * 2 - 1) / frheight; int xoff = border; int yoff = border; if (normalizescaling) { if (xscale < yscale) { yoff += ((getSize().height - border * 2) - ((Ymax - Ymin) * xscale)) / 2; yscale = xscale; } else if (yscale < xscale) { xoff += ((getSize().width - border * 2) - ((Xmax - Xmin) * yscale)) / 2; xscale = yscale; } } turtle = new CLSTurtle(startAngle, 0 - Xmin, 0 - Ymin, xoff, yoff, xscale, yscale); } for (int pos = 0; pos < path.length(); pos++) { switch (path.charAt(pos)) { case '+': turtle.rotate(rotAngle); break; case '-': turtle.rotate(-rotAngle); break; case '[': turtleStack.push(turtle); turtle = new CLSTurtle(turtle); break; case ']': turtle = turtleStack.pop(); break; case 'f': turtle.jump(); break; case 'F': if (g == null) { includePt(turtle.X, turtle.Y); turtle.jump(); includePt(turtle.X, turtle.Y); } else { turtle.draw(g); } break; default: break; } } }
Example 6
Source File: CheckTreeSelectionModel.java From osp with GNU General Public License v3.0 | 18 votes |
/** * Unselects the ancestor of a path and selects ancestor's descendants * other than those for which the path is a descendant. * * @param path the path */ private void unselectAncestor(TreePath path) { // find selected ancestor Stack<TreePath> stack = new Stack<TreePath>(); stack.push(path); TreePath ancestor = path.getParentPath(); while((ancestor!=null)&&!isPathSelected(ancestor)) { stack.push(ancestor); ancestor = ancestor.getParentPath(); } if(ancestor==null) { // no selected ancestors! return; } stack.push(ancestor); // for each path in the stack, unselect it and select all child nodes while(!stack.isEmpty()) { TreePath next = stack.pop(); super.removeSelectionPaths(new TreePath[] {next}); if(stack.isEmpty()) { return; } Object node = next.getLastPathComponent(); int childCount = model.getChildCount(node); for(int i = 0; i<childCount; i++) { Object child = model.getChild(node, i); super.addSelectionPaths(new TreePath[] {next.pathByAddingChild(child)}); } } }
Example 7
Source File: NextGreaterNode_1019.java From AlgoCS with MIT License | 17 votes |
public int[] nextLargerNodes(ListNode head) { List<Integer> list = new ArrayList<>(); while (head != null) { list.add(head.val); head = head.next; } int[] res = new int[list.size()]; Stack<Integer> st = new Stack<>(); for (int i = list.size() - 1; i >= 0; i--) { int num = list.get(i); while (!st.isEmpty() && st.peek() <= num) st.pop(); if (st.isEmpty()) res[i] = 0; else res[i] = st.peek(); st.push(num); } return res; }
Example 8
Source File: Expr.java From lemon with Apache License 2.0 | 16 votes |
/** * 处理操作符. */ public void processOper(Token token, Stack<Token> tokenStack, List<Token> output) { if ("(".equals(token.getValue())) { tokenStack.push(token); return; } if (")".equals(token.getValue())) { popTokenStack(tokenStack, output, true); return; } if (tokenStack.empty()) { tokenStack.push(token); return; } Token innerToken = tokenStack.peek(); // 越靠前,索引越小,优先级越高 if (opers.indexOf(innerToken.getValue()) <= opers.indexOf(token .getValue())) { // 如果当前token的优先级低于栈顶的操作符优先级,就弹出栈顶的操作符 output.add(tokenStack.pop()); } tokenStack.push(token); }
Example 9
Source File: BasicLogicalPlanVisitor.java From tajo with Apache License 2.0 | 15 votes |
@Override public RESULT visitTableSubQuery(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); RESULT result = null; if (plan != null) { LogicalPlan.QueryBlock childBlock = plan.getBlock(node.getSubQuery()); result = visit(context, plan, childBlock, childBlock.getRoot(), stack); } else { result = visit(context, null, null, node.getSubQuery(), stack); } stack.pop(); return result; }
Example 10
Source File: BezierCurve.java From gef with Eclipse Public License 2.0 | 14 votes |
/** * <p> * Computes an approximation of this {@link BezierCurve} by a strip of * {@link Line}s. * </p> * <p> * The {@link BezierCurve} is recursively subdivided until it is "similar" * to a straight {@link Line}. The similarity check computes the sum of the * distances of the control {@link Point}s to the baseline ( * {@link #toLine()}) of this {@link BezierCurve}. If this sum is smaller * than the given <i>lineSimilarity</i>, the {@link BezierCurve} is assumed * to be "similar" to a straight line. * </p> * * @param lineSimilarity * the threshold for the sum of the distances of the control * points to the baseline of this {@link BezierCurve} * @param startInterval * the {@link Interval} of this {@link BezierCurve} that has to * be approximated by a strip of {@link Line}s * @return {@link Line} segments approximating this {@link BezierCurve} */ public Line[] toLineStrip(double lineSimilarity, Interval startInterval) { ArrayList<Line> lines = new ArrayList<>(); Point startPoint = getHC(startInterval.a).toPoint(); Stack<Interval> parts = new Stack<>(); parts.push(startInterval); while (!parts.isEmpty()) { Interval i = parts.pop(); BezierCurve part = getClipped(i.a, i.b); if (distanceToBaseLine(part) < lineSimilarity) { Point endPoint = getHC(i.b).toPoint(); lines.add(new Line(startPoint, endPoint)); startPoint = endPoint; } else { double im = i.getMid(); parts.push(new Interval(im, i.b)); parts.push(new Interval(i.a, im)); } } return lines.toArray(new Line[] {}); }
Example 11
Source File: NDC.java From logging-log4j2 with Apache License 2.0 | 13 votes |
/** * Clone the diagnostic context for the current thread. * <p> * Internally a diagnostic context is represented as a stack. A * given thread can supply the stack (i.e. diagnostic context) to a * child thread so that the child can inherit the parent thread's * diagnostic context. * </p> * <p> * The child thread uses the {@link #inherit inherit} method to * inherit the parent's diagnostic context. * </p> * @return Stack A clone of the current thread's diagnostic context. */ @SuppressWarnings("rawtypes") public static Stack cloneStack() { final Stack<String> stack = new Stack<>(); for (final String element : org.apache.logging.log4j.ThreadContext.cloneStack().asList()) { stack.push(element); } return stack; }
Example 12
Source File: BaseAlgebraVisitor.java From incubator-tajo with Apache License 2.0 | 12 votes |
@Override public RESULT visitSort(CONTEXT ctx, Stack<Expr> stack, Sort expr) throws PlanningException { stack.push(expr); for (Sort.SortSpec sortSpec : expr.getSortSpecs()) { visit(ctx, stack, sortSpec.getKey()); } RESULT result = visit(ctx, stack, expr.getChild()); return result; }
Example 13
Source File: Sub206.java From spring-boot-demo with MIT License | 11 votes |
public ListNode reverseList(ListNode head) { Stack<ListNode> stack = new Stack<>(); while (head != null) { stack.push(head); head = head.next; } ListNode root = stack.isEmpty() ? null : stack.pop(); ListNode temp = root; while (stack.size() > 0) { temp.next = stack.pop(); temp = temp.next; } if (temp != null) temp.next = null; return root; }
Example 14
Source File: CheckTreeSelectionModel.java From MeteoInfo with GNU Lesser General Public License v3.0 | 10 votes |
private void toggleRemoveSelection(TreePath path) { Stack stack = new Stack(); TreePath parent = path.getParentPath(); while (parent != null && !isPathSelected(parent)) { stack.push(parent); parent = parent.getParentPath(); } if (parent != null) { stack.push(parent); } else { super.removeSelectionPaths(new TreePath[]{path}); return; } while (!stack.isEmpty()) { TreePath temp = (TreePath) stack.pop(); TreePath peekPath = stack.isEmpty() ? path : (TreePath) stack.peek(); Object node = temp.getLastPathComponent(); Object peekNode = peekPath.getLastPathComponent(); int childCount = model.getChildCount(node); for (int i = 0; i < childCount; i++) { Object childNode = model.getChild(node, i); if (childNode != peekNode) { super.addSelectionPaths(new TreePath[]{temp.pathByAddingChild(childNode)}); } } } super.removeSelectionPaths(new TreePath[]{parent}); }
Example 15
Source File: BasicLogicalPlanVisitor.java From incubator-tajo with Apache License 2.0 | 9 votes |
@Override public RESULT visitLimit(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, LimitNode node, Stack<LogicalNode> stack) throws PlanningException { stack.push(node); RESULT result = visit(context, plan, block, node.getChild(), stack); stack.pop(); return result; }
Example 16
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 8 votes |
@Test public void findPipelineRunsForAPipelineTest() throws Exception { FreeStyleProject p1 = j.createFreeStyleProject("pipeline1"); FreeStyleProject p2 = j.createFreeStyleProject("pipeline2"); p1.getBuildersList().add(new Shell("echo hello!\nsleep 1")); p2.getBuildersList().add(new Shell("echo hello!\nsleep 1")); Stack<FreeStyleBuild> builds = new Stack<FreeStyleBuild>(); FreeStyleBuild b11 = p1.scheduleBuild2(0).get(); FreeStyleBuild b12 = p1.scheduleBuild2(0).get(); builds.push(b11); builds.push(b12); j.assertBuildStatusSuccess(b11); j.assertBuildStatusSuccess(b12); List<Map> resp = get("/search?q=type:run;organization:jenkins;pipeline:pipeline1", List.class); assertEquals(builds.size(), resp.size()); for(int i=0; i< builds.size(); i++){ Map p = resp.get(i); FreeStyleBuild b = builds.pop(); validateRun(b, p); } }
Example 17
Source File: GraphUtils.java From sundrio with Apache License 2.0 | 7 votes |
public static LinkedList<String> getScopes(Collection<TypeDef> types) { Stack<String> stack = new Stack<String>(); for (TypeDef type : types) { String scope = (String) type.getAttributes().get(BEGIN_SCOPE); if (scope != null && !scope.isEmpty()) { stack.push(scope); } scope = (String) type.getAttributes().get(END_SCOPE); if (scope != null && !scope.isEmpty()) { try { String found = stack.pop(); if (!scope.equals(found)) { throw new IllegalStateException("End of scope:" + scope + " but active scope was:" + found); } } catch (EmptyStackException e) { throw new IllegalStateException("Expected active scope:" + scope + " but not was active.", e); } } } return new LinkedList<String>(stack); }
Example 18
Source File: GeneratorMain.java From greycat with Apache License 2.0 | 6 votes |
static void deleteDir(File dir) { File[] currList; Stack<File> stack = new Stack<File>(); stack.push(dir); while (!stack.isEmpty()) { if (stack.lastElement().isDirectory()) { currList = stack.lastElement().listFiles(); if (currList.length > 0) { for (File curr : currList) { stack.push(curr); } } else { stack.pop().delete(); } } else { stack.pop().delete(); } } }
Example 19
Source File: ThreadGlobalInstantiator.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public static void set(Instantiator instantiator) { Stack<Instantiator> stack = getStack(); if (instantiator != null) { stack.push(instantiator); } else if (!stack.empty()) { stack.pop(); } }
Example 20
Source File: LastGroupSeparator.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
public String process() { StringTokenizer base = new StringTokenizer(startingString, "()", true); int sbLength = startingString.length(); root = new StringBuilder(sbLength); StringBuilder temp = new StringBuilder(sbLength); boolean isValid = false; Stack<String> expected = new Stack<>(); while (base.hasMoreTokens()) { String working = base.nextToken(); if (expected.isEmpty()) { if (isValid) { root.append('('); root.append(temp); root.append(')'); } temp = new StringBuilder(sbLength); isValid = false; } if ("(".equals(working)) { if (!expected.isEmpty()) { temp.append(working); } isValid = true; expected.push(")"); } else if (")".equals(working)) { if (expected.isEmpty()) { throw new GroupingMismatchException( startingString + " did not have an open parenthesis " + "before close: " + temp); } else if (!")".equals(expected.pop())) { throw new GroupingMismatchException( startingString + " did not have matching parenthesis " + "inside of brackets: " + temp); } else if (!expected.isEmpty()) { temp.append(working); } } else if (expected.isEmpty()) { root.append(working); } else { temp.append(working); } } if (expected.isEmpty()) { if (!isValid) { return null; } return temp.toString(); } throw new GroupingMismatchException( startingString + " reached end of String while attempting to match: " + expected.pop()); }