List of usage examples for java.util Stack push
public E push(E item)
From source file:app.web.ApplicationITCase.java
@Test public void testApplication() { //goToHomepage(); selenium.open(APPLICATION_HOMEPAGE); Stack<URL> locationStack = new Stack<URL>(); locationStack.push(toLocationPath(APPLICATION_HOMEPAGE)); testPageRecursively(locationStack);/*from w w w. j a va 2s.c o m*/ }
From source file:org.apache.maven.shared.release.phase.AbstractReleaseTestCase.java
protected List<MavenProject> createReactorProjects(String path, String targetPath, String subpath) throws Exception { File testFile = getTestFile("target/test-classes/projects/" + path + subpath + "/pom.xml"); Stack<File> projectFiles = new Stack<File>(); projectFiles.push(testFile); List<DefaultArtifactRepository> repos = Collections.singletonList( new DefaultArtifactRepository("central", getRemoteRepositoryURL(), new DefaultRepositoryLayout())); Repository repository = new Repository(); repository.setId("central"); repository.setUrl(getRemoteRepositoryURL()); ProfileManager profileManager = new DefaultProfileManager(getContainer()); Profile profile = new Profile(); profile.setId("profile"); profile.addRepository(repository);//from ww w .j ava2 s . c o m profileManager.addProfile(profile); profileManager.activateAsDefault(profile.getId()); List<MavenProject> reactorProjects = new ArrayList<MavenProject>(); while (!projectFiles.isEmpty()) { File file = (File) projectFiles.pop(); // Recopy the test resources since they are modified in some tests String filePath = file.getPath(); int index = filePath.indexOf("test-classes") + "test-classes".length() + 1; filePath = filePath.substring(index).replace('\\', '/'); File newFile = getTestFile("target/test-classes/" + StringUtils.replace(filePath, path, targetPath)); FileUtils.copyFile(getTestFile("src/test/resources/" + filePath), newFile); MavenProject project = projectBuilder.build(newFile, localRepository, profileManager); for (Iterator i = project.getModules().iterator(); i.hasNext();) { String module = (String) i.next(); projectFiles.push(new File(file.getParentFile(), module + "/pom.xml")); } reactorProjects.add(project); } ProjectSorter sorter = new ProjectSorter(reactorProjects); reactorProjects = sorter.getSortedProjects(); ArtifactFactory artifactFactory = (ArtifactFactory) lookup(ArtifactFactory.ROLE); ArtifactCollector artifactCollector = (ArtifactCollector) lookup(ArtifactCollector.class.getName()); ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource) lookup( ArtifactMetadataSource.ROLE); // pass back over and resolve dependencies - can't be done earlier as the order may not be correct for (Iterator i = reactorProjects.iterator(); i.hasNext();) { MavenProject project = (MavenProject) i.next(); project.setRemoteArtifactRepositories(repos); project.setPluginArtifactRepositories(repos); Artifact projectArtifact = project.getArtifact(); Map managedVersions = createManagedVersionMap( ArtifactUtils.versionlessKey(projectArtifact.getGroupId(), projectArtifact.getArtifactId()), project.getDependencyManagement(), artifactFactory); project.setDependencyArtifacts(project.createArtifacts(artifactFactory, null, null)); ArtifactResolutionResult result = artifactCollector.collect(project.getDependencyArtifacts(), projectArtifact, managedVersions, localRepository, repos, artifactMetadataSource, null, Collections.EMPTY_LIST); project.setArtifacts(result.getArtifacts()); } return reactorProjects; }
From source file:org.abstracthorizon.proximity.storage.local.ReadOnlyFileSystemStorage.java
public void recreateMetadata(Map extraProps) throws StorageException { // issue #44, we will not delete existing metadata, // instead, we will force to "recreate" those the properties factory // eventually appending it with new ones. int processed = 0; Stack stack = new Stack(); List dir = listItems(ItemProperties.PATH_ROOT); stack.push(dir); while (!stack.isEmpty()) { dir = (List) stack.pop(); for (Iterator i = dir.iterator(); i.hasNext();) { ItemProperties ip = (ItemProperties) i.next(); if (ip.isDirectory()) { List subdir = listItems(ip.getPath()); stack.push(subdir);/*from w w w. j ava2s . c o m*/ } else { logger.debug("**** {}", ip.getPath()); File target = new File(getStorageBaseDir(), ip.getPath()); ItemProperties nip = getProxiedItemPropertiesFactory().expandItemProperties(ip.getPath(), target, false); if (extraProps != null) { nip.getAllMetadata().putAll(extraProps); } storeItemProperties(nip); processed++; } } } logger.info("Recreated metadata on {} items.", Integer.toString(processed)); }
From source file:net.riezebos.thoth.commands.CommentCommand.java
protected Section parseSections(String body, String contextName, String fileName) throws ContentManagerException { CommentManager commentManager = getThothEnvironment().getCommentManager(); Pattern sectionStartPattern = Pattern.compile(DETAILSTART + "(.*?)" + MARKER); Pattern sectionEndPattern = Pattern.compile(DETAILEND); Stack<Section> sections = new Stack<>(); Section main = new Section(fileName); main.setComments(commentManager.getComments(contextName, fileName, null)); sections.push(main); for (String line : body.split("\n")) { Matcher matcher = sectionStartPattern.matcher(line); if (matcher.find()) { String path = matcher.group(1); Section subSection = new Section(path); List<Comment> comments = commentManager.getComments(contextName, path, null); subSection.setComments(comments); sections.peek().addSection(subSection); sections.push(subSection);/* ww w .ja v a2 s .co m*/ } else if (sectionEndPattern.matcher(line).find()) { sections.pop(); } else sections.peek().addSection(line); } return main; }
From source file:atter.jedis.RedisCacheTemplateTest.java
@Test public void testStack() { String key = "orderStack"; String orderId = "orderStack1"; String order = "orderABC"; String orderId1 = "orderStack2"; String order1 = "orderABC"; String orderId2 = "orderStack3"; String order2 = "orderABC"; Stack stack = cacheTemplate.getStack(key); stack.push(order); stack.push(order1);// ww w. j a v a2 s .co m stack.push(order2); stack.push(orderId); stack.push(orderId1); stack.push(orderId2); for (int i = 0; i < 6; i++) { String savedOrder = (String) stack.pop(); // switch (i) { case 0: assertEquals("??", orderId2, savedOrder); break; case 1: assertEquals("??", orderId1, savedOrder); break; case 2: assertEquals("??", orderId, savedOrder); break; case 3: assertEquals("??", order2, savedOrder); break; case 4: assertEquals("??", order1, savedOrder); break; case 5: assertEquals("??", order, savedOrder); break; } } }
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 .ja v a 2s.c om*/ 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:ar.com.zauber.commons.spring.servlet.mvc.support.ZauberBeanNameBasedClassNameHandlerMapping.java
/** * <ul>/*from www .ja va 2s . c o m*/ * <li>ChangePassword -> password/change</li> * <li>changePassword -> password/change</li> * <li>login -> login</li> * </ul> * */ protected final String getCompoundPath(final String s) { final Stack<String> stack = new Stack<String>(); final int n = s.length(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { final char c = s.charAt(i); if (Character.isUpperCase(c)) { if (sb.length() > 0) { stack.push(sb.toString()); sb = new StringBuilder(); } sb.append(Character.toLowerCase(c)); } else { sb.append(c); } } if (sb.length() > 0) { stack.push(sb.toString()); sb = new StringBuilder(); } while (!stack.isEmpty()) { sb.append(stack.pop()); sb.append('/'); } return sb.toString(); }
From source file:ru.emdev.ldap.util.EmDevSchemaLdifExtractor.java
/** * Calculates the destination file./*from w w w . ja va 2 s. c om*/ * * @param resource the source file * @return the destination file's parent directory */ private File getDestinationFile(File resource) { File parent = resource.getParentFile(); Stack<String> fileComponentStack = new Stack<String>(); fileComponentStack.push(resource.getName()); while (parent != null) { if (parent.getName().equals("schema")) { // All LDIF files besides the schema.ldif are under the // schema/schema base path. So we need to add one more // schema component to all LDIF files minus this schema.ldif fileComponentStack.push("schema"); return assembleDestinationFile(fileComponentStack); } fileComponentStack.push(parent.getName()); if (parent.equals(parent.getParentFile()) || parent.getParentFile() == null) { throw new IllegalStateException(I18n.err(I18n.ERR_08005)); } parent = parent.getParentFile(); } /* this seems retarded so I replaced it for now with what is below it will not break from loop above unless parent == null so the if is never executed - just the else is executed every time if ( parent != null ) { return assembleDestinationFile( fileComponentStack ); } else { throw new IllegalStateException( "parent cannot be null" ); } */ throw new IllegalStateException(I18n.err(I18n.ERR_08006)); }
From source file:com.webcohesion.ofx4j.io.nanoxml.TestNanoXMLOFXReader.java
/** * tests whitespace before and after// www. j av a2 s .c om */ public void testWhitespaceBeforeAndAfter() throws Exception { NanoXMLOFXReader reader = new NanoXMLOFXReader(); final Map<String, List<String>> headers = new HashMap<String, List<String>>(); final Stack<Map<String, List<Object>>> aggregateStack = new Stack<Map<String, List<Object>>>(); TreeMap<String, List<Object>> root = new TreeMap<String, List<Object>>(); aggregateStack.push(root); reader.setContentHandler(getNewDefaultHandler(headers, aggregateStack)); reader.parse(TestNanoXMLOFXReader.class.getResourceAsStream("whitespace-example.ofx")); assertEquals(9, headers.size()); assertEquals(1, aggregateStack.size()); assertSame(root, aggregateStack.pop()); TreeMap<String, List<Object>> OFX = (TreeMap<String, List<Object>>) root.remove("OFX").get(0); assertNotNull(OFX); assertEquals("E", OFX.remove("S").get(0)); assertTrue(OFX.isEmpty()); assertTrue(root.isEmpty()); }
From source file:org.apache.hadoop.tools.mapred.TestCopyCommitter.java
private boolean checkDirectoryPermissions(FileSystem fs, String targetBase, FsPermission sourcePerm) throws IOException { Path base = new Path(targetBase); Stack<Path> stack = new Stack<Path>(); stack.push(base); while (!stack.isEmpty()) { Path file = stack.pop();/*from ww w . j a v a2 s . c om*/ if (!fs.exists(file)) continue; FileStatus[] fStatus = fs.listStatus(file); if (fStatus == null || fStatus.length == 0) continue; for (FileStatus status : fStatus) { if (status.isDirectory()) { stack.push(status.getPath()); Assert.assertEquals(status.getPermission(), sourcePerm); } } } return true; }