List of usage examples for java.util LinkedList size
int size
To view the source code for java.util LinkedList size.
Click Source Link
From source file:eu.uqasar.model.tree.TreeNode.java
@SuppressWarnings("unchecked") @Override/*w w w .ja va 2 s.co m*/ public boolean changePositionWithNextSibling(boolean changeParents) { LinkedList<TreeNode> directSiblings = (LinkedList<TreeNode>) getMutableSiblings(); int currentIndex = directSiblings.indexOf(this); int newIndex = currentIndex + 1; if (newIndex < directSiblings.size()) { // switch currently selected node with the next one TreeNode movedNode = directSiblings.remove(currentIndex); directSiblings.add(newIndex, movedNode); getParent().setChildren(directSiblings); logger.info(String.format("Moving %s from index %s to %s", this, currentIndex, newIndex)); return true; } else if (newIndex >= directSiblings.size() && changeParents) { // add currently selected node as first entry to the next parent // sibling LinkedList<TreeNode> parentSiblings = (LinkedList<TreeNode>) this.getParent().getMutableSiblings(); int parentIndex = parentSiblings.indexOf(this.getParent()); int newParentIndex = parentIndex + 1; if (newParentIndex < parentSiblings.size()) { TreeNode oldParent = this.getParent(); LinkedList<TreeNode> oldParentChildren = oldParent.getChildren(); oldParentChildren.removeLast(); oldParent.setChildren(oldParentChildren); TreeNode newParent = parentSiblings.get(newParentIndex); logger.info(String.format("Moving %s from parent %s to %s", this, this.getParent(), newParent)); this.setParent(newParent); return true; } } return false; }
From source file:m.c.m.proxyma.context.ProxyFolderBean.java
/** * Add the a plugin to the specified list using the execution priority * to define the position of the plugin into the list. * @param pluginName the plugin name to add to the list * @param list the list to update./* w w w . j av a2 s . c om*/ */ private void addPluginUsingExecutionPriority(String pluginName, String baseXPath, ConcurrentLinkedQueue<String> list) { String pluginPriorityXPath = baseXPath + "[@class='" + pluginName + "']/@executionPriority"; int pluginPriority = 0; try { pluginPriority = Integer.parseInt(context.getSingleValueParameter(pluginPriorityXPath)); } catch (Exception x) { log.warning("executionPiority not an integer in \"" + pluginPriorityXPath + "\""); } //put the new object in the correct position based upon its execution priority LinkedList<String> tmpList = new LinkedList(list); String currentPlugin = null; int currentPluginPriority = 0; boolean inserted = false; for (int i = 0; (i < tmpList.size() && !inserted); i++) { currentPlugin = tmpList.get(i); pluginPriorityXPath = baseXPath + "[@class='" + currentPlugin + "']/@executionPriority"; try { currentPluginPriority = Integer.parseInt(context.getSingleValueParameter(pluginPriorityXPath)); } catch (Exception x) { currentPluginPriority = 0; } if (pluginPriority < currentPluginPriority) { tmpList.add(i, pluginName); inserted = true; } } //If a place for the plugin was not found the plugin is addedd on the tail if (!inserted) tmpList.add(pluginName); //Update the thread-safe queue list.removeAll(tmpList); list.addAll(tmpList); }
From source file:model.utilities.stats.collectors.PeriodicMarketObserver.java
public void attachCSVWriter(CSVWriter writer) throws IOException { this.writer = writer; LinkedList<String> row = new LinkedList<>(); row.add("price"); row.add("traded"); row.add("produced"); row.add("consumed"); row.add("day"); row.add("demand gap"); row.add("supply gap"); writer.writeNext(row.toArray(new String[row.size()])); writer.flush();/*from w w w . j a v a 2 s . co m*/ }
From source file:eu.stratosphere.nephele.multicast.MulticastManager.java
/** * This method creates a tree with an arbitrary fan out (two means binary tree). * If topology information or penalties are available, it considers that. * If fanout is set to 1, it creates a sequential tree. * if fanout is set to Integer.MAXVALUE, it creates a unicast tree. * //from w ww . ja v a 2 s.c o m * @param nodes * @param fanout * @return */ private MulticastForwardingTable createDefaultTree(LinkedList<TreeNode> nodes, int fanout) { // Store nodes that already have a parent, but no children LinkedList<TreeNode> connectedNodes = new LinkedList<TreeNode>(); final TreeNode rootnode = nodes.pollFirst(); TreeNode actualnode = rootnode; while (nodes.size() > 0) { // We still have unconnected nodes... for (int i = 0; i < fanout; i++) { if (nodes.size() > 0) { // pick the closest one and attach to actualnode TreeNode child = pollClosestNode(actualnode, nodes); actualnode.addChild(child); // The child is now connected and can be used as forwarder in the next iteration.. connectedNodes.add(child); } else { break; } } // OK.. take the next node to attach children to it.. // TODO: Optimization? "pollBest()" ? actualnode = connectedNodes.pollFirst(); } LOG.info("created multicast tree with following topology:\n" + rootnode.printTree()); return rootnode.createForwardingTable(); }
From source file:net.sf.jabref.external.ExternalFilePanel.java
/** * Creates a Runnable that searches the external file directory for the given * field name, including subdirectories, and looks for files named after the * current entry's bibtex key.// w w w . j a v a2 s . c o m * * @param fieldName * The field to set. * @param editor * An EntryEditor instance where to set the value found. * @return A reference to the Runnable that can perform the operation. */ public Runnable autoSetFile(final String fieldName, final FieldEditor editor) { Object o = getKey(); if ((o == null) || (Globals.prefs.get(fieldName + Globals.DIR_SUFFIX) == null)) { output(Localization.lang("You must set both BibTeX key and %0 directory", fieldName.toUpperCase()) + '.'); return null; } output(Localization.lang("Searching for %0 file", fieldName.toUpperCase()) + " '" + o + '.' + fieldName + "'..."); return new Runnable() { @Override public void run() { /* * Find the following directories to look in for: * * default directory for this field type. * * directory of bibtex-file. // NOT POSSIBLE at the moment. * * JabRef-directory. */ LinkedList<String> list = new LinkedList<>(); String[] dirs = metaData.getFileDirectory(fieldName); Collections.addAll(list, dirs); String found = FileFinder.findPdf(getEntry(), fieldName, list.toArray(new String[list.size()]));// , off); // To activate findFile: // String found = Util.findFile(getEntry(), null, dir, // ".*[bibtexkey].*"); if (found != null) { editor.setText(found); if (entryEditor != null) { entryEditor.updateField(editor); } output(Localization.lang("%0 field set", fieldName.toUpperCase()) + '.'); } else { output(Localization.lang("No %0 found", fieldName.toUpperCase()) + '.'); } } }; }
From source file:mulavito.algorithms.shortestpath.ksp.Yen.java
@Override protected List<List<E>> getShortestPathsIntern(final V source, final V target, int k) { LinkedList<List<E>> found_paths = new LinkedList<List<E>>(); PriorityQueue<WeightedPath> prioQ = new PriorityQueue<WeightedPath>(); DijkstraShortestPath<V, E> blockedDijkstra; // Check if target is reachable from source. if (dijkstra.getDistance(source, target) == null) return found_paths; // Add Dijkstra solution, the first shortest path. found_paths.add(dijkstra.getPath(source, target)); while (found_paths.size() < k) { List<E> curShortestPath = found_paths.getLast(); int maxIndex = curShortestPath.size(); List<V> curShortestPathNodes = new LinkedList<V>(); curShortestPathNodes.add(source); for (E e : found_paths.getLast()) { V v = graph.getEndpoints(e).getFirst(); if (!curShortestPathNodes.contains(v)) curShortestPathNodes.add(v); v = graph.getEndpoints(e).getSecond(); if (!curShortestPathNodes.contains(v)) curShortestPathNodes.add(v); }//ww w.ja va2s .c o m curShortestPathNodes.remove(target); // Split path into Head and NextEdge for (int i = 0; i < maxIndex; i++) { List<E> head = curShortestPath.subList(0, i); // V deviation = head.isEmpty() ? source : graph.getEndpoints(head.get(i - 1)).getSecond(); V deviation = curShortestPathNodes.get(i); // 1. Block edges. Graph<V, E> blocked = blockFilter(head, deviation, curShortestPathNodes, found_paths); // 2. Get shortest path in graph with blocked edges. blockedDijkstra = new DijkstraShortestPath<V, E>(blocked, nev); Number dist = blockedDijkstra.getDistance(deviation, target); if (dist == null) continue; List<E> tail = blockedDijkstra.getPath(deviation, target); // 3. Combine head and tail into new path. List<E> candidate = new ArrayList<E>(); candidate.addAll(head); candidate.addAll(tail); // Check if we already found this solution boolean duplicate = false; for (WeightedPath path : prioQ) if (ListUtils.isEqualList(path.getPath(), candidate)) { duplicate = true; break; } if (!duplicate) prioQ.add(new WeightedPath(candidate)); } if (prioQ.isEmpty()) break; // We have not found any new candidate! else found_paths.add(prioQ.poll().getPath()); } return found_paths; }
From source file:com.blocks.framework.utils.date.StringUtil.java
/** * split?//from w ww.java 2s. c om * @param line String * @param separator String * @return String[] */ public static final String[] split(String line, String separator) { LinkedList<String> list = new LinkedList<String>(); if (line != null) { int start = 0; int end = 0; int separatorLen = separator.length(); while ((end = line.indexOf(separator, start)) >= 0) { list.add(line.substring(start, end)); start = end + separatorLen; } if (start < line.length()) { list.add(line.substring(start, line.length())); } } return (String[]) list.toArray(new String[list.size()]); }
From source file:org.nekorp.workflow.desktop.view.BitacoraView.java
@Override public void updateModel(Object origen, String property, Object value) { if (!ignore.remove(value)) { LinkedList<EventoVB> param = (LinkedList<EventoVB>) value; LinkedList<EventoVB> borrar = new LinkedList<>(); for (EventoVB obj : modelo) { if (!param.contains(obj)) { borrar.add(obj);//from w ww .j a va 2s . c o m } } for (EventoVB x : borrar) { removeEvento(x); } for (int i = 0; i < param.size(); i++) { if (this.modelo.size() > i) { if (!param.get(i).equals(this.modelo.get(i))) { this.modelo.add(i, param.get(i)); addEventoView(this.modelo.get(i), i); } } else { this.modelo.add(param.get(i)); addEventoView(this.modelo.get(i), i); } } this.updateUI(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum()); } }); } }
From source file:com.bluros.updater.service.UpdateCheckService.java
@Override public void onResponse(JSONObject jsonObject) { int updateType = Utils.getUpdateType(); LinkedList<UpdateInfo> lastUpdates = State.loadState(this); LinkedList<UpdateInfo> updates = parseJSON(jsonObject.toString(), updateType); int newUpdates = 0, realUpdates = 0; for (UpdateInfo ui : updates) { if (!lastUpdates.contains(ui)) { newUpdates++;/*from ww w. ja v a 2 s .c om*/ } if (ui.isNewerThanInstalled()) { realUpdates++; } } Intent intent = new Intent(ACTION_CHECK_FINISHED); intent.putExtra(EXTRA_UPDATE_COUNT, updates.size()); intent.putExtra(EXTRA_REAL_UPDATE_COUNT, realUpdates); intent.putExtra(EXTRA_NEW_UPDATE_COUNT, newUpdates); recordAvailableUpdates(updates, intent); State.saveState(this, updates); }
From source file:net.semanticmetadata.lire.builders.GlobalDocumentBuilder.java
/** * @param image the image to analyze.//from w w w. ja v a 2 s .c o m * @return Lucene Fields. */ @Override public Field[] createDescriptorFields(BufferedImage image) { docsCreated = true; LinkedList<Field> resultList = new LinkedList<Field>(); Field[] fields; if (extractorItems.size() > 0) { for (Map.Entry<ExtractorItem, String[]> extractorItemEntry : extractorItems.entrySet()) { fields = getGlobalDescriptorFields(image, extractorItemEntry.getKey()); Collections.addAll(resultList, fields); } } return resultList.toArray(new Field[resultList.size()]); }