List of usage examples for java.util Stack Stack
public Stack()
From source file:at.ac.tuwien.big.we14.lab2.tests.SeleniumTest.java
/** * @throws java.lang.Exception/*from w ww. j av a 2 s. co m*/ */ @Before public void setUp() throws Exception { try { driver = new FirefoxDriver(); } catch (Exception ffExceptions) { try { driver = new ChromeDriver(); } catch (Exception chromeExceptions) { try { driver = new InternetExplorerDriver(); } catch (Exception ieExceptions) { throw new Exception( "Couldn't create a valid webdriver for Firefox, Chrome, or Internet Explorer"); } } } driver.get("http://" + host + ":" + port + contextPath + mainUrl); currentCheckCategory = new Stack<String>(); }
From source file:com.intuit.tank.harness.functions.StringFunctions.java
/** * @param minId// w w w. j a va 2s. c om * @param maxId * @return */ public synchronized static Stack<Integer> getStack(Integer minId, Integer maxId, String exclusions, boolean include) { String key = getStackKey(minId, maxId, exclusions, include); Stack<Integer> stack = stackMap.get(key); if (stack == null) { int blockSize = (maxId - minId) / APITestHarness.getInstance().getAgentRunData().getTotalAgents(); int offset = APITestHarness.getInstance().getAgentRunData().getAgentInstanceNum() * blockSize; LOG.info(LogUtil.getLogMessage("Creating userId Block starting at " + (offset + minId) + " and containing " + blockSize + " entries with " + (include ? "inclusion" : "exclusion") + " pattern(s) of " + exclusions, LogEventType.System)); List<Integer> list = new ArrayList<Integer>(); List<String> exclusionList = parseExclusions(exclusions); for (int i = 0; i < blockSize; i++) { int nextNum = i + minId + offset; if (nextNum < maxId) { if (shouldInclude(Integer.toString(nextNum), exclusionList, include)) { list.add(nextNum); } } } Collections.shuffle(list); // Collections.reverse(list); stack = new Stack<Integer>(); stack.addAll(list); stackMap.put(key, stack); } return stack; }
From source file:jp.terasoluna.fw.batch.util.BatchUtil.java
/** * ???// ww w. jav a 2 s . c om * @param tranMap PlatformTransactionManager * @param statMap TransactionStatus * @param log Log * @return ???PlatformTransactionManager?????????true?? */ public static boolean endTransactions(Map<?, ?> tranMap, Map<String, TransactionStatus> statMap, Log log) { boolean isNormal = true; Set<Entry<String, TransactionStatus>> statSet = statMap.entrySet(); if (statSet == null || statSet.isEmpty()) { return isNormal; } Stack<Entry<String, TransactionStatus>> stack = new Stack<Entry<String, TransactionStatus>>(); for (Entry<String, TransactionStatus> stat : statSet) { stack.push(stat); } while (!stack.isEmpty()) { // ??? Entry<String, TransactionStatus> statEntry = stack.pop(); String key = statEntry.getKey(); TransactionStatus trnStat = statEntry.getValue(); if (trnStat == null) { continue; } // ??? Object ptmObj = tranMap.get(key); if (ptmObj == null || !(ptmObj instanceof PlatformTransactionManager)) { continue; } PlatformTransactionManager ptm = (PlatformTransactionManager) ptmObj; // ?????? if (trnStat.isCompleted()) { continue; } if (log != null && log.isDebugEnabled()) { logDebug(log, LogId.DAL025041, trnStat); } // ? try { ptm.rollback(trnStat); } catch (TransactionException e) { if (log != null && log.isErrorEnabled()) { logError(log, LogId.EAL025045, e, key); } isNormal = false; // ???????? } if (log != null && log.isDebugEnabled()) { logDebug(log, LogId.DAL025041, trnStat); } } return isNormal; }
From source file:mml.handler.get.MMLGetMMLHandler.java
/** * Create the MMLtext using the invert index and the cortex and corcode * @param cortex the plain text version/*from w w w. ja v a 2 s . c om*/ * @param ccDflt the default STIL markup for that plain text * @param ccPages the page-breaks or null * @param layer the number of the layer to build */ void createMML(ScratchVersion cortex, ScratchVersion ccDflt, ScratchVersion ccPages, int layer) { String text = cortex.getLayerString(layer); mml = new StringBuilder(); String stilDflt = ccDflt.getLayerString(layer); String stilPages = (ccPages == null) ? null : ccPages.getLayerString(layer); JSONObject mDflt = (JSONObject) JSONValue.parse(stilDflt); if (stilPages != null) { JSONObject mPages = (JSONObject) JSONValue.parse(stilPages); mDflt = mergeCorcodes(mDflt, mPages); } JSONArray ranges = (JSONArray) mDflt.get("ranges"); Stack<EndTag> stack = new Stack<EndTag>(); int offset = 0; for (int i = 0; i < ranges.size(); i++) { JSONObject r = (JSONObject) ranges.get(i); Number len = (Number) r.get("len"); Number relOff = (Number) r.get("reloff"); String name = (String) r.get("name"); if (invertIndex.containsKey(name)) { JSONObject def = invertIndex.get(name); String startTag = mmlStartTag(def, offset); String endTag = mmlEndTag(def, len.intValue()); int start = offset + relOff.intValue(); // 1. insert pending end-tags and text before current range int pos = offset; while (!stack.isEmpty() && stack.peek().offset <= start) { // check for NLs here if obj is of type lineformat int tagEnd = stack.peek().offset; boolean isLF = isLineFormat(stack); for (int j = pos; j < tagEnd; j++) { char c = text.charAt(j); if (c != '\n') { if (globals.containsKey(c)) mml.append(globals.get(c)); else mml.append(c); } else if (isLF && j < tagEnd - 1) startPreLine(stack); else mml.append(c); } pos = tagEnd; // newlines are not permitted before tag end while (mml.length() > 0 && mml.charAt(mml.length() - 1) == '\n') mml.setLength(mml.length() - 1); mml.append(stack.pop().text); } // 2. insert intervening text boolean inPre = isLineFormat(stack); int nNLs = countTerminalNLs(mml); for (int j = pos; j < start; j++) { char c = text.charAt(j); if (c == '\n') { if (mml.length() == 0 || nNLs == 0) mml.append(c); if (nNLs > 0) nNLs--; if (inPre) startPreLine(stack); } else { mml.append(c); nNLs = 0; } } // 3. insert new start tag normaliseNewlines(startTag); mml.append(startTag); stack.push(new EndTag(start + len.intValue(), endTag, def)); } else System.out.println("Ignoring tag " + name); offset += relOff.intValue(); } //empty stack int pos = offset; while (!stack.isEmpty()) { int tagEnd = stack.peek().offset; boolean inPre = isLineFormat(stack); for (int j = pos; j < tagEnd; j++) { char c = text.charAt(j); mml.append(c); if (c == '\n' && inPre && j < tagEnd - 1) startPreLine(stack); } pos = tagEnd; // newlines are not permitted before tag end while (mml.length() > 0 && mml.charAt(mml.length() - 1) == '\n') mml.setLength(mml.length() - 1); mml.append(stack.pop().text); } }
From source file:org.hdiv.urlProcessor.AbstractUrlProcessor.java
/** * Removes from <code>url<code> references to relative paths. * //from www. j a v a2s .co m * @param url * url * @param originalRequestUri * originalRequestUri * @return returns <code>url</code> without relative paths. */ protected String removeRelativePaths(String url, String originalRequestUri) { String urlWithoutRelativePath = url; if (url.startsWith("..")) { Stack stack = new Stack(); String localUri = originalRequestUri.substring(originalRequestUri.indexOf("/"), originalRequestUri.lastIndexOf("/")); StringTokenizer localUriParts = new StringTokenizer(localUri.replace('\\', '/'), "/"); while (localUriParts.hasMoreTokens()) { String part = localUriParts.nextToken(); stack.push(part); } StringTokenizer pathParts = new StringTokenizer(url.replace('\\', '/'), "/"); while (pathParts.hasMoreTokens()) { String part = pathParts.nextToken(); if (!part.equals(".")) { if (part.equals("..")) { stack.pop(); } else { stack.push(part); } } } StringBuffer flatPathBuffer = new StringBuffer(); for (int i = 0; i < stack.size(); i++) { flatPathBuffer.append("/").append(stack.elementAt(i)); } urlWithoutRelativePath = flatPathBuffer.toString(); } return urlWithoutRelativePath; }
From source file:net.firejack.platform.core.utils.Factory.java
public Class getGenericParameterClass(Class actualClass, Class genericClass, int parameterIndex) { if (!genericClass.isAssignableFrom(actualClass) || genericClass.equals(actualClass)) { throw new IllegalArgumentException( "Class " + genericClass.getName() + " is not a superclass of " + actualClass.getName() + "."); }/* www . j a v a 2 s. c om*/ Stack<ParameterizedType> types = new Stack<ParameterizedType>(); Class clazz = actualClass; while (true) { Type currentType = genericClass.isInterface() ? getGenericInterface(clazz, genericClass) : clazz.getGenericSuperclass(); Type rawType; if (currentType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) currentType; types.push(type); rawType = type.getRawType(); } else { types.clear(); rawType = currentType; } if (!rawType.equals(genericClass)) { clazz = (Class) rawType; } else { break; } } if (types.isEmpty()) { return (Class) genericClass.getTypeParameters()[parameterIndex].getGenericDeclaration(); } Type result = types.pop().getActualTypeArguments()[parameterIndex]; while (result instanceof TypeVariable && !types.empty()) { int actualArgumentIndex = getParameterTypeDeclarationIndex((TypeVariable) result); ParameterizedType type = types.pop(); result = type.getActualTypeArguments()[actualArgumentIndex]; } if (result instanceof TypeVariable) { throw new IllegalStateException("Unable to resolve type variable " + result + "." + " Try to replace instances of parametrized class with its non-parameterized subtype."); } if (result instanceof ParameterizedType) { result = ((ParameterizedType) result).getRawType(); } if (result == null) { throw new IllegalStateException( "Unable to determine actual parameter type for " + actualClass.getName() + "."); } if (!(result instanceof Class)) { throw new IllegalStateException( "Actual parameter type for " + actualClass.getName() + " is not a Class."); } return (Class) result; }
From source file:com.anite.antelope.zebra.om.AntelopeProcessInstance.java
/** * Looks for the first list of tasks that come from the child(ren) of this * processinstance This is used for finding the next screen. We don't do * this exaustively as it could be very large. The first is good enough for * determining the next screen// w w w. j ava 2 s.co m */ public List getFirstTasksFromAChildProcess() throws NestableException { Stack checkList = new Stack(); checkList.push(this); while (!checkList.isEmpty()) { try { AntelopeProcessInstance currentProcess = (AntelopeProcessInstance) checkList.pop(); List childProcesses = currentProcess.getRunningChildProcesses(); for (Iterator it = childProcesses.iterator(); it.hasNext();) { AntelopeProcessInstance child = (AntelopeProcessInstance) it.next(); List allTasks = child.getUsersTasks(); if (!allTasks.isEmpty()) { return allTasks; } checkList.push(child); } } catch (Exception e) { String emsg = "Failed to retrieve child processes"; log.error(emsg, e); throw new NestableException(emsg, e); } } return new ArrayList(); }
From source file:com.intuit.tank.harness.functions.StringFunctions.java
/** * @param minId/*from w w w . ja va 2 s . c om*/ * @param maxId * @return */ private synchronized static Stack<Integer> getStackWithMods(Integer minId, Integer maxId, Integer mod, boolean include) { String key = getStackKey(minId, maxId, mod, include); Stack<Integer> stack = stackMap.get(key); if (stack == null) { int blockSize = (maxId - minId) / APITestHarness.getInstance().getAgentRunData().getTotalAgents(); int offset = APITestHarness.getInstance().getAgentRunData().getAgentInstanceNum() * blockSize; LOG.info(LogUtil.getLogMessage( "Creating userId Block starting at " + offset + " and containing " + blockSize + " entries.", LogEventType.System)); List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < blockSize; i++) { int nextNum = i + minId + offset; if (include && nextNum < maxId && nextNum % mod == 0) { list.add(nextNum); } else if (!include && nextNum < maxId && nextNum % mod != 0) { list.add(nextNum); } } Collections.shuffle(list); // Collections.reverse(list); stack = new Stack<Integer>(); stack.addAll(list); stackMap.put(key, stack); } return stack; }
From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java
/** * @param results//www . jav a 2 s.c o m * @param q * @throws HibernateException */ @Transient private void recursivelyQueryChildProcesses(List<ZebraProcessInstance> results, Query q) throws HibernateException { // Recursive Process children Stack<ZebraProcessInstance> checkList = new Stack<ZebraProcessInstance>(); checkList.push(this); while (!checkList.isEmpty()) { ZebraProcessInstance processInstance = checkList.pop(); q.setLong("guid", processInstance.getProcessInstanceId().longValue()); for (Iterator it = q.iterate(); it.hasNext();) { ZebraProcessInstance childProcess = (ZebraProcessInstance) it.next(); results.add(childProcess); checkList.push(childProcess); } } }