List of usage examples for java.util Stack Stack
public Stack()
From source file:hydrograph.engine.core.xmlparser.parametersubstitution.ParameterSubstitutor.java
private String substitute(String input, Stack<String> unresolvedParameters) { StringBuilder mutable;//from www . jav a 2 s . co m int startIndex = input.indexOf(VARIABLE_PREFIX); int endIndex = input.indexOf(VARIABLE_SUFFIX, startIndex); if (startIndex == -1 || endIndex == -1) { // If there is no parameter syntax then just return as nothing to // substitute return input; } // string builder is required to work with substitution mutable = new StringBuilder(input); // stack is required to keep track of unresolved parameters to detect // circular dependencies if (unresolvedParameters == null) { unresolvedParameters = new Stack<String>(); } substituteMutable(mutable, unresolvedParameters); return mutable.toString(); }
From source file:javalin.draw.Drawing.java
public void draw(final DrawingGraphics dg) { float[] pos = new float[] { 0, 0, 0 }; final Stack<FloatList> polygonStack = new Stack<FloatList>(); FloatList polygon = null;/*from www .j av a 2 s .c o m*/ Map<Integer, float[][][]> patches = null; int argIndex = 0; final Iterator<DrawingOp> opIter = drawing.iterator(); while (opIter.hasNext()) { final DrawingOp op = opIter.next(); switch (op) { case LINE_TO: float x = args.get(argIndex++); float y = args.get(argIndex++); float z = args.get(argIndex++); dg.drawLine(pos[0], pos[1], pos[2], x, y, z); pos[0] = x; pos[1] = y; pos[2] = z; break; case MOVE_TO: pos[0] = args.get(argIndex++); pos[1] = args.get(argIndex++); pos[2] = args.get(argIndex++); break; case SETCOLOR: dg.setColor(args.get(argIndex++), args.get(argIndex++), args.get(argIndex++), args.get(argIndex++)); break; case START_POLY: if (polygon != null) polygonStack.push(polygon); polygon = new FloatList(64); break; case VERTEX: if (polygon == null) throw new IllegalStateException("You can't create a vertex before a polygon is begun."); polygon.add(pos[0], pos[1], pos[2]); break; case END_POLY: if (polygon == null) throw new IllegalStateException("You can't end a polygon before a polygon is begun."); dg.drawPolygon(polygon.toArray()); polygon = polygonStack.size() > 0 ? polygonStack.pop() : null; break; case INIT_PATCH: int patchIndex = (int) args.get(argIndex++); if (patches == null) patches = new HashMap<Integer, float[][][]>(); float[][][] patch; if (patches.containsKey(patchIndex)) patch = patches.get(patchIndex); else { patch = new float[4][4][3]; patches.put(patchIndex, patch); } for (int row = 0; row < 4; row++) for (int col = 0; col < 4; col++) for (int d = 0; d < 3; d++) patch[row][col][d] = 0; break; case CONTROL_POINT: patchIndex = (int) args.get(argIndex++); patch = patches.get(patchIndex); if (patch == null) throw new IllegalStateException("Patch " + patchIndex + " has not been initialized."); int row = (int) args.get(argIndex++); int col = (int) args.get(argIndex++); patch[row][col][0] = args.get(argIndex++); patch[row][col][1] = args.get(argIndex++); patch[row][col][2] = args.get(argIndex++); break; case DRAW_PATCH: patchIndex = (int) args.get(argIndex++); patch = patches.get(patchIndex); if (patch == null) throw new IllegalStateException( "You can't draw patch " + patchIndex + " before it is initialized."); final int gridSteps = (int) args.get(argIndex++); dg.drawPatch(patch, gridSteps); break; } } if (polygon != null || polygonStack.size() > 0) throw new IllegalStateException("Unfinished polygon."); }
From source file:cz.vse.esper.XMLRenderer.java
/** * Ctor./*from ww w.j av a 2 s. c o m*/ * @param eventType type of event to render * @param options rendering options */ public XMLRenderer(EventType eventType, XMLRenderingOptions options) { EventPropertyRenderer propertyRenderer = null; EventPropertyRendererContext propertyRendererContext = null; if (options.getRenderer() != null) { propertyRenderer = options.getRenderer(); propertyRendererContext = new EventPropertyRendererContext(eventType, false); } rendererMetaOptions = new RendererMetaOptions(options.isPreventLooping(), true, propertyRenderer, propertyRendererContext); meta = new RendererMeta(eventType, new Stack<EventTypePropertyPair>(), rendererMetaOptions); this.options = options; }
From source file:app.web.SeleniumPage.java
public SeleniumPage(Selenium selenium, final String url) { this(selenium, url, new Stack<Action>()); this.selenium.open(url); currentPage = this; }
From source file:com.espertech.esper.event.util.XMLRendererImpl.java
/** * Ctor./*ww w.jav a 2 s. c om*/ * @param eventType type of event to render * @param options rendering options */ public XMLRendererImpl(EventType eventType, XMLRenderingOptions options) { EventPropertyRenderer propertyRenderer = null; EventPropertyRendererContext propertyRendererContext = null; if (options.getRenderer() != null) { propertyRenderer = options.getRenderer(); propertyRendererContext = new EventPropertyRendererContext(eventType, false); } rendererMetaOptions = new RendererMetaOptions(options.isPreventLooping(), true, propertyRenderer, propertyRendererContext); meta = new RendererMeta(eventType, new Stack<EventTypePropertyPair>(), rendererMetaOptions); this.options = options; }
From source file:importer.handler.post.stages.SAXSplitter.java
/** * Split a TEI-XML file into versions of XML * @param tei the TEI content containing versions * @return an analysis of the variant markup in a file * @throws ImportException if something went wrong *///from w w w . j a va 2 s .c o m public JSONArray scan(String tei) throws ImporterException { this.layers = new HashMap<String, Integer>(); this.lineNo = 1; this.splits = new HashSet<String>(); this.attributes = new HashMap<String, String>(); this.siblings = new HashMap<String, String>(); this.states = new Stack<Integer>(); this.states.push(0); this.siblingCount = 0; this.path = new StringBuilder(); // hard-wire config for now attributes.put("add", "n"); attributes.put("rdg", "wit"); attributes.put("lem", "wit"); siblings.put("add", "del"); siblings.put("del", "add"); siblings.put("lem", "rdg"); siblings.put("rdg", "lem"); splits.add("add"); splits.add("del"); splits.add("sic"); splits.add("corr"); splits.add("abbrev"); splits.add("expan"); splits.add("rdg"); splits.add("lem"); splits.add("app"); splits.add("mod"); splits.add("choice"); splits.add("subst"); try { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); parser = spf.newSAXParser(); xmlReader = parser.getXMLReader(); xmlReader.setContentHandler(this); xmlReader.setErrorHandler(new MyErrorHandler(System.err)); CharArrayReader car = new CharArrayReader(tei.toCharArray()); xmlReader.parse(new InputSource(car)); return layersToJson(); } catch (Exception e) { throw new ImporterException(e); } }
From source file:com.blackducksoftware.integration.hub.detect.detector.pip.PipenvGraphParser.java
public PipParseResult parse(final String projectName, final String projectVersionName, final List<String> pipFreezeOutput, final List<String> pipenvGraphOutput, final String sourcePath) { final MutableMapDependencyGraph dependencyGraph = new MutableMapDependencyGraph(); final Stack<Dependency> dependencyStack = new Stack<>(); final Map<String, String[]> pipFreezeMap = pipFreezeOutput.stream() .map(line -> line.split(TOP_LEVEL_SEPARATOR)).filter(splitLine -> splitLine.length == 2) .collect(Collectors.toMap(splitLine -> splitLine[0].trim().toLowerCase(), splitLine -> splitLine)); int lastLevel = -1; for (final String line : pipenvGraphOutput) { final int currentLevel = getLevel(line); final Optional<Dependency> parsedDependency = getDependencyFromLine(pipFreezeMap, line); if (!parsedDependency.isPresent()) { continue; }/*ww w .j a v a2s . co m*/ final Dependency dependency = parsedDependency.get(); if (currentLevel == lastLevel) { dependencyStack.pop(); } else { for (; lastLevel >= currentLevel; lastLevel--) { dependencyStack.pop(); } } if (dependencyStack.size() > 0) { dependencyGraph.addChildWithParent(dependency, dependencyStack.peek()); } else { dependencyGraph.addChildrenToRoot(dependency); } lastLevel = currentLevel; dependencyStack.push(dependency); } if (!dependencyGraph.getRootDependencyExternalIds().isEmpty()) { final ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName); final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, projectExternalId, dependencyGraph).build(); return new PipParseResult(projectName, projectVersionName, codeLocation); } else { return null; } }
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();/*w w w .j a v 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:com.ms.commons.test.math.expression.util.MathExpressionParseUtil.java
private static Stack<String> parseTokenStack(String expr) throws MathParseException { Stack<String> expressionStack = new Stack<String>(); StringBuilder lastTokens = new StringBuilder(); char[] cs = expr.toCharArray(); boolean isLastBracketsBlock = false; int fromIndex = 0; int endIndex = expr.length() - 1; for (int i = fromIndex; i <= endIndex; i++) { char c = cs[i]; switch (c) { case '(': if (isLastBracketsBlock) { throw new MathParseException("Error token '(' or ')' useage in '" + expr + "'."); }//from w w w . j a va2 s. c o m int nextCloseBracket = findNextCloseBracket(cs, (i + 1), endIndex); if (nextCloseBracket == -1) { throw new MathParseException("Token '(' or ')' not paried in '" + expr + "'."); } for (int x = i + 1; x < nextCloseBracket; x++) { lastTokens.append(cs[x]); } i = nextCloseBracket; isLastBracketsBlock = true; break; case '+': case '-': case '*': case '/': checkIndex(i, fromIndex, endIndex, cs, lastTokens); expressionStack.push(lastTokens.toString()); expressionStack.push(String.valueOf(c)); lastTokens = new StringBuilder(); isLastBracketsBlock = false; break; default: if (c == ')') { throw new MathParseException("Error token ')' in '" + expr + "'."); } if (isLastBracketsBlock) { throw new MathParseException("Error token '(' or ')' useage in '" + expr + "'."); } // check more ilgeal char ? lastTokens.append(c); break; } } if (lastTokens.length() > 0) { expressionStack.add(lastTokens.toString()); } return expressionStack; }
From source file:com.modelsolv.kaboom.serializer.HalSerializerImpl.java
@Override public String serialize(ObjectResource res, CanonicalObjectReader reader) { objectCount = 0;/*from w w w.j a v a2s. c om*/ // The object bound to this resource. . Object obj = res.getCanonicalObject(); // The resource data model, with property exclusions and reference // treatments. ResourceDataModel rdm = res.getResourceDefinition().getResourceDataModel(); Representation rep = createNewRepresentation(res); buildObjectRepresentation(rep, obj, reader, rdm, new Stack<Object>()); return rep.toString(halFormat); }