List of usage examples for java.util LinkedList removeFirst
public E removeFirst()
From source file:org.alfresco.repo.rendition.StandardRenditionLocationResolverImpl.java
private RenditionLocationImpl findOrCreateTemplatedPath(NodeRef sourceNode, String path, NodeRef companyHome) { if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("FindOrCreateTemplatedPath for ").append(sourceNode).append(", ").append(path); log.debug(msg.toString());/*from w ww . j a v a 2 s . c o m*/ } NodeService nodeService = serviceRegistry.getNodeService(); List<String> pathElements = Arrays.asList(path.split("/")); LinkedList<String> folderElements = new LinkedList<String>(pathElements); // We need to strip out any empty strings within the path elements. // prior to passing this path to the fileFolderService for creation. // e.g. "//foo//bar///item.txt" would cause an exception. folderElements.removeAll(Arrays.asList(new String[] { "" })); // Remove 'Company Home' if it is at the start of the path. Serializable companyHomeName = nodeService.getProperty(companyHome, ContentModel.PROP_NAME); if (folderElements.getFirst().equals(companyHomeName)) { folderElements.removeFirst(); } String fileName = folderElements.removeLast(); if (fileName == null || fileName.length() == 0) { StringBuilder msg = new StringBuilder(); msg.append("The path must include a valid filename! Path: ").append(path); if (log.isDebugEnabled()) { log.debug(msg.toString()); } throw new RenditionServiceException(msg.toString()); } FileFolderService fileFolderService = serviceRegistry.getFileFolderService(); NodeRef parent = companyHome; if (!folderElements.isEmpty()) { FileInfo parentInfo = FileFolderUtil.makeFolders(fileFolderService, companyHome, folderElements, ContentModel.TYPE_FOLDER); parent = parentInfo.getNodeRef(); } if (log.isDebugEnabled()) { log.debug("folderElements: " + folderElements); log.debug("parent: " + parent); log.debug(" " + nodeService.getType(parent) + " " + nodeService.getPath(parent)); log.debug("fileName: " + fileName); } NodeRef child = fileFolderService.searchSimple(parent, fileName); if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("RenditionLocation parent=").append(parent).append(", child=").append(child) .append(", fileName=").append(fileName); log.debug(msg.toString()); if (child != null) { log.debug("child path = " + nodeService.getPath(child)); } } return new RenditionLocationImpl(parent, child, fileName); }
From source file:com.redhat.rcm.version.mgr.VersionManager.java
protected List<PomPeek> peekAtPomHierarchy(final File topPom, final VersionManagerSession session) throws IOException { final LinkedList<File> pendingPoms = new LinkedList<File>(); pendingPoms.add(topPom.getCanonicalFile()); final String topDir = topPom.getParentFile().getCanonicalPath(); final Set<File> seen = new HashSet<File>(); final List<PomPeek> peeked = new ArrayList<PomPeek>(); while (!pendingPoms.isEmpty()) { final File pom = pendingPoms.removeFirst(); seen.add(pom);/*from w w w . j a v a 2 s .c o m*/ logger.info("PEEK: " + pom); final PomPeek peek = new PomPeek(pom); final FullProjectKey key = peek.getKey(); if (key != null) { session.addPeekPom(key, pom); peeked.add(peek); final File dir = pom.getParentFile(); final String relPath = peek.getParentRelativePath(); if (relPath != null) { logger.info("Found parent relativePath: " + relPath + " in pom: " + pom); File parent = new File(dir, relPath); if (parent.isDirectory()) { parent = new File(parent, "pom.xml"); } logger.info("Looking for parent POM: " + parent); parent = parent.getCanonicalFile(); if (parent.getParentFile().getCanonicalPath().startsWith(topDir) && parent.exists() && !seen.contains(parent) && !pendingPoms.contains(parent)) { pendingPoms.add(parent); } else { logger.info("Skipping reference to non-existent parent relativePath: '" + relPath + "' in: " + pom); } } final Set<String> modules = peek.getModules(); if (modules != null && !modules.isEmpty()) { for (final String module : modules) { logger.info("Found module: " + module + " in pom: " + pom); File modPom = new File(dir, module); if (modPom.isDirectory()) { modPom = new File(modPom, "pom.xml"); } logger.info("Looking for module POM: " + modPom); if (modPom.getParentFile().getCanonicalPath().startsWith(topDir) && modPom.exists() && !seen.contains(modPom) && !pendingPoms.contains(modPom)) { pendingPoms.addLast(modPom); } else { logger.info("Skipping reference to non-existent module: '" + module + "' in: " + pom); } } } } else { logger.info("Skipping " + pom + " as its a template file."); } } return peeked; }
From source file:com.erudika.scoold.controllers.QuestionController.java
@GetMapping({ "/{id}", "/{id}/{title}" }) public String get(@PathVariable String id, @PathVariable(required = false) String title, @RequestParam(required = false) String sortby, HttpServletRequest req, HttpServletResponse res, Model model) {//from w ww . j a v a2s .c o m Post showPost = pc.read(id); if (showPost == null || !ParaObjectUtils.typesMatch(showPost)) { return "redirect:" + QUESTIONSLINK; } Profile authUser = utils.getAuthUser(req); if (!utils.canAccessSpace(authUser, showPost.getSpace())) { return "redirect:" + (utils.isDefaultSpacePublic() ? QUESTIONSLINK : SIGNINLINK + "?returnto=" + showPost.getPostLink(false, false)); } Pager itemcount = utils.getPager("page", req); itemcount.setSortby("newest".equals(sortby) ? "timestamp" : "votes"); List<Reply> answerslist = showPost.getAnswers(itemcount); LinkedList<Post> allPosts = new LinkedList<Post>(); allPosts.add(showPost); allPosts.addAll(answerslist); utils.fetchProfiles(allPosts); utils.getComments(allPosts); utils.updateViewCount(showPost, req, res); model.addAttribute("path", "question.vm"); model.addAttribute("title", utils.getLang(req).get("questions.title") + " - " + showPost.getTitle()); model.addAttribute("description", Utils.abbreviate(Utils.stripAndTrim(showPost.getBody(), " "), 195)); model.addAttribute("itemcount", itemcount); model.addAttribute("showPost", allPosts.removeFirst()); model.addAttribute("answerslist", allPosts); model.addAttribute("similarquestions", utils.getSimilarPosts(showPost, new Pager(10))); model.addAttribute("maxCommentLength", Comment.MAX_COMMENT_LENGTH); model.addAttribute("maxCommentLengthError", Utils.formatMessage(utils.getLang(req).get("maxlength"), Comment.MAX_COMMENT_LENGTH)); return "base"; }
From source file:org.apache.hadoop.hdfs.server.datanode.TestDirectoryScannerInlineFiles.java
@Test public void testInlineBlocks() throws Exception { LinkedList<Long> newFormatBlocks = new LinkedList<Long>(); // Test 1: blocks on disk and not in memory for (int i = 0; i < 100; i++) { newFormatBlocks.add(createInlineBlockFile(checksumType)); }//from w w w . j av a 2 s .c o m totalBlocks += newFormatBlocks.size(); checker().setTotalBlocks(totalBlocks).setDiffSize(newFormatBlocks.size()).setMissingMetaFile(0) .setMissingBlockFile(0).setMissingMemoryBlocks(newFormatBlocks.size()).setMismatchBlocks(0) .scanAndAssert(); checker().setTotalBlocks(totalBlocks).setZeroDiff().scanAndAssert(); // Test 2: removed some blocks from disk for (int i = 0; i < 5; i++) { removeFromDisk(newFormatBlocks.removeFirst()); totalBlocks--; } checker().setTotalBlocks(totalBlocks).setDiffSize(5).setMissingMetaFile(5).setMissingBlockFile(5) .setMissingMemoryBlocks(0).setMismatchBlocks(0).scanAndAssert(); checker().setTotalBlocks(totalBlocks).setZeroDiff().scanAndAssert(); // Test 3: removed some blocks from memory for (int i = 0; i < 5; i++) { removeFromMemory(newFormatBlocks.removeFirst()); } checker().setTotalBlocks(totalBlocks).setDiffSize(5).setMissingMetaFile(0).setMissingBlockFile(0) .setMissingMemoryBlocks(5).setMismatchBlocks(0).scanAndAssert(); checker().setTotalBlocks(totalBlocks).setZeroDiff().scanAndAssert(); // Test 3: truncate some blocks for (int i = 0; i < 5; i++) { truncateOnDisk(newFormatBlocks.removeFirst()); } checker().setTotalBlocks(totalBlocks).setDiffSize(5).setMissingMetaFile(0).setMissingBlockFile(0) .setMissingMemoryBlocks(0).setMismatchBlocks(5).scanAndAssert(); checker().setTotalBlocks(totalBlocks).setZeroDiff().scanAndAssert(); // Test 4: truncate some, remove from memory some, remove from disk some for (int i = 0; i < 5; i++) { removeFromDisk(newFormatBlocks.removeFirst()); totalBlocks--; } for (int i = 0; i < 7; i++) { removeFromMemory(newFormatBlocks.removeFirst()); } for (int i = 0; i < 11; i++) { truncateOnDisk(newFormatBlocks.removeFirst()); } checker().setTotalBlocks(totalBlocks).setDiffSize(5 + 7 + 11).setMissingMetaFile(5).setMissingBlockFile(5) .setMissingMemoryBlocks(7).setMismatchBlocks(11).scanAndAssert(); checker().setTotalBlocks(totalBlocks).setZeroDiff().scanAndAssert(); }
From source file:com.ccc.ccm.client.activemq.StoreablePooledConnectionFactory.java
public synchronized Connection createConnection(String userName, String password) throws JMSException { if (stopped.get()) { LOG.debug("PooledConnectionFactory is stopped, skip create new connection."); return null; }//w w w . j ava2 s .c om ConnectionKey key = new ConnectionKey(userName, password); LinkedList<ConnectionPool> pools = cache.get(key); if (pools == null) { pools = new LinkedList<ConnectionPool>(); cache.put(key, pools); } ConnectionPool connection = null; if (pools.size() == maxConnections) { connection = pools.removeFirst(); } // Now.. we might get a connection, but it might be that we need to // dump it.. if (connection != null && connection.expiredCheck()) { connection = null; } if (connection == null) { ActiveMQConnection delegate = createConnection(key); connection = createConnectionPool(delegate); } pools.add(connection); return new PooledConnection(connection); }
From source file:org.fusesource.mop.MOP.java
private void listCommand(LinkedList<String> argList) throws Exception { String type = "installed"; if (!argList.isEmpty()) { type = argList.removeFirst(); }/*from ww w . jav a2 s.co m*/ this.artifactIds = parseArtifactList(argList); Set<ArtifactId> artifactIds = repository.list(type); for (ArtifactId a : artifactIds) { System.out.println(a); } }
From source file:org.commonjava.emb.project.ProjectLoader.java
private void addProjects(final ProjectToolsSession session, final List<MavenProject> projects) { final DependencyGraph depGraph = session.getDependencyGraph(); for (final MavenProject project : projects) { final LinkedList<Artifact> parentage = new LinkedList<Artifact>(); MavenProject parent = project;/*from w w w .j a v a 2 s. c o m*/ while (parent != null) { final org.apache.maven.artifact.Artifact pomArtifact = mavenRepositorySystem .createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "pom"); final Artifact aetherPomArtifact = RepositoryUtils.toArtifact(pomArtifact); parentage.addFirst(aetherPomArtifact); parent = parent.getParent(); } Artifact current = parentage.removeFirst(); while (!parentage.isEmpty()) { final Artifact next = parentage.getFirst(); // This is WEIRD, but the parent POM is actually a dependency of the current one, // since it's required in order to build the current project... if (LOGGER.isDebugEnabled()) { LOGGER.debug("Marking parent POM: " + current + " as dependency of POM: " + next); } depGraph.addDependency(next, current, true, true); if (!parentage.isEmpty()) { current = parentage.removeFirst(); } } } }
From source file:org.cloudata.core.common.ipc.CClient.java
/** * Get a connection from the pool, or create a new one and add it to the pool. * Connections to a given host/port are reused. *//* www .j av a 2s . co m*/ private Connection getConnection(InetSocketAddress address) throws IOException { Connection connection; synchronized (connections) { LinkedList<Connection> hostConnections = connections.get(address); if (hostConnections == null) { hostConnections = new LinkedList<Connection>(); connections.put(address, hostConnections); } if (hostConnections.isEmpty()) { connection = new Connection(address); } else { connection = hostConnections.removeFirst(); } connection.touch(); } // we don't invoke the method below inside "synchronized (connections)" // block above. The reason for that is if the server happens to be slow, // it will take longer to establish a connection and that will slow the // entire system down. connection.setupIOstreams(); return connection; }
From source file:org.fusesource.mop.MOP.java
private ArrayList<ArtifactId> parseArtifactList(LinkedList<String> values) throws UsageException { ArrayList<ArtifactId> rc = new ArrayList<ArtifactId>(); assertNotEmpty(values);//from ww w. ja va 2 s. c om String value = values.removeFirst(); ArtifactId id = parseArtifactId(value); rc.add(id); while (!values.isEmpty() && isAnotherArtifactId(values.getFirst())) { value = values.removeFirst().substring(1); id = parseArtifactId(value); rc.add(id); } return rc; }
From source file:org.fusesource.mop.MOP.java
private void execJava(LinkedList<String> argList) throws Exception { assertNotEmpty(argList);//from w ww. j a v a 2s . c om artifactIds = parseArtifactList(argList); assertNotEmpty(argList); className = argList.removeFirst(); reminingArgs = argList; List<File> dependencies = resolveFiles(); execClass(dependencies); }