List of usage examples for java.util LinkedList addFirst
public void addFirst(E e)
From source file:graph.util.MyDijkstraShortestPath.java
/** * Returns a <code>List</code> of the edges on the shortest path from * <code>source</code> to <code>target</code>, in order of their * occurrence on this path. /*from www.j a va2 s .com*/ * If either vertex is not in the graph for which this instance * was created, throws <code>IllegalArgumentException</code>. */ public List<E> getPath(V source, V target) { if (!g.containsVertex(source)) throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); if (!g.containsVertex(target)) throw new IllegalArgumentException("Specified target vertex " + target + " is not part of graph " + g); LinkedList<E> path = new LinkedList<E>(); // collect path data; must use internal method rather than // calling getIncomingEdge() because getIncomingEdge() may // wipe out results if results are not cached Set<V> targets = new HashSet<V>(); targets.add(target); singleSourceShortestPath(source, targets, g.getVertexCount()); @SuppressWarnings("unchecked") Map<V, E> incomingEdges = ((SourcePathData) sourceMap.get(source)).incomingEdges; if (incomingEdges.isEmpty() || incomingEdges.get(target) == null) return path; V current = target; while (!current.equals(source)) { E incoming = incomingEdges.get(current); path.addFirst(incoming); current = ((Graph<V, E>) g).getOpposite(current, incoming); } return path; }
From source file:org.apache.metron.stellar.common.StellarCompiler.java
private void exitLambdaVariables() { Token<?> t = expression.tokenDeque.pop(); LinkedList<String> variables = new LinkedList<>(); for (; !expression.tokenDeque.isEmpty() && t != LAMBDA_VARIABLES; t = expression.tokenDeque.pop()) { variables.addFirst(t.getValue().toString()); }//from ww w. jav a 2 s. co m expression.tokenDeque.push(new Token<>(variables, List.class, getArgContext())); }
From source file:com.clustercontrol.composite.FacilityTreeComposite.java
/** * //from w w w . j a v a 2 s . c o m * @param keyword ? */ public void doSearch(String keyword) { // Check and format keyword if (null == keyword) { return; } keyword = keyword.trim(); if (keyword.isEmpty()) { return; } StructuredSelection selection = (StructuredSelection) treeViewer.getSelection(); Object targetItem = selection.getFirstElement(); FacilityTreeItem result = searchItem( (FacilityTreeItem) (null != targetItem ? targetItem : treeViewer.getInput()), keyword); if (null != result) { FacilityTreeItem trace = result; LinkedList<FacilityTreeItem> pathList = new LinkedList<>(); do { pathList.addFirst(trace); trace = trace.getParent(); } while (null != trace); TreePath path = new TreePath(pathList.toArray(new FacilityTreeItem[] {})); treeViewer.setSelection(new TreeSelection(path), true); } else { MessageDialog.openInformation(this.getShell(), Messages.getString("message"), Messages.getString("search.not.found")); treeViewer.setSelection( new StructuredSelection(((FacilityTreeItem) treeViewer.getInput()).getChildren().get(0)), true); } }
From source file:org.ow2.proactive_grid_cloud_portal.cli.CommandFactory.java
/** * Returns an ordered {@link Command} list for specified user arguments. * * @param cli the command-line arguments * @return an ordered {@link Command} list. *///from w w w . ja v a2 s .c o m protected List<Command> getCommandList(CommandLine cli, Map<String, Command> map, ApplicationContext currentContext) { LinkedList<Command> list = new LinkedList<>(); if (map.containsKey(opt(COMMON_HELP))) { list.add(map.remove(opt(COMMON_HELP))); return list; } if (map.containsKey(opt(RM_HELP))) { list.add(map.remove(opt(RM_HELP))); return list; } if (map.containsKey(opt(SCHEDULER_HELP))) { list.add(map.remove(opt(SCHEDULER_HELP))); return list; } if (map.containsKey(opt(SILENT))) { list.add(map.remove(opt(SILENT))); } if (map.containsKey(opt(DEBUG))) { list.add(map.remove(opt(DEBUG))); } if (map.containsKey(opt(URL))) { list.addFirst(map.remove(opt(URL))); } if (map.containsKey(opt(INSECURE))) { list.add(map.remove(opt(INSECURE))); } else if (map.containsKey(opt(CA_CERTS))) { list.add(map.remove(opt(CA_CERTS))); if (map.containsKey(opt(CA_CERTS_PASSWORD))) { list.add(map.remove(opt(CA_CERTS_PASSWORD))); } } if (map.containsKey(opt(SESSION_ID))) { list.add(map.remove(opt(SESSION_ID))); } else if (map.containsKey(opt(SESSION_ID_FILE))) { list.add(map.remove(opt(SESSION_ID_FILE))); } if (map.containsKey(opt(PASSWORD))) { list.add(map.remove(opt(PASSWORD))); } if (map.containsKey(opt(LOGIN))) { list.add(map.remove(opt(LOGIN))); } else if (map.containsKey(opt(CREDENTIALS))) { list.add(map.remove(opt(CREDENTIALS))); } else { // auto login String resourceType = currentContext.getResourceType(); String filename = resourceType + ".cc"; File credFile = new File(DFLT_SESSION_DIR, filename); if (credFile.exists()) { list.add(new LoginWithCredentialsCommand(credFile.getAbsolutePath(), true)); } else { String schedulerHome = ClasspathUtils.findSchedulerHome(); File defaultCredentials = new File(schedulerHome, DEFAULT_CREDENTIALS_PATH); if (defaultCredentials.exists()) { list.add(new LoginWithCredentialsCommand(defaultCredentials.getAbsolutePath(), true)); } } } if (map.containsKey(opt(INFRASTRUCTURE))) { list.add(map.remove(opt(INFRASTRUCTURE))); } if (map.containsKey(opt(POLICY))) { list.add(map.remove(opt(POLICY))); } if (map.isEmpty()) { list.add(new ImodeCommand()); } else { Command output = map.remove(opt(OUTPUT)); list.addAll(map.values()); if (output != null) { list.add(output); } } return list; }
From source file:com.google.gwt.dev.javac.typemodel.TypeOracle.java
private List<JClassType> classChain(JClassType cls) { LinkedList<JClassType> chain = new LinkedList<JClassType>(); while (cls != null) { chain.addFirst(cls); cls = cls.getSuperclass();/* w ww. j a v a 2 s . c o m*/ } return chain; }
From source file:edu.umn.msi.tropix.persistence.dao.hibernate.TropixObjectDaoImpl.java
private void addConstraintForPathPart(final String pathPart, final int index, final StringBuilder whereBuilder, final LinkedList<String> parameters) { final Matcher matcher = ID_FROM_PATH_PATTERN.matcher(pathPart); final boolean containsId = matcher.matches(); if (containsId) { whereBuilder.append(String.format(" and o%d.id = :o%dconst", index, index)); parameters.addFirst(matcher.group(1)); } else {/*from w ww . j a v a 2s . c o m*/ parameters.addFirst(pathPart); whereBuilder.append(String.format(" and o%d.name = :o%dconst", index, index)); } }
From source file:io.hops.transaction.lock.BaseINodeLock.java
protected List<INode> readUpInodes(INode leaf) throws StorageException, TransactionContextException { LinkedList<INode> pathInodes = new LinkedList<>(); pathInodes.add(leaf);/* w w w. j a va2s . co m*/ INode curr = leaf; while (curr.getParentId() != INodeDirectory.ROOT_PARENT_ID) { curr = find(TransactionLockTypes.INodeLockType.READ_COMMITTED, curr.getParentId()); if (curr == null) { break; } pathInodes.addFirst(curr); } return pathInodes; }
From source file:org.accelio.jxio.WorkerCache.java
Worker getCachedWorker(String clientId) { Worker w;/* ww w . ja v a 2 s .c o m*/ LinkedList<Worker> clientWorkers = workersCache.get(clientId); // first time this client connects or wasn't connected for a long time and was removed by LRU if (clientWorkers == null) { if (LOG.isDebugEnabled()) LOG.debug("client id " + clientId + " wasn't found in hash"); w = wp.getWorker(); if (w != null) { LinkedList<Worker> list = new LinkedList<Worker>(); list.add(w); workersCache.put(clientId, list); } return w; } // look for free worker in client's previously connected workers int pos = 0; while (pos < clientWorkers.size()) { w = clientWorkers.get(pos); if (w.isFree()) { if (LOG.isDebugEnabled()) LOG.debug("found free worker" + w + " for client id " + clientId); clientWorkers.remove(pos); clientWorkers.addFirst(w); return w; } pos++; } // no free workers to use from previously connected, get a new one w = wp.getWorker(); if (w != null) { clientWorkers.addFirst(w); if (clientWorkers.size() > MAX_ENTRY_WORKERS) { clientWorkers.removeLast(); } } return w; }
From source file:com.stimulus.archiva.domain.Volumes.java
public synchronized void setVolumePriority(int id, Priority priority) { LinkedList<Volume> list = volumes; Volume v = list.get(id);/* ww w. j a va 2 s . c o m*/ if (v.getStatus() != Volume.Status.UNUSED) // can only reorder unused return; if (priority == Priority.PRIORITY_HIGHER && id - 1 >= 0) { // cannot affect non unused vols Volume vs = list.get(id - 1); if (vs.getStatus() != Volume.Status.UNUSED) return; } list.remove(v); switch (priority) { case PRIORITY_HIGHER: if ((id - 1) <= 0) list.addFirst(v); else list.add(id - 1, v); break; case PRIORITY_LOWER: if ((id + 1) >= list.size()) list.addLast(v); else list.add(id + 1, v); break; } }
From source file:net.sf.jasperreports.engine.export.tabulator.Tabulator.java
protected Cell overlapParentCell(Cell existingCell, FrameCell currentParent) { LinkedList<FrameCell> existingParents = new LinkedList<FrameCell>(); for (FrameCell parent = existingCell.getParent(); parent != null; parent = parent.getParent()) { existingParents.addFirst(parent); }/* w w w. ja va2 s .c om*/ LinkedList<FrameCell> currentParents = new LinkedList<FrameCell>(); for (FrameCell parent = currentParent; parent != null; parent = parent.getParent()) { currentParents.addFirst(parent); } Iterator<FrameCell> existingIt = existingParents.iterator(); Iterator<FrameCell> currentIt = currentParents.iterator(); while (existingIt.hasNext()) { FrameCell existingParent = existingIt.next(); FrameCell currentCell = currentIt.hasNext() ? currentIt.next() : null; if (currentCell == null || !existingParent.equals(currentCell)) { return existingParent; } } return existingCell; }