List of usage examples for java.util LinkedList addFirst
public void addFirst(E e)
From source file:org.drugis.mtc.graph.MinimumDiameterSpanningTree.java
private void addPath(DelegateTree<V, E> tree, V u, V v) { Map<V, E> incomingEdgeMap = d_shortestPath.getIncomingEdgeMap(u); LinkedList<V> path = new LinkedList<V>(); while (!v.equals(u)) { path.addFirst(v); E e = incomingEdgeMap.get(v);// ww w . j av a 2 s .c o m List<V> incidentVertices = new ArrayList<V>(d_graph.getIncidentVertices(e)); v = incidentVertices.get(0).equals(v) ? incidentVertices.get(1) : incidentVertices.get(0); } path.addFirst(u); for (int i = 0; i < path.size() - 1; ++i) { E e = d_graph.findEdge(path.get(i), path.get(i + 1)); if (!tree.containsEdge(e)) { tree.addChild(e, path.get(i), path.get(i + 1)); } } }
From source file:com.github.javarch.support.data.LocalFileStorage.java
public String storeFile(FileData fileData) { File file = new File(storageDirectory, fileData.getName()); if (file.exists()) { file.delete();/*from w w w .j a va 2s. c o m*/ } File parent = file.getParentFile(); if (parent != null && !parent.equals(storageDirectory)) { parent.mkdirs(); } LinkedList<File> parents = new LinkedList<File>(); while (parent != null && !parent.equals(storageDirectory)) { parents.addFirst(parent); parent = parent.getParentFile(); } if (deleteOnExit) { for (File p : parents) { p.deleteOnExit(); } file.deleteOnExit(); } try { file.createNewFile(); FileOutputStream os = new FileOutputStream(file); os.write(fileData.getBytes()); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return file.toURI().toString(); }
From source file:org.apache.directory.studio.templateeditor.EntryTemplatePluginUtils.java
/** * Gets the list of matching templates for the given object class description. * <p>/*from w w w . j ava2 s. c o m*/ * To do this, we're using a "Breadth First Search" algorithm to go through all * the superiors (and the superiors of these superiors, etc.). * * @param objectClassDescription * the object class description * @param schema * the associated schema * @return * the list of matching templates for the given object class description */ private static List<Template> getTemplatesFromHighestObjectClass(ObjectClass objectClassDescription, Schema schema) { // Creating a set to hold all the matching templates List<Template> matchingTemplates = new ArrayList<Template>(); // Getting the templates manager TemplatesManager manager = EntryTemplatePlugin.getDefault().getTemplatesManager(); // Getting the list of all the available templates Template[] templates = manager.getTemplates(); // Creating a MultiValueMap that holds the templates ordered by ObjectClassDescription object MultiValueMap templatesByOcd = new MultiValueMap(); // Populating this map for (Template template : templates) { templatesByOcd.put(getObjectClass(template.getStructuralObjectClass(), schema), template); } // Initializing the LIFO queue with the highest ObjectClassDescription object LinkedList<ObjectClass> ocdQueue = new LinkedList<ObjectClass>(); ocdQueue.add(objectClassDescription); // Looking if we need to test a new ObjectClassDescription object while (!ocdQueue.isEmpty()) { // Dequeuing the last object for testing ObjectClass currentOcd = ocdQueue.removeLast(); // Adds the templates for the current object class description to the list of matching templates addTemplatesForObjectClassDescription(currentOcd, matchingTemplates, manager); // Adding each superior object to the queue List<String> currentOcdSups = currentOcd.getSuperiorOids(); if (currentOcdSups != null) { for (String currentOcdSup : currentOcdSups) { ocdQueue.addFirst(getObjectClass(currentOcdSup, schema)); } } } return matchingTemplates; }
From source file:ch.tatool.core.element.NodeImpl.java
/** * Unique id of the element. This includes the localId of the parent elements as well * and has to be unique in a element/handler tree *//*from w ww. jav a 2 s . com*/ public String getId() { LinkedList<Node> nodes = new LinkedList<Node>(); Node u = this; while (u != null) { nodes.addFirst(u); u = u.getParent(); } StringBuilder builder = new StringBuilder(); Iterator<Node> it = nodes.iterator(); // add first element (we know we have at least one!) NodeImpl n = (NodeImpl) it.next(); builder.append(n.getLocalId()); while (it.hasNext()) { n = (NodeImpl) it.next(); builder.append('.'); builder.append(n.getLocalId()); } return builder.toString(); }
From source file:hudson.widgets.BuildHistoryWidget.java
/** * Returns the queue item if the owner is scheduled for execution in the queue, in REVERSE ORDER *//* w w w. j a va 2 s . c om*/ public List<Item> getQueuedItems() { LinkedList<Item> list = new LinkedList<Item>(); for (Item item : Jenkins.getInstance().getQueue().getApproximateItemsQuickly()) { if (item.task == owner) { list.addFirst(item); } } return list; }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans.java
public LinkedList<Mutable<ILogicalOperator>> allRootsInReverseOrder() { LinkedList<Mutable<ILogicalOperator>> allRoots = new LinkedList<Mutable<ILogicalOperator>>(); for (ILogicalPlan p : nestedPlans) { for (Mutable<ILogicalOperator> r : p.getRoots()) { allRoots.addFirst(r); }//from ww w . j a v a2 s . c o m } return allRoots; }
From source file:com.intirix.cloudpasswordmanager.pages.BaseActivity.java
protected void addNavigationItems(LinkedList<NavigationItem> navItems) { if (autoLogoffService.isSessionStillValid()) { navItems.addFirst(new LogOffNavigationItem(this, sessionService)); navItems.addLast(new PasswordListNavigationItem(this)); navItems.addLast(new SettingsNavigationItem(this)); } else {//from ww w.ja v a 2 s.com navItems.addFirst(new LoginNavigationItem(this)); } navItems.addLast(new AboutNavigationItem(this)); }
From source file:com.kajj.tools.logviewer.LogRepository.java
/** * Returns the last <code>numberOfLines</code> lines from the log file. * * @param fileName the name of the log file. * @param numberOfLines the number of lines to return. * @return The last <code>numberOfLines</code> lines in the log file. * @throws IOException if an I/O exception occurs reading the log file. *///w w w . ja v a2 s .c om public List<String> getTailLog(final String fileName, final int numberOfLines) throws IOException { final File logFile = new File(LOG_DIRECTORY, fileName); final ReversedLinesFileReader reader = new ReversedLinesFileReader(logFile); final LinkedList<String> logs = new LinkedList<>(); for (int i = 0; i < numberOfLines; i++) { final String line = reader.readLine(); if (line == null) { break; } logs.addFirst(line); } return logs; }
From source file:org.dcm4che3.conf.core.misc.DeepEquals.java
/** * Deeply compare two SortedMap instances. This method walks the Maps in order, * taking advantage of the fact that they Maps are SortedMaps. * @param map1 SortedMap one/*from w ww .ja va 2s. co m*/ * @param map2 SortedMap two * @param stack add items to compare to the Stack (Stack versus recursion) * @param visited Set containing items that have already been compared, to prevent cycles. * @return false if the Maps are for certain not equals. 'true' indicates that 'on the surface' the maps * are equal, however, it will place the contents of the Maps on the stack for further comparisons. */ private static boolean compareSortedMap(SortedMap map1, SortedMap map2, LinkedList stack, Set visited) { // Same instance check already performed... if (map1.size() != map2.size()) { return false; } Iterator i1 = map1.entrySet().iterator(); Iterator i2 = map2.entrySet().iterator(); while (i1.hasNext()) { Map.Entry entry1 = (Map.Entry) i1.next(); Map.Entry entry2 = (Map.Entry) i2.next(); // Must split the Key and Value so that Map.Entry's equals() method is not used. DualKey dk = new DualKey(entry1.getKey(), entry2.getKey()); if (!visited.contains(dk)) { // Push Keys for further comparison stack.addFirst(dk); } dk = new DualKey(entry1.getValue(), entry2.getValue()); if (!visited.contains(dk)) { // Push values for further comparison stack.addFirst(dk); } } return true; }
From source file:org.openiam.idm.srvc.synch.srcadapter.SynchScriptFactory.java
public static List<TransformScript> createTransformationScript(SynchConfig config, SynchReview review) throws ClassNotFoundException, IOException { Map<String, Object> bindingMap = new HashMap<String, Object>(); bindingMap.put("config", config); bindingMap.put("synchConfigId", config.getSynchConfigId()); if (review != null) { bindingMap.put("review", review); }/* w w w . ja v a 2 s .c o m*/ LinkedList<TransformScript> scripts = new LinkedList<TransformScript>(); if (config.getUsePolicyMap()) { AttributeMapDozerConverter attributeMapDozerConverter = (AttributeMapDozerConverter) SpringContextProvider .getBean("attributeMapDozerConverter"); IdentitySynchService synchService = (IdentitySynchService) SpringContextProvider .getBean("synchService"); List<AttributeMapEntity> attrMapEntity = synchService .getSynchConfigAttributeMaps(config.getSynchConfigId()); List<AttributeMap> attrMap = attributeMapDozerConverter.convertToDTOList(attrMapEntity, true); TransformScript transformScript = new PolicyMapTransformScript(attrMap); scripts.add(transformScript); } if (config.getUseTransformationScript() && StringUtils.isNotBlank(config.getTransformationRule())) { TransformScript script = (TransformScript) createScript(config.getTransformationRule(), bindingMap); if (config.getPolicyMapBeforeTransformation()) { scripts.addLast(script); } else { scripts.addFirst(script); } } return scripts; }