List of usage examples for java.util Stack pop
public synchronized E pop()
From source file:com.sm.store.server.QueryIterator.java
private boolean needTableScan() { //check tableScan if (tableScan) return true; else {/*from www .ja v a 2s . c o m*/ if (!sorted) { Stack<Predicate> stack = (Stack<Predicate>) predicateStack.clone(); while (!stack.empty()) { if (traverse(stack.pop())) return true; } } return false; } }
From source file:gov.medicaid.screening.dao.impl.NurseAnesthetistsLicenseDAOBean.java
/** * Parses the full name into a User object. * * @param fullName the full name displayed on the site * @return the parsed name/* ww w. j a va 2 s .c om*/ */ private User parseName(String fullName) { fullName = fullName.substring(0, fullName.indexOf(",")); // remove certificate title User user = new User(); Stack<String> nameParts = new Stack<String>(); for (String string : fullName.split(" ")) { nameParts.push(string); } user.setLastName(nameParts.pop()); if (nameParts.size() > 1) { user.setMiddleName(nameParts.pop()); } StringBuffer sb = new StringBuffer(); while (!nameParts.isEmpty()) { sb.insert(0, nameParts.pop() + " "); } user.setFirstName(sb.toString().trim()); return user; }
From source file:fr.ritaly.dungeonmaster.item.ItemManager.java
@Override public synchronized Item removeItem(Sector sector) { Validate.notNull(sector, "The given sector is null"); if (items != null) { final Stack<Item> stack = items.get(sector); if (stack != null) { // Remove the top item from the stack final Item item = stack.pop(); if (stack.isEmpty()) { items.remove(sector);// ww w .j a va 2s .co m if (items.isEmpty()) { items = null; } } fireItemRemovedEvent(item, sector); return item; } } return null; }
From source file:com.aperigeek.dropvault.web.rest.SearchService.java
@GET @Produces("application/json") public Response query(@HeaderParam("Authorization") String authorization, @QueryParam("q") String query) throws IndexException { User user;//from w ww . ja v a2s.co m try { user = authenticationService.checkAuthentication(authorization); } catch (InvalidPasswordException ex) { return Response.status(401).header("WWW-Authenticate", "Basic realm=\"Search authentication\"").build(); } catch (NotAuthorizedException ex) { return Response.status(403).build(); } catch (ProtocolException ex) { return Response.status(400).build(); } URI userUri = URI.create(DAV_BASE); List<String> uris = new ArrayList<String>(); List<String> ids = indexService.search(user.getUsername(), user.getPassword(), query); for (String id : ids) { Resource res = fileService.getResource(id); Stack<Resource> path = new Stack<Resource>(); Resource parent = res; while (parent != null) { path.push(parent); parent = fileService.getParent(parent); } // Remove the user's root folder, we don't want it in the path path.pop(); UriBuilder builder = UriBuilder.fromUri(userUri); while (!path.empty()) { Resource e = path.pop(); builder.path(e.getName()); } uris.add(builder.build().toString()); } JSONArray array = new JSONArray(uris); return Response.ok(array.toString()).build(); }
From source file:BracketChecker.java
public void check() { Stack<Character> theStack = new Stack<Character>(); for (int j = 0; j < input.length(); j++) { char ch = input.charAt(j); switch (ch) { case '{': case '[': case '(': theStack.push(ch);/*w ww . j ava2 s. c om*/ break; case '}': case ']': case ')': if (!theStack.isEmpty()) { char chx = theStack.pop(); if ((ch == '}' && chx != '{') || (ch == ']' && chx != '[') || (ch == ')' && chx != '(')) System.out.println("Error: " + ch + " at " + j); } else System.out.println("Error: " + ch + " at " + j); break; default: break; } } if (!theStack.isEmpty()) { System.out.println("Error: missing right delimiter"); } }
From source file:com.ikanow.infinit.e.application.utils.LogstashConfigUtils.java
public static BasicDBObject parseLogstashConfig(String configFile, StringBuffer error) { BasicDBObject tree = new BasicDBObject(); // Stage 0: remove escaped "s and 's (for the purpose of the validation): // (prevents tricksies with escaped "s and then #s) // (http://stackoverflow.com/questions/5082398/regex-to-replace-single-backslashes-excluding-those-followed-by-certain-chars) configFile = configFile.replaceAll("(?<!\\\\)(?:((\\\\\\\\)*)\\\\)[\"']", "X"); //TESTED (by hand - using last 2 fields of success_2_1) // Stage 1: remove #s, and anything in quotes (for the purpose of the validation) configFile = configFile.replaceAll("(?m)(?:([\"'])(?:(?!\\1).)*\\1)", "VALUE").replaceAll("(?m)(?:#.*$)", "");//from w w w .j a va2 s . c om //TESTED (2_1 - including with a # inside the ""s - Event_Date -> Event_#Date) //TESTED (2_2 - various combinations of "s nested inside 's) ... yes that is a negative lookahead up there - yikes! // Stage 2: get a nested list of objects int depth = 0; int ifdepth = -1; Stack<Integer> ifStack = new Stack<Integer>(); BasicDBObject inputOrFilter = null; Matcher m = _navigateLogstash.matcher(configFile); // State: String currTopLevelBlockName = null; String currSecondLevelBlockName = null; BasicDBObject currSecondLevelBlock = null; while (m.find()) { boolean simpleField = false; //DEBUG //System.out.println("--DEPTH="+depth + " GROUP=" + m.group() + " IFS" + Arrays.toString(ifStack.toArray())); //System.out.println("STATES: " + currTopLevelBlockName + " AND " + currSecondLevelBlockName); if (m.group().equals("}")) { if (ifdepth == depth) { // closing an if statement ifStack.pop(); if (ifStack.isEmpty()) { ifdepth = -1; } else { ifdepth = ifStack.peek(); } } //TESTED (1_1bc, 2_1) else { // closing a processing block depth--; if (depth < 0) { // {} Mismatch error.append("{} Mismatch (})"); return null; } //TESTED (1_1abc) } } else { // new attribute! String typeName = m.group(1); if (null == typeName) { // it's an if statement or a string value typeName = m.group(4); if (null != typeName) { simpleField = true; } } else if (typeName.equalsIgnoreCase("else")) { // It's an if statement.. typeName = null; } if (null == typeName) { // if statement after all // Just keep track of ifs so we can ignore them ifStack.push(depth); ifdepth = depth; // (don't increment depth) } //TESTED (1_1bc, 2_1) else { // processing block String subTypeName = m.group(3); if (null != subTypeName) { // eg codec.multiline typeName = typeName + "." + subTypeName; } //TESTED (2_1, 2_3) if (depth == 0) { // has to be one of input/output/filter) String topLevelType = typeName.toLowerCase(); if (topLevelType.equalsIgnoreCase("input") || topLevelType.equalsIgnoreCase("filter")) { if (tree.containsField(topLevelType)) { error.append("Multiple input or filter blocks: " + topLevelType); return null; } //TESTED (1_3ab) else { inputOrFilter = new BasicDBObject(); tree.put(topLevelType, inputOrFilter); // Store state: currTopLevelBlockName = topLevelType; } //TESTED (*) } else { if (topLevelType.equalsIgnoreCase("output")) { error.append( "Not allowed output blocks - these are appended automatically by the logstash harvester"); } else { error.append("Unrecognized processing block: " + topLevelType); } return null; } //TESTED (1_4a) } else if (depth == 1) { // processing blocks String subElType = typeName.toLowerCase(); // Some validation: can't include a type called "filter" anywhere if ((null != currTopLevelBlockName) && currTopLevelBlockName.equals("input")) { if (subElType.equals("filter") || subElType.endsWith(".filter")) { error.append("Not allowed sub-elements of input called 'filter' (1)"); return null; } } //TESTED (1_5b) BasicDBList subElements = (BasicDBList) inputOrFilter.get(subElType); if (null == subElements) { subElements = new BasicDBList(); inputOrFilter.put(subElType, subElements); } BasicDBObject newEl = new BasicDBObject(); subElements.add(newEl); // Store state: currSecondLevelBlockName = subElType; currSecondLevelBlock = newEl; } //TESTED (*) else if (depth == 2) { // attributes of processing blocks // we'll just store the field names for these and do any simple validation that was too complicated for the regexes String subSubElType = typeName.toLowerCase(); // Validation: if (null != currTopLevelBlockName) { // 1] sincedb path if (currTopLevelBlockName.equals("input") && (null != currSecondLevelBlockName)) { // (don't care what the second level block name is - no sincedb allowed) if (subSubElType.equalsIgnoreCase("sincedb_path")) { error.append("Not allowed sincedb_path in input.* block"); return null; } //TESTED (1_5a) // 2] no sub-(-sub etc)-elements of input called filter if (subSubElType.equals("filter") || subSubElType.endsWith(".filter")) { error.append("Not allowed sub-elements of input called 'filter' (2)"); return null; } //TESTED (1_5c) } } // Store in map: if (null != currSecondLevelBlock) { currSecondLevelBlock.put(subSubElType, new BasicDBObject()); } } // (won't go any deeper than this) if (!simpleField) { depth++; } } } } if (0 != depth) { error.append("{} Mismatch ({)"); return null; } //TESTED (1_2a) return tree; }
From source file:org.apache.hadoop.hive.ql.parse.PTFTranslator.java
public static ArrayList<PTFInvocationSpec> componentize(PTFInvocationSpec ptfInvocation) throws SemanticException { ArrayList<PTFInvocationSpec> componentInvocations = new ArrayList<PTFInvocationSpec>(); Stack<PTFInputSpec> ptfChain = new Stack<PTFInvocationSpec.PTFInputSpec>(); PTFInputSpec spec = ptfInvocation.getFunction(); while (spec instanceof PartitionedTableFunctionSpec) { ptfChain.push(spec);/* w w w . j a va2 s. c om*/ spec = spec.getInput(); } PartitionedTableFunctionSpec prevFn = (PartitionedTableFunctionSpec) ptfChain.pop(); applyConstantPartition(prevFn); PartitionSpec partSpec = prevFn.getPartition(); OrderSpec orderSpec = prevFn.getOrder(); if (partSpec == null) { // oops this should have been caught before trying to componentize throw new SemanticException("No Partitioning specification specified at start of a PTFChain"); } if (orderSpec == null) { orderSpec = new OrderSpec(partSpec); prevFn.setOrder(orderSpec); } while (!ptfChain.isEmpty()) { PartitionedTableFunctionSpec currentFn = (PartitionedTableFunctionSpec) ptfChain.pop(); String fnName = currentFn.getName(); if (!FunctionRegistry.isTableFunction(fnName)) { throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(fnName)); } boolean transformsRawInput = FunctionRegistry.getTableFunctionResolver(fnName).transformsRawInput(); /* * if the current table function has no partition info specified: inherit it from the PTF up * the chain. */ if (currentFn.getPartition() == null) { currentFn.setPartition(prevFn.getPartition()); if (currentFn.getOrder() == null) { currentFn.setOrder(prevFn.getOrder()); } } /* * If the current table function has no order info specified; */ if (currentFn.getOrder() == null) { currentFn.setOrder(new OrderSpec(currentFn.getPartition())); } if (!currentFn.getPartition().equals(partSpec) || !currentFn.getOrder().equals(orderSpec) || transformsRawInput) { PTFInvocationSpec component = new PTFInvocationSpec(); component.setFunction(prevFn); componentInvocations.add(component); PTFQueryInputSpec cQInSpec = new PTFQueryInputSpec(); cQInSpec.setType(PTFQueryInputType.PTFCOMPONENT); currentFn.setInput(cQInSpec); } prevFn = currentFn; partSpec = prevFn.getPartition(); orderSpec = prevFn.getOrder(); } componentInvocations.add(ptfInvocation); return componentInvocations; }
From source file:com.inmobi.conduit.distcp.tools.SimpleCopyListing.java
private void traverseNonEmptyDirectory(SequenceFile.Writer fileListWriter, FileStatus sourceStatus, Path sourcePathRoot, boolean localFile, DistCpOptions options) throws IOException { FileSystem sourceFS = sourcePathRoot.getFileSystem(getConf()); Stack<FileStatus> pathStack = new Stack<FileStatus>(); pathStack.push(sourceStatus);//w w w.j av a 2 s. c om while (!pathStack.isEmpty()) { for (FileStatus child : getChildren(sourceFS, pathStack.pop())) { if (LOG.isDebugEnabled()) LOG.debug("Recording source-path: " + sourceStatus.getPath() + " for copy."); writeToFileListing(fileListWriter, child, sourcePathRoot, localFile, options); if (isDirectoryAndNotEmpty(sourceFS, child)) { if (LOG.isDebugEnabled()) LOG.debug("Traversing non-empty source dir: " + sourceStatus.getPath()); pathStack.push(child); } } } }
From source file:FunctionParser.MathExp2SPARQL.java
private String prefixToInfix(Stack<String> stack, Stack<String> infixstack) { String s;//from www . j av a2 s .c o m while (!stack.isEmpty()) { s = stack.pop(); if (opmap.containsValue(s)) { String pop1 = infixstack.pop(); String pop2 = infixstack.pop(); //System.out.println(pop1 + s +pop2); if (s.equals("==")) s = "="; String nelem = "( " + pop1 + " " + s + " " + pop2 + " )"; infixstack.push(nelem); } else if (s.equals("CEIL")) { String nelem = "CEIL" + infixstack.pop(); infixstack.push(nelem); } else { infixstack.add(s); } } return infixstack.toString(); }
From source file:csns.importer.parser.MFTScoreParser.java
public void parse(MFTScoreImporter importer) { Department department = importer.getDepartment(); Date date = importer.getDate(); Scanner scanner = new Scanner(importer.getText()); scanner.useDelimiter("\\s+|\\r\\n|\\r|\\n"); while (scanner.hasNext()) { // last name String lastName = scanner.next(); while (!lastName.endsWith(",")) lastName += " " + scanner.next(); lastName = lastName.substring(0, lastName.length() - 1); // first name String firstName = scanner.next(); // score//from www. j av a 2 s . c o m Stack<String> stack = new Stack<String>(); String s = scanner.next(); while (!isScore(s)) { stack.push(s); s = scanner.next(); } int value = Integer.parseInt(s); // authorization code stack.pop(); // cin String cin = null; if (!stack.empty() && isCin(stack.peek())) cin = stack.pop(); // user User user = null; if (cin != null) user = userDao.getUserByCin(cin); else { List<User> users = userDao.getUsers(lastName, firstName); if (users.size() == 1) user = users.get(0); } if (user != null) { MFTScore score = mftScoreDao.getScore(department, date, user); if (score == null) { score = new MFTScore(); score.setDepartment(department); score.setDate(date); score.setUser(user); } else { logger.info(user.getId() + ": " + score.getValue() + " => " + value); } score.setValue(value); importer.getScores().add(score); } else { User failedUser = new User(); failedUser.setLastName(lastName); failedUser.setFirstName(firstName); failedUser.setCin(cin); importer.getFailedUsers().add(failedUser); } logger.debug(lastName + "," + firstName + "," + cin + "," + value); } scanner.close(); }