List of usage examples for java.util Stack peek
public synchronized E peek()
From source file:org.openremote.server.route.SubflowRoute.java
public static String peekCorrelationStack(Map<String, Object> headers, boolean root, boolean removeHeader) { String instanceId = null;//from w ww . java 2 s.c om if (hasCorrelationStack(headers)) { @SuppressWarnings("unchecked") Stack<String> correlationStack = (Stack<String>) headers.get(SUBFLOW_CORRELATION_STACK); if (correlationStack.size() > 0) { if (root) { instanceId = correlationStack.get(0); LOG.debug("Got correlation stack root element: " + instanceId); } else { instanceId = correlationStack.peek(); LOG.debug("Got correlation stack current element: " + instanceId); } } if (removeHeader) headers.remove(SUBFLOW_CORRELATION_STACK); } return instanceId; }
From source file:com.baifendian.swordfish.execserver.parameter.placeholder.CalculateUtil.java
/** * ???/*from w w w . jav a 2 s . c o m*/ * * @param inOrderList * @return ?? */ private static List<String> getPostOrder(List<String> inOrderList) { List<String> result = new ArrayList<>(); Stack<String> stack = new Stack<>(); for (int i = 0; i < inOrderList.size(); i++) { if (Character.isDigit(inOrderList.get(i).charAt(0))) { result.add(inOrderList.get(i)); } else { switch (inOrderList.get(i).charAt(0)) { case '(': stack.push(inOrderList.get(i)); break; case ')': while (!stack.peek().equals("(")) { result.add(stack.pop()); } stack.pop(); break; default: while (!stack.isEmpty() && compare(stack.peek(), inOrderList.get(i))) { result.add(stack.pop()); } stack.push(inOrderList.get(i)); break; } } } while (!stack.isEmpty()) { result.add(stack.pop()); } return result; }
From source file:opennlp.tools.parse_thicket.kernel_interface.BracesProcessor.java
public static boolean checkParentesis(String str) { if (str.isEmpty()) return true; Stack<Character> stack = new Stack<Character>(); for (int i = 0; i < str.length(); i++) { char current = str.charAt(i); if (current == '{' || current == '(' || current == '[') { stack.push(current);/*from w ww .j a va 2 s .c o m*/ } if (current == '}' || current == ')' || current == ']') { if (stack.isEmpty()) return false; char last = stack.peek(); if (current == '}' && (last == '{' || current == ')') && last == '(' || (current == ']' && last == '[')) stack.pop(); else return false; } } return stack.isEmpty(); }
From source file:opennlp.tools.parse_thicket.kernel_interface.BracesProcessor.java
public static boolean isParenthesisMatch(String str) { Stack<Character> stack = new Stack<Character>(); char c;// w ww. jav a 2 s . c o m for (int i = 0; i < str.length(); i++) { c = str.charAt(i); if (c == '{') return false; if (c == '(') stack.push(c); if (c == '{') { stack.push(c); if (c == '}') if (stack.empty()) return false; else if (stack.peek() == '{') stack.pop(); } else if (c == ')') if (stack.empty()) return false; else if (stack.peek() == '(') stack.pop(); else return false; } return stack.empty(); }
From source file:org.jbpm.JbpmConfiguration.java
static JbpmConfiguration getCurrentJbpmConfiguration() { JbpmConfiguration currentJbpmConfiguration = null; Stack stack = getJbpmConfigurationStack(); if (!stack.isEmpty()) { currentJbpmConfiguration = (JbpmConfiguration) stack.peek(); }/* www .j a va2s .co m*/ return currentJbpmConfiguration; }
From source file:de.codesourcery.jasm16.ast.ASTUtils.java
public static Iterator<ASTNode> createDepthFirst(ASTNode node) { final Stack<ASTNode> stack = new Stack<ASTNode>(); if (node != null) { stack.push(node);/*from w w w . j av a 2 s .c o m*/ } return new Iterator<ASTNode>() { @Override public boolean hasNext() { return !stack.isEmpty(); } @Override public ASTNode next() { ASTNode n = stack.peek(); for (ASTNode child : n.getChildren()) { stack.push(child); } return stack.pop(); } @Override public void remove() { throw new UnsupportedOperationException("Not implemented"); } }; }
From source file:org.apache.hadoop.hdfs.TestDFSStripedOutputStreamWithFailure.java
private static void getComb(int n, int k, Stack<Integer> stack, List<List<Integer>> res) { if (stack.size() == k) { List<Integer> list = new ArrayList<Integer>(stack); res.add(list);/*from w ww . ja v a2s .c o m*/ } else { int next = stack.empty() ? 0 : stack.peek() + 1; while (next < n) { stack.push(next); getComb(n, k, stack, res); next++; } } if (!stack.empty()) { stack.pop(); } }
From source file:de.tudarmstadt.ukp.csniper.webapp.search.tgrep.PennTreeUtils.java
public static PennTreeNode parsePennTree(String aTree) { StringTokenizer st = new StringTokenizer(aTree, "() ", true); PennTreeNode root = null;// w ww . j a v a2s . com Stack<PennTreeNode> stack = new Stack<PennTreeNode>(); boolean seenLabel = false; int i = 0; while (st.hasMoreTokens()) { String t = st.nextToken().trim(); if (t.length() == 0) { // Skip } else if ("(".equals(t)) { PennTreeNode n = new PennTreeNode(); stack.push(n); if (root == null) { root = n; } seenLabel = false; } else if (")".equals(t)) { PennTreeNode n = stack.pop(); if (!stack.isEmpty()) { PennTreeNode p = stack.peek(); p.addChild(n); } } else if (seenLabel) { // If the node has two labels, its a leaf, add a new terminal node then. PennTreeNode p = stack.peek(); PennTreeNode n = new PennTreeNode(); n.setTokenIndex(i); i++; n.setLabel(t); p.addChild(n); } else { PennTreeNode n = stack.peek(); n.setLabel(t); seenLabel = true; } } return root; }
From source file:de.tudarmstadt.ukp.dkpro.core.io.penntree.PennTreeUtils.java
public static PennTreeNode parsePennTree(String aTree) { StringTokenizer st = new StringTokenizer(aTree, "() ", true); PennTreeNode root = null;//ww w. j a v a 2 s .c o m Stack<PennTreeNode> stack = new Stack<PennTreeNode>(); boolean seenLabel = false; while (st.hasMoreTokens()) { String t = st.nextToken().trim(); if (t.length() == 0) { // Skip } else if ("(".equals(t)) { PennTreeNode n = new PennTreeNode(); stack.push(n); if (root == null) { root = n; } seenLabel = false; } else if (")".equals(t)) { PennTreeNode n = stack.pop(); if (!stack.isEmpty()) { PennTreeNode p = stack.peek(); p.addChild(n); } } else if (seenLabel) { // If the node has two labels, its a leaf, add a new terminal node then. PennTreeNode p = stack.peek(); PennTreeNode n = new PennTreeNode(); n.setLabel(t); p.addChild(n); } else { PennTreeNode n = stack.peek(); n.setLabel(t); seenLabel = true; } } return root; }
From source file:org.alfresco.service.cmr.calendar.CalendarTimezoneHelper.java
/** * Turns an iCal event into event + timezone parameters. * This is very closely tied to the SPP / VTI implementation, * and should be replaced with something more general. * Until then, it is deliberately not public. * //from w w w . j av a 2 s .co m * @param icalText iCal text for the event, and the TZ (prefixed) */ protected static Map<String, String> getICalParams(String icalText) { // Split the iCal file by lines String[] segregatedLines = icalText.split("\r\n"); if (segregatedLines.length == 1 && icalText.indexOf('\n') > 0) { segregatedLines = icalText.split("\n"); } // Perform a stack based parsing of it Map<String, String> result = new HashMap<String, String>(); int attendeeNum = 0; Stack<String> stack = new Stack<String>(); for (String line : segregatedLines) { String[] keyValue = icalLineKeyValue(line); if (keyValue.length >= 2) { if (keyValue[0].equals("BEGIN")) { stack.push(keyValue[1]); continue; } if (keyValue[0].equals("END")) { stack.pop(); continue; } if (!stack.isEmpty() && stack.peek().equals(ICAL_SECTION_EVENT)) { if (keyValue[0].contains(";")) { // Capture the extra details as suffix keys, they're sometimes needed int splitAt = keyValue[0].indexOf(';'); String mainKey = keyValue[0].substring(0, splitAt); if (splitAt < keyValue[0].length() - 2) { // Grab each ;k=v part and store as mainkey-k=v String[] extras = keyValue[0].substring(splitAt + 1).split(";"); for (String extra : extras) { splitAt = extra.indexOf('='); if (splitAt > -1 && !result.containsKey(mainKey + "-" + extra.substring(0, splitAt - 1))) { result.put(mainKey + "-" + extra.substring(0, splitAt - 1), extra.substring(splitAt + 1)); } } } // Use the main key for the core value keyValue[0] = mainKey; } if (keyValue[0].equals("ATTENDEE")) { keyValue[0] = keyValue[0] + attendeeNum; attendeeNum++; } if (!result.containsKey(keyValue[0])) { result.put(keyValue[0], keyValue[keyValue.length - 1]); } } if (!stack.isEmpty() && stack.peek().equals(ICAL_SECTION_TIMEZONE) && !result.containsKey("TZ-" + keyValue[0])) { // Store the top level timezone details with a TZ prefix result.put("TZ-" + keyValue[0], keyValue[keyValue.length - 1]); } if (stack.size() >= 2 && stack.get(stack.size() - 2).equals(ICAL_SECTION_TIMEZONE) && (stack.peek().equals(ICAL_SECTION_TZ_STANDARD) || stack.peek().equals(ICAL_SECTION_TZ_DAYLIGHT)) && !result.containsKey("TZ-" + stack.peek() + "-" + keyValue[0])) { // Store the timezone details with a TZ prefix + details type result.put("TZ-" + stack.peek() + "-" + keyValue[0], keyValue[keyValue.length - 1]); } } } return result; }