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:com.commander4j.util.JUtility.java
public static int getActiveHostCount() { int result = 0; JHost hst = new JHost(); LinkedList<JHost> temp = Common.hostList.getHosts(); for (int j = 0; j < temp.size(); j++) { hst = (JHost) temp.get(j);/*from www . j a v a2s. c om*/ if (hst.getEnabled().equals("Y")) { if (hst.getDatabaseParameters().getjdbcDriver().equals("http") == false) { result++; } } } return result; }
From source file:nl.mindef.c2sc.nbs.olsr.pud.uplink.server.dao.impl.NodesImpl.java
@Override @Transactional(readOnly = true)//www .j av a 2s .c om @SuppressWarnings("unchecked") public List<List<Node>> getClusters(RelayServer relayServer) { try { this.txChecker.checkInTx("Nodes::getClusters"); } catch (Throwable e) { e.printStackTrace(); } List<Node> allNodes = null; if (relayServer == null) { allNodes = this.sessionFactory.getCurrentSession() .createQuery("select node from Node node order by size(node.clusterNodes) desc").list(); } else { allNodes = this.sessionFactory.getCurrentSession().createQuery( "select node from Node node where node.sender is not null and node.sender.relayServer.id = :rsId " + "order by size(node.clusterNodes) desc") .setLong("rsId", relayServer.getId().longValue()).list(); } if (allNodes.size() == 0) { return null; } List<List<Node>> clusters = new LinkedList<List<Node>>(); while (!allNodes.isEmpty()) { LinkedList<Node> cluster = new LinkedList<Node>(); Set<Node> clusterLeaders = new HashSet<Node>(); addToCluster(allNodes, clusterLeaders, cluster, allNodes.get(0), true); if (cluster.size() > 0) { Collections.sort(cluster, new NodeComparatorOnClusterNodes_ReceptionTime_MainIP()); clusters.add(cluster); } } if (clusters.size() > 0) { return clusters; } return null; }
From source file:de.quadrillenschule.azocamsyncd.ftpservice.FTPConnection.java
public void deleteFiles(int remainingNumber, LocalStorage localStorage) { if (remainingNumber < 0) { return;//from www .jav a 2s . c o m } if (ftpclient != null) { close(); } ftpclient = new FTPClient(); ftpclient.setDefaultTimeout(TIMEOUT); try { ftpclient.connect(getLastWorkingConnection()); LinkedList<AZoFTPFile> afs = discoverRemoteFiles("/", false); int todelete = afs.size() - remainingNumber; if (todelete > 0) { notify(FTPConnectionStatus.DELETING_FILES, "", -1); int i = 0; Collections.sort(afs, new Comparator<AZoFTPFile>() { @Override public int compare(AZoFTPFile o1, AZoFTPFile o2) { return o1.ftpFile.getTimestamp().compareTo(o2.ftpFile.getTimestamp()); } }); close(); LinkedList<String> deleteables = new LinkedList(); for (AZoFTPFile af : afs) { i++; if (localStorage.isFileSynced(af)) { // deleteSingleFile(lastWorkingConnection) deleteables.add((af.dir + af.ftpFile.getName())); // System.out.println("Would delete"+af.ftpFile.getName()); } if (i >= todelete) { break; } } simplyConnect(FTP.ASCII_FILE_TYPE); for (String s : deleteables) { ftpclient.deleteFile(s); } // remountSD(deleteables); notify(FTPConnectionStatus.SUCCESS, "", -1); } else { close(); } } catch (IOException ex) { close(); } close(); }
From source file:com.mtgi.analytics.BehaviorTrackingManagerImpl.java
/** * Flush any completed events to the event persister. This operation can be called * manually via JMX, or can be called on a fixed interval via the Quartz Scheduler. * This operation results in the logging of a "flush" event to the database. * //from ww w . java 2s. c o m * @return the number of events persisted */ @ManagedOperation(description = "Immediately flush all completed events to the behavior tracking database. Returns the number of events written to the database (not counting the flush event that is also logged)") public int flush() { LinkedList<BehaviorEvent> oldList = null; //rotate the buffer. synchronized (bufferSync) { oldList = writeBuffer; pendingFlush -= oldList.size(); writeBuffer = new LinkedList<BehaviorEvent>(); flushRequested = false; } //prevent no-ops from spewing a bunch of noise into the logs. if (oldList.isEmpty()) return 0; //we log flush events, so that we can correlate flush events to system //resource spikes, and also see evidence of behavior tracking //churn in the database if tuning parameters aren't set correctly. //we don't call our own start/stop/createEvents methods, because that could //recursively lead to another flush() or other nasty problems if the flush //threshold is set too small BehaviorEvent flushEvent = new FlushEvent(event.get()); if (!warned && !flushEvent.isRoot()) { warned = true; log.warn( "Flush is being called from inside an application thread! It is strongly advised the flush only be called from a dedicated, reduced-priority thread pool (are you using a SyncTaskExecutor in your spring configuration?)."); } EventDataElement data = flushEvent.addData(); flushEvent.start(); int count = oldList.size(); event.set(flushEvent); try { persister.persist(oldList); if (log.isDebugEnabled()) log.debug("Flushed " + count + " events with " + pendingFlush + " remaining"); return count; } finally { //restore stack state event.set(flushEvent.getParent()); data.add("count", count); flushEvent.stop(); //persist the flush event immediately. LinkedList<BehaviorEvent> temp = new LinkedList<BehaviorEvent>(); temp.add(flushEvent); persister.persist(temp); } }
From source file:de.quadrillenschule.azocamsyncd.ftpservice.FTPConnection.java
public void remountSD() { LinkedList<String> commands = new LinkedList<>(); commands.add("/usr/bin/refresh_sd"); telnetCommands(commands.toArray(new String[commands.size()])); }
From source file:m.c.m.proxyma.context.ProxymaContext.java
/** * Updates Context Destination Indexes.<br/> * This method is invoked from a proxy folder that has changed its * destination in order to keep aligned the internal index of the * registered proxy folders./*w w w .ja v a 2 s. c om*/ * * @param theFolder the folder that has jus been updated */ protected void updateFolderDestinationIndex(URL oldDestination, ProxyFolderBean theFolder) { //Remove the proxy-folder from the second indexing map. String destinationHost = URLUtils.getDestinationHost(oldDestination); LinkedList<ProxyFolderBean> currentSlot = null; currentSlot = proxyFoldersByDestinationHost.get(destinationHost); if (currentSlot.size() == 1) { currentSlot.remove(theFolder); proxyFoldersByDestinationHost.remove(destinationHost); } else { Iterator<ProxyFolderBean> iterator = currentSlot.iterator(); while (iterator.hasNext()) { ProxyFolderBean curFolder = iterator.next(); if (curFolder == theFolder) iterator.remove(); } } //Re-Add the proxy folder with the new destination host destinationHost = URLUtils.getDestinationHost(theFolder.getDestinationAsURL()); currentSlot = null; if (proxyFoldersByDestinationHost.containsKey(destinationHost)) { currentSlot = proxyFoldersByDestinationHost.get(destinationHost); currentSlot.add(theFolder); } else { currentSlot = new LinkedList(); currentSlot.add(theFolder); proxyFoldersByDestinationHost.put(destinationHost, currentSlot); } }
From source file:lv.semti.morphology.webservice.VerbResource.java
public String parsequery(Boolean verb) { String query = (String) getRequest().getAttributes().get("query"); try {/*w w w . j a va2 s . c o m*/ query = URLDecoder.decode(query, "UTF8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } MorphoServer.analyzer.defaultSettings(); LinkedList<Word> tokens = Splitting.tokenize(MorphoServer.analyzer, query); String debug = ""; for (Word token : tokens) { if (token.isRecognized()) debug += token.wordforms.get(0).getDescription(); else debug += token.getToken(); debug += "\n"; } debug += String.valueOf(tokens.size()); String tag = ""; if (tokens.size() == 1) tag = tagWord(tokens.get(0), verb); else tag = tagChunk(tokens); // Heiristikas vair?kv?rdu situ?cijas risin?anai if (tag == "") return debug; else return tag; }
From source file:de.quadrillenschule.azocamsyncd.ftpservice.FTPConnection.java
public LinkedList<AZoFTPFile> download(LinkedList<AZoFTPFile> afs, LocalStorage localStorage) { if (afs.size() <= 0) { return afs; }/*from w w w . ja va 2 s. c o m*/ LinkedList<AZoFTPFile> retval = new LinkedList<>(); /* for (AZoFTPFile a : afs) { retval.add(a); }*/ Collections.sort(afs, new Comparator<AZoFTPFile>() { @Override public int compare(AZoFTPFile o1, AZoFTPFile o2) { return o1.ftpFile.getTimestamp().compareTo(o2.ftpFile.getTimestamp()); } }); simplyConnect(FTP.BINARY_FILE_TYPE); notify(FTPConnectionStatus.CONNECTED, getLastWorkingConnection(), -1); if (afs.size() > 0) { AZoFTPFile af = afs.getFirst();//) { File localFile = null; try { localFile = localStorage.getLocalFile(af); } catch (IOException ex) { notify(FTPConnectionStatus.LOCALSTORAGEERROR, af.dir + af.ftpFile.getName(), -1); close(); return retval; } if (!localStorage.prepareLocalFile(localFile)) { notify(FTPConnectionStatus.LOCALSTORAGEERROR, af.dir + af.ftpFile.getName(), -1); close(); return retval; } FileOutputStream fos = null; InputStream is = null; try { fos = new FileOutputStream(localFile); ftpclient.setSoTimeout(LONG_TIMEOUT); is = ftpclient.retrieveFileStream(af.dir + af.ftpFile.getName()); cis = new CountingInputStream(is); downloadsize = af.ftpFile.getSize(); notify(FTPConnectionStatus.DOWNLOADING, af.dir + af.ftpFile.getName(), ((int) (100.0 * ((afs.indexOf(af) + 1.0) / (double) afs.size())))); // ftpclient.setDataTimeout(TIMEOUT); // ftpclient.setSoTimeout(TIMEOUT); // Files.copy(cis, localFile.toPath(), StandardCopyOption.REPLACE_EXISTING); try { IOUtils.copyLarge(cis, fos); } catch (Exception ie) { fos.close(); is.close(); } while (!ftpclient.completePendingCommand()) { try { Thread.currentThread().wait(500); } catch (InterruptedException ex) { Logger.getLogger(FTPConnection.class.getName()).log(Level.SEVERE, null, ex); } } ; is.close(); fos.close(); localStorage.setLatestIncoming(localFile); localStorage.addSyncedFile(af); notify(FTPConnectionStatus.NEW_LOCAL_FILE, localFile.getAbsolutePath(), -1); retval.add(af); notify(FTPConnectionStatus.SUCCESS, af.dir + af.ftpFile.getName(), ((int) (100.0 * ((afs.indexOf(af) + 2.0) / (double) afs.size())))); } catch (Exception ex) { try { is.close(); fos.close(); close(); localFile.delete(); simplyConnect(FTP.BINARY_FILE_TYPE); } catch (Exception ex2) { close(); } } } close(); return retval; }
From source file:com.samanamp.algorithms.RandomSelectionAlgorithm.java
public void runAlgoAndSimulation(int maxCost, int maxTime, int runs) { this.maxCost = maxCost; this.maxTime = maxTime; this.runs = runs; Random randomGen = new Random(); randomGen.setSeed(System.currentTimeMillis()); Node[] nodes = graph.vertexSet().toArray(new Node[graph.vertexSet().size()]); LinkedList<Node> selectedNodes = new LinkedList<Node>(); Node tmpNode;// w ww . j a v a2s . c o m int arraySize = nodes.length; for (int currentCost = 0; currentCost < maxCost;) { tmpNode = nodes[((int) (randomGen.nextFloat() * arraySize))]; if (tmpNode.cost + currentCost <= maxCost) { selectedNodes.add(tmpNode); currentCost += tmpNode.cost; } } System.out.println("#nodes selected: " + selectedNodes.size()); runSimulation(selectedNodes); }
From source file:com.frostwire.platform.FileSystemWalkTest.java
@Test public void testDir() throws IOException { File f1 = File.createTempFile("aaa", null); File d1 = f1.getParentFile(); final File d2 = new File(d1, "d2"); if (d2.exists()) { FileUtils.deleteDirectory(d2);//from ww w.j a v a 2 s. co m } assertTrue(d2.mkdir()); File f2 = new File(d2, "bbb"); assertTrue(f2.createNewFile()); final LinkedList<File> l = new LinkedList<>(); fs.walk(d1, new FileFilter() { @Override public boolean accept(File file) { return true; } @Override public void file(File file) { l.add(file); } }); Set<File> set = new LinkedHashSet<>(l); assertEquals(set.size(), l.size()); assertFalse(l.contains(d1)); assertTrue(l.contains(f1)); assertTrue(l.contains(d2)); assertTrue(l.contains(f2)); l.clear(); fs.walk(d1, new FileFilter() { @Override public boolean accept(File file) { return !file.equals(d2); } @Override public void file(File file) { l.add(file); } }); assertFalse(l.contains(d1)); assertTrue(l.contains(f1)); assertFalse(l.contains(d2)); assertFalse(l.contains(f2)); assertTrue(f2.delete()); assertTrue(d2.delete()); assertTrue(f1.delete()); }