List of usage examples for java.util LinkedList remove
public E remove(int index)
From source file:eu.uqasar.model.tree.TreeNode.java
@SuppressWarnings("unchecked") @Override/*from w w w. j a v a 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:org.cloudata.core.common.ipc.CClient.java
/** * Makes a set of calls in parallel. Each parameter is sent to the * corresponding address. When all values are available, or have timed out or * errored, the collected results are returned in an array. The array contains * nulls for calls that timed out or errored. *///from w ww . j a v a2s .c om // public NWritable[] call(NWritable[] params, InetSocketAddress[] addresses) // throws IOException { // if (addresses.length == 0) // return new NWritable[0]; // // ParallelResults results = new ParallelResults(params.length); // synchronized (results) { // byte[] data = null; // int dataLength = 0; // // // long time1 = System.nanoTime(); // for (int i = 0; i < params.length; i++) { // final ParallelCall call = new ParallelCall(params[i], results, i); // try { // if (data == null) { // NDataOutputBuffer d = new NDataOutputBuffer(); // for serializing // // the // call.param.write(d); // data = d.getData(); // dataLength = d.getLength(); // } // parallelCallExecutor.execute(new SendTask(call, addresses[i], data, // dataLength, results)); // } catch (IOException e) { // results.size--; // wait for one fewer result // } // } // // long time2 = System.nanoTime(); // // System.out.println(">>>>>" + (time2 - time1)); // // try { // results.wait(timeout); // wait for all results // } catch (InterruptedException e) { // } // // if (results.count == 0) { // throw new SocketTimeoutException("no responses"); // } else { // return results.values; // } // } // } // class SendTask implements Runnable { // ParallelCall call; // // InetSocketAddress address; // // byte[] data; // // int dataLength; // // ParallelResults results; // // public SendTask(ParallelCall call, InetSocketAddress address, byte[] data, // int dataLength, ParallelResults results) { // this.call = call; // this.address = address; // this.data = data; // this.dataLength = dataLength; // this.results = results; // } // // public void run() { // try { // Connection connection = getConnection(address); // connection.sendParam(call, data, dataLength); // } catch (IOException e) { // synchronized (results) { // results.size--; // } // } // } // } public void closeThisConnection(InetSocketAddress address, Connection conn) { //LOG.warn("closeThisConnection:" + address + "," + this); synchronized (connections) { LinkedList<Connection> hostConnections = connections.get(address); if (hostConnections != null) { hostConnections.remove(conn); if (hostConnections.isEmpty()) { connections.remove(address); } } } conn.close(); }
From source file:org.jpos.space.HzlSpace.java
private Object getHead(Object key, boolean remove) { Object obj = null;// w ww.j av a 2 s . c om LinkedList<Object> l = this.entries.get(key); boolean wasExpirable = false; while (obj == null && l != null && l.size() > 0) { obj = l.get(0); if (obj == null) { l.remove(0); if (l.size() == 0) { entries.remove(key); } } } if (obj != null && remove) { l.remove(0); if (l.size() == 0) { this.entries.remove(key); if (wasExpirable) unregisterExpirable(key); } } this.entries.replace(key, l); return obj; }
From source file:pivotal.au.se.gemfirexdweb.controller.QueryController.java
private void addCommandToHistory(HttpSession session, UserPref prefs, String sql) { @SuppressWarnings("unchecked") LinkedList<String> historyList = (LinkedList<String>) session.getAttribute("history"); int maxsize = prefs.getHistorySize(); if (historyList.size() == maxsize) { historyList.remove((maxsize - 1)); historyList.addFirst(sql);/* ww w . j a va 2 s . c o m*/ } else { historyList.addFirst(sql); } }
From source file:se.trixon.pacoma.ui.PagePanel.java
private void init() { mDropTarget = new DropTarget() { @Override/* www . java2 s .c om*/ public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); LinkedList<File> droppedFiles = new LinkedList<>( (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)); List<File> invalidFiles = new LinkedList<>(); droppedFiles.forEach((droppedFile) -> { if (droppedFile.isFile() && FilenameUtils.isExtension(droppedFile.getName().toLowerCase(Locale.getDefault()), new String[] { "jpg", "jpeg", "png" })) { //all ok } else { invalidFiles.add(droppedFile); } }); invalidFiles.forEach((invalidFile) -> { droppedFiles.remove(invalidFile); System.out.println("remomve invalid file: " + invalidFile.getAbsolutePath()); }); droppedFiles.forEach((droppedFile) -> { System.out.println("accept: " + droppedFile.getAbsolutePath()); }); mCollage.addFiles(droppedFiles); } catch (UnsupportedFlavorException | IOException ex) { System.err.println(ex.getMessage()); } } }; setDropTarget(mDropTarget); }
From source file:playground.johannes.socialnets.NetworkGenerator2.java
public SocialNetwork generate(Population population) { random = new Random(); logger.info("Initializing social network..."); SocialNetwork net = new SocialNetwork(); for (Person p : population) { egoList.add(net.addEgo(p));/*from www . jav a 2s. c o m*/ } logger.info("Initializing degree distribution..."); TObjectIntHashMap<Ego> stubsMap = initDegreeDistribution(net.getVertices()); // try { // dumpStats(net, null, 0); // } catch (FileNotFoundException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } LinkedList<Ego> pendingNodes = new LinkedList<Ego>(net.getVertices()); Collections.shuffle(pendingNodes); while (!pendingNodes.isEmpty()) { logger.info("Starting new component..."); Ego v1 = pendingNodes.getFirst(); Collection<Ego> nextWave = new HashSet<Ego>(); int stubs = stubsMap.get(v1); for (int i = 0; i < stubs; i++) { Ego n1 = findNeighbour(v1, egoList, stubsMap, false); if (n1 == null) { pendingNodes.remove(v1); break; } if (!formConnection(v1, n1, net, stubsMap)) { /* * Should never happen (?) */ int v2stubs = stubsMap.get(v1); int v3stubs = stubsMap.get(n1); System.err.println("The selected neighbour is not valid!" + " v2stubs=" + v2stubs + ", v3stubs=" + v3stubs); System.exit(-1); } else { nextWave.add(n1); if (stubsMap.get(n1) == 0) pendingNodes.remove(n1); } } if (stubsMap.get(v1) == 0) pendingNodes.remove(v1); while (!nextWave.isEmpty()) { nextWave = closeTriads(nextWave, stubsMap, pendingNodes, net); } } int sum = 0; for (int val : stubsMap.getValues()) { sum += val; } System.err.println(sum + " stubs left!"); return net; }
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);//from w w w .j a v a 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.erdfelt.android.sdkfido.configer.ConfigCmdLineParser.java
public void parse(String[] args) throws CmdLineParseException { LinkedList<String> arglist = new LinkedList<String>(); arglist.addAll(Arrays.asList(args)); // Quick Help if (arglist.contains("--" + OPT_HELP)) { usage();//from w w w . j a v a 2 s .c om return; } // Configuration File Option int idx = arglist.indexOf("--" + OPT_CONFIG); if (idx >= 0) { if (idx + 1 > arglist.size()) { throw new CmdLineParseException("Expected <File> parameter for option: --" + OPT_CONFIG); } String value = arglist.get(idx + 1); File file = (File) ConvertUtils.convert(value, File.class); this.configer.setPersistFile(file); arglist.remove(idx + 1); arglist.remove(idx); } // Save Options Option boolean saveOptions = false; idx = arglist.indexOf("--" + OPT_SAVE); if (idx >= 0) { saveOptions = true; arglist.remove(idx); } // Restore from persist first. try { configer.restore(); } catch (IOException e) { throw new CmdLineParseException("Unable to load configuration: " + e.getMessage(), e); } // Set values from command line now. String value; ListIterator<String> iter = arglist.listIterator(); while (iter.hasNext()) { String arg = iter.next(); if (arg.startsWith("--")) { // Its an option. String optname = arg.substring(2); Configurable cfgrbl = configer.getConfigurable(optname); if (cfgrbl == null) { throw new CmdLineParseException("Invalid Option: " + arg); } if (!iter.hasNext()) { throw new CmdLineParseException( "Expected <" + cfgrbl.getType() + "> parameter for option: " + arg); } value = iter.next(); configer.setValue(optname, value); continue; // process next arg } // All others are considered args. addToRawArgs(arg); } // Save options (if specified) if (saveOptions) { try { configer.persist(); } catch (IOException e) { throw new CmdLineParseException("Unable to save configuration: " + e.getMessage(), e); } } }
From source file:org.agnitas.web.MailingStatAction.java
/** * Loads mailing statistics.// w w w.j a v a 2 s . c o m */ protected void loadMailingStat(MailingStatForm aForm, HttpServletRequest req) { //set variables from form: MailingStat aMailStat = (MailingStat) getBean("MailingStat"); aMailStat.setCompanyID(getCompanyID(req)); int tid = aForm.getTargetID(); aMailStat.setTargetID(tid); int mid = aForm.getMailingID(); aMailStat.setMailingID(mid); if (aForm.getTargetIDs() != null) { LinkedList targets = aForm.getTargetIDs(); int atid = aForm.getNextTargetID(); if (targets.contains(new Integer(atid)) == false) { targets.add(new Integer(atid)); } if (req.getParameter("delTargetID") != null) { if (targets.contains(new Integer(req.getParameter("delTargetID"))) && targets.size() > 1) { targets.remove(new Integer(req.getParameter("delTargetID"))); } } aMailStat.setTargetIDs(targets); } else { LinkedList targets = new LinkedList(); targets.add(new Integer(0)); aMailStat.setTargetIDs(targets); } // if we come from the mailstat page itself, pass statValues data: if (req.getParameter("add.x") != null) { aMailStat.setStatValues(aForm.getStatValues()); } else if (req.getParameter("delTargetID") != null) { // delete MailingStatEntry for targetID to be deleted: Hashtable tmpStatVal = aForm.getStatValues(); if (tmpStatVal.containsKey(new Integer(req.getParameter("delTargetID")))) { tmpStatVal.remove(new Integer(req.getParameter("delTargetID"))); } // and put the statValues in the MailingStat class: aMailStat.setStatValues(tmpStatVal); } else { // delete all stat info: LinkedList targets = new LinkedList(); targets.add(new Integer(0)); aMailStat.setTargetIDs(targets); Hashtable tmpStatVal = new Hashtable(); aMailStat.setStatValues(tmpStatVal); } if (aMailStat.getMailingStatFromDB(this.getWebApplicationContext(), (Locale) req.getSession().getAttribute(org.apache.struts.Globals.LOCALE_KEY)) == true) { // write results back to form: aForm.setCsvfile(aMailStat.getCsvfile()); aForm.setClickSubscribers(aMailStat.getClickSubscribers()); aForm.setClicks(aMailStat.getClicks()); aForm.setOpenedMails(aMailStat.getOpenedMails()); aForm.setOptOuts(aMailStat.getOptOuts()); aForm.setBounces(aMailStat.getBounces()); aForm.setTotalSubscribers(aMailStat.getTotalSubscribers()); aForm.setValues(aMailStat.getValues()); aForm.setMailingShortname(aMailStat.getMailingShortname()); aForm.setMailingID(mid); aForm.setStatValues(aMailStat.getStatValues()); aForm.setTargetIDs(aMailStat.getTargetIDs()); aForm.setUrlNames(aMailStat.getUrls()); aForm.setUrlShortnames(aMailStat.getUrlShortnames()); aForm.setMaxblue(aMailStat.getMaxblue()); aForm.setMaxNRblue(aMailStat.getMaxNRblue()); aForm.setMaxSubscribers(aMailStat.getMaxSubscribers()); aForm.setClickedUrls(aMailStat.getClickedUrls()); aForm.setNotRelevantUrls(aMailStat.getNotRelevantUrls()); } else { AgnUtils.logger().error("loadMailingStat: could not load mailing stats."); } }
From source file:org.accelio.jxio.WorkerCache.java
Worker getCachedWorker(String clientId) { Worker w;//from ww w .j av 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; }