List of usage examples for java.util Stack pop
public synchronized E pop()
From source file:com.anite.zebra.core.Engine.java
public void transitionTask(ITaskInstance taskInstance) throws TransitionException { /*/*www . j av a 2s . co m*/ * we need to LOCK the ProcessInstance from changes by other Engine * instances */ IProcessInstance currentProcess = taskInstance.getProcessInstance(); try { stateFactory.acquireLock(currentProcess, this); } catch (LockException e) { String emsg = "Failed to aquire an exclusive lock on the Process Instance (" + currentProcess + "). Transitioning aborted."; log.error(emsg, e); throw new TransitionException(emsg, e); } Stack taskStack = new Stack(); taskStack.push(taskInstance); while (!taskStack.empty()) { // get the task from the Stack ITaskInstance currentTask = (ITaskInstance) taskStack.pop(); Map createdTasks; try { createdTasks = transitionTaskFromStack(currentTask, currentProcess); } catch (Exception e) { String emsg = "Problem encountered transitioning task from Stack"; log.error(emsg, e); throw new TransitionException(e); } for (Iterator it = createdTasks.values().iterator(); it.hasNext();) { ITaskInstance newTask = (ITaskInstance) it.next(); ITaskDefinition td; try { td = newTask.getTaskDefinition(); } catch (DefinitionNotFoundException e) { String emsg = "FATAL: Failed to access the Task Definition"; log.error(emsg, e); // throwing an exception here will leave the process "locked", but that is a valid situation throw new TransitionException(emsg, e); } if (td.isAuto() || td.isSynchronised()) { /* * is an Auto task, so add to the stack for processing. * Also treat * check, * to see if task is present in stack before adding it */ if (!taskStack.contains(newTask)) { if (log.isInfoEnabled()) { log.info("Added task to TaskStack - " + newTask); } taskStack.push(newTask); } else { if (log.isInfoEnabled()) { log.info("transitionTask - task already exists in stack " + newTask); } } } } } try { if (currentProcess.getTaskInstances().size() == 0) { // mark process complete doProcessDestruct(currentProcess); } /* * release lock on process instance */ stateFactory.releaseLock(currentProcess, this); } catch (Exception e) { String emsg = "FATAL: Couldnt release lock on Process Instance (" + currentProcess + ") after transitioning. Process will be left in an usuable state"; log.fatal(emsg, e); throw new TransitionException(emsg, e); } }
From source file:barrysw19.calculon.icc.ICCInterface.java
private List<ResponseBlockLv2> parseBlockResponseLv2(String lvl2String) { List<ResponseBlockLv2> rv = new ArrayList<>(); Stack<StringBuffer> allBlocks = new Stack<>(); for (int i = 0; i < lvl2String.length(); i++) { if (lvl2String.charAt(i) == ('Y' & 0x1F) && lvl2String.charAt(i + 1) == '(') { allBlocks.push(new StringBuffer()); i++;//from w w w . j a v a 2 s. c o m continue; } if (lvl2String.charAt(i) == ('Y' & 0x1F) && lvl2String.charAt(i + 1) == ')') { rv.add(ResponseBlockLv2.createResponseBlock(allBlocks.pop().toString())); i++; continue; } allBlocks.peek().append(lvl2String.charAt(i)); } LOG.debug(String.valueOf(rv)); return rv; }
From source file:edu.uci.ics.jung.algorithms.importance.BetweennessCentrality.java
protected void computeBetweenness(Graph<V, E> graph) { Map<V, BetweennessData> decorator = new HashMap<V, BetweennessData>(); Map<V, Number> bcVertexDecorator = vertexRankScores.get(getRankScoreKey()); bcVertexDecorator.clear();// ww w. j av a2 s. c o m Map<E, Number> bcEdgeDecorator = edgeRankScores.get(getRankScoreKey()); bcEdgeDecorator.clear(); Collection<V> vertices = graph.getVertices(); for (V s : vertices) { initializeData(graph, decorator); decorator.get(s).numSPs = 1; decorator.get(s).distance = 0; Stack<V> stack = new Stack<V>(); Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(s); while (!queue.isEmpty()) { V v = queue.remove(); stack.push(v); for (V w : getGraph().getSuccessors(v)) { if (decorator.get(w).distance < 0) { queue.add(w); decorator.get(w).distance = decorator.get(v).distance + 1; } if (decorator.get(w).distance == decorator.get(v).distance + 1) { decorator.get(w).numSPs += decorator.get(v).numSPs; decorator.get(w).predecessors.add(v); } } } while (!stack.isEmpty()) { V w = stack.pop(); for (V v : decorator.get(w).predecessors) { double partialDependency = (decorator.get(v).numSPs / decorator.get(w).numSPs); partialDependency *= (1.0 + decorator.get(w).dependency); decorator.get(v).dependency += partialDependency; E currentEdge = getGraph().findEdge(v, w); double edgeValue = bcEdgeDecorator.get(currentEdge).doubleValue(); edgeValue += partialDependency; bcEdgeDecorator.put(currentEdge, edgeValue); } if (w != s) { double bcValue = bcVertexDecorator.get(w).doubleValue(); bcValue += decorator.get(w).dependency; bcVertexDecorator.put(w, bcValue); } } } if (graph instanceof UndirectedGraph) { for (V v : vertices) { double bcValue = bcVertexDecorator.get(v).doubleValue(); bcValue /= 2.0; bcVertexDecorator.put(v, bcValue); } for (E e : graph.getEdges()) { double bcValue = bcEdgeDecorator.get(e).doubleValue(); bcValue /= 2.0; bcEdgeDecorator.put(e, bcValue); } } for (V vertex : vertices) { decorator.remove(vertex); } }
From source file:forestry.core.gui.GuiAlyzer.java
protected final void drawAnalyticsPageClassification(IIndividual individual) { startPage();// w ww . j a v a2 s .co m drawLine(StringUtil.localize("gui.alyzer.classification") + ":", 12); newLine(); Stack<IClassification> hierarchy = new Stack<IClassification>(); IClassification classification = individual.getGenome().getPrimary().getBranch(); while (classification != null) { if (classification.getScientific() != null && !classification.getScientific().isEmpty()) hierarchy.push(classification); classification = classification.getParent(); } boolean overcrowded = hierarchy.size() > 5; int x = 12; IClassification group = null; while (!hierarchy.isEmpty()) { group = hierarchy.pop(); if (overcrowded && group.getLevel().isDroppable()) continue; drawLine(group.getScientific(), x, group.getLevel().getColour()); drawLine(group.getLevel().name(), 155, group.getLevel().getColour()); newLine(); x += 10; } // Add the species name String binomial = individual.getGenome().getPrimary().getBinomial(); if (group != null && group.getLevel() == EnumClassLevel.GENUS) binomial = group.getScientific().substring(0, 1) + ". " + binomial.toLowerCase(Locale.ENGLISH); drawLine(binomial, x, 0xebae85); drawLine("SPECIES", 155, 0xebae85); newLine(); newLine(); drawLine(StringUtil.localize("gui.alyzer.authority") + ": " + individual.getGenome().getPrimary().getAuthority(), 12); if (AlleleManager.alleleRegistry.isBlacklisted(individual.getIdent())) { String extinct = ">> " + StringUtil.localize("gui.alyzer.extinct").toUpperCase() + " <<"; fontRendererObj.drawStringWithShadow(extinct, adjustToFactor(guiLeft + 208) - fontRendererObj.getStringWidth(extinct), adjustToFactor(guiTop + getLineY()), fontColor.get("gui.beealyzer.dominant")); } newLine(); String description = individual.getGenome().getPrimary().getDescription(); if (StringUtils.isBlank(description) || description.startsWith("for.description.")) drawSplitLine(StringUtil.localize("gui.alyzer.nodescription"), 12, 208, 0x666666); else { String tokens[] = description.split("\\|"); drawSplitLine(tokens[0], 12, 208, 0x666666); if (tokens.length > 1) fontRendererObj.drawStringWithShadow("- " + tokens[1], adjustToFactor(guiLeft + 208) - fontRendererObj.getStringWidth("- " + tokens[1]), adjustToFactor(guiTop + 145 - 14), 0x99cc32); } endPage(); }
From source file:org.apache.tajo.plan.ExprAnnotator.java
@Override public EvalNode visitNot(Context ctx, Stack<Expr> stack, NotExpr expr) throws TajoException { stack.push(expr);//from www . ja v a 2 s.c om EvalNode child = visit(ctx, stack, expr.getChild()); stack.pop(); return new NotEval(child); }
From source file:org.springjutsu.validation.rules.ValidationRulesContainer.java
/** * Copy rules from parent classes into child classes. *///ww w . ja v a 2s . c o m @SuppressWarnings("unchecked") protected void initInheritance() { Set<Class<?>> inheritanceChecked = new HashSet<Class<?>>(); for (ValidationEntity entity : validationEntityMap.values()) { Stack<Class<?>> classStack = new Stack<Class<?>>(); classStack.push(entity.getValidationClass()); for (Class<?> clazz = entity.getValidationClass().getSuperclass(); clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) { classStack.push(clazz); } Set<ValidationRule> inheritableRules = new ListOrderedSet(); Set<ValidationTemplateReference> inheritableTemplateReferences = new ListOrderedSet(); Set<ValidationContext> inheritableContexts = new ListOrderedSet(); Set<String> inheritableExclusionPaths = new HashSet<String>(); Set<String> inheritableInclusionPaths = new HashSet<String>(); while (!classStack.isEmpty()) { Class<?> clazz = classStack.pop(); if (supportsClass(clazz) && !inheritanceChecked.contains(clazz)) { validationEntityMap.get(clazz).getRules().addAll(inheritableRules); validationEntityMap.get(clazz).getValidationContexts().addAll(inheritableContexts); validationEntityMap.get(clazz).getExcludedPaths().addAll(inheritableExclusionPaths); validationEntityMap.get(clazz).getIncludedPaths().addAll(inheritableInclusionPaths); validationEntityMap.get(clazz).getTemplateReferences().addAll(inheritableTemplateReferences); } if (hasRulesForClass(clazz)) { inheritableRules.addAll(validationEntityMap.get(clazz).getRules()); } if (supportsClass(clazz)) { inheritableContexts.addAll(validationEntityMap.get(clazz).getValidationContexts()); inheritableExclusionPaths.addAll(validationEntityMap.get(clazz).getExcludedPaths()); inheritableInclusionPaths.addAll(validationEntityMap.get(clazz).getIncludedPaths()); } inheritanceChecked.add(clazz); } } }
From source file:com._4dconcept.springframework.data.marklogic.core.query.QueryBuilder.java
@Nullable private Criteria buildCriteria(Object bean, MarklogicPersistentEntity<?> entity) { Stack<Criteria> stack = new Stack<>(); PersistentPropertyAccessor propertyAccessor = entity.getPropertyAccessor(bean); entity.doWithProperties((PropertyHandler<MarklogicPersistentProperty>) property -> { Object value = propertyAccessor.getProperty(property); if (hasContent(value)) { if (stack.empty()) { stack.push(buildCriteria(property, value)); } else { Criteria criteria = stack.peek(); if (criteria.getOperator() == null) { Criteria andCriteria = new Criteria(Criteria.Operator.and, new ArrayList<>(Arrays.asList(criteria, buildCriteria(property, value)))); stack.pop(); stack.push(andCriteria); } else { Criteria subCriteria = buildCriteria(property, value); if (subCriteria != null) { criteria.add(subCriteria); }//from w w w .j a va 2 s .c om } } } }); return stack.empty() ? null : stack.peek(); }
From source file:com.jsmartframework.web.manager.TagHandler.java
@SuppressWarnings("unchecked") protected void popDelegateTagParent() { Stack<RefAction> actionStack = (Stack<RefAction>) getMappedValue(DELEGATE_TAG_PARENT); RefAction refAction = actionStack.pop(); if (actionStack.empty()) { removeMappedValue(DELEGATE_TAG_PARENT); }/*w w w.j av a 2s . com*/ Map<String, EventAction> refs = refAction.getRefs(); if (refs != null) { for (String refId : refs.keySet()) { EventAction eventAction = refs.get(refId); if (eventAction == null) { continue; } Map<String, Set<Ajax>> refAjaxs = eventAction.getAjaxs(); if (refAjaxs != null) { for (String event : refAjaxs.keySet()) { for (Ajax jsonAjax : refAjaxs.get(event)) { StringBuilder builder = new StringBuilder(); builder.append(JSMART_AJAX.format(getJsonValue(jsonAjax))); builder = getDelegateFunction(id, "*[role-delegate=\"" + refId + "\"]", event.toLowerCase(), builder); appendDocScript(builder); } } } Map<String, Set<Bind>> refBinds = eventAction.getBinds(); if (refBinds != null) { for (String event : refBinds.keySet()) { for (Bind jsonBind : refBinds.get(event)) { StringBuilder builder = new StringBuilder(); builder.append(JSMART_BIND.format(getJsonValue(jsonBind))); builder = getDelegateFunction(id, "*[role-delegate=\"" + refId + "\"]", event.toLowerCase(), builder); appendDocScript(builder); } } } } } }
From source file:org.apache.tajo.plan.ExprAnnotator.java
@Override public EvalNode visitIsNullPredicate(Context ctx, Stack<Expr> stack, IsNullPredicate expr) throws TajoException { stack.push(expr);//from w ww .j a v a 2 s . co m EvalNode child = visit(ctx, stack, expr.getPredicand()); stack.pop(); return new IsNullEval(expr.isNot(), child); }
From source file:org.pgptool.gui.encryption.implpgp.KeyFilesOperationsPgpImpl.java
@Override public void exportPublicKey(Key key, String targetFilePathname) { Preconditions.checkArgument(key != null && key.getKeyData() != null && key.getKeyInfo() != null, "Key must be providedand fully described"); Preconditions.checkArgument(StringUtils.hasText(targetFilePathname), "targetFilePathname must be provided"); Stack<OutputStream> os = new Stack<>(); try {/*from w w w. j av a2s. c o m*/ os.push(new FileOutputStream(targetFilePathname)); if ("asc".equalsIgnoreCase(FilenameUtils.getExtension(targetFilePathname))) { os.push(new ArmoredOutputStream(os.peek())); } KeyDataPgp keyDataPgp = KeyDataPgp.get(key); if (keyDataPgp.getPublicKeyRing() != null) { keyDataPgp.getPublicKeyRing().encode(os.peek()); } else { keyDataPgp.getSecretKeyRing().getPublicKey().encode(os.peek()); } } catch (Throwable t) { throw new RuntimeException( "Failed to export public key " + key.getKeyInfo().getUser() + " to " + targetFilePathname, t); } finally { while (!os.isEmpty()) { IoStreamUtils.safeClose(os.pop()); } } }