List of usage examples for java.util LinkedList iterator
Iterator<E> iterator();
From source file:at.medevit.elexis.gdt.tools.DirectoryWatcher.java
public void watch() { logger.log("Watching " + observers.size() + " directories.", Log.DEBUGMSG); try {// w w w .ja v a 2s . co m monitor.start(); } catch (Exception e) { logger.log(e.getMessage(), Log.INFOS); } // Need to iterate through all registered directories for (File directory : directories) { LinkedList<File> files = (LinkedList<File>) FileUtils.listFiles(directory, null, false); Collections.sort(files, new DateTimeAscending()); for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) { File file = (File) iterator.next(); processFile(file); } } }
From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java
/** * Gets a set of boxes which covers all and only the pixels covered by * <code>A</code> and <code>B</code>. * /* www .j a va2s .co m*/ * @param A * a set of boxes to union with * @param B * a set of boxes to union with * @return a set of boxes corresponding to the region shared by A and B */ public static BoundingBox union(BoundingBox A, BoundingBox B) { BoundingBox temp = new BoundingBox(); LinkedList aList; temp.composed = true; int x = Math.min(A.rect.x, B.rect.x); int y = Math.min(A.rect.y, B.rect.y); int x2 = Math.max(A.rect.x + A.rect.width, B.rect.x + B.rect.width); int y2 = Math.max(A.rect.y + A.rect.height, B.rect.y + B.rect.height); temp.rect = new Rectangle(x, y, x2, y2); if (A.composed) aList = (LinkedList) A.pieces.clone(); else { aList = new LinkedList(); aList.add(A); } if (B.composed) temp = B.copy(); else { temp.pieces = new LinkedList(); temp.pieces.add(B.copy()); temp.composed = true; } ListIterator iter = aList.listIterator(0); while (iter.hasNext()) { BoundingBox child = (BoundingBox) iter.next(); Iterator ti = temp.pieces.iterator(); LinkedList childRemains = null; /* remove an offending piece of the child */ while (ti.hasNext() && (null == (childRemains = ((BoundingBox) ti.next()).subtractFrom(child)))) ; /* * Add the broken pieces into the list and break back to top loop * remove the offending rectangle and replace it with its shards, * then clean up those. */ if (childRemains != null) { ti = childRemains.iterator(); iter.remove(); while (ti.hasNext()) { iter.add(ti.next()); iter.previous(); } } } temp.pieces.addAll(aList); temp.simplify(); return (temp); }
From source file:it.intecs.pisa.develenv.model.launch.ToolboxScriptRunLaunch.java
protected static boolean checkIfDeployed(IProject project, String serviceName, String operationName) { HttpClient client;// ww w . j a v a 2 s.c o m GetMethod method; int statusCode; DOMUtil util; Document doc; Element root; Element ithServiceTag; Element ithOperationTag; Iterator serviceIterator; Iterator operationIterator; LinkedList serviceTags; LinkedList operationTags; String url; util = new DOMUtil(); client = new HttpClient(); url = ToolboxEclipseProjectPreferences.getToolboxHostURL(project); url += "/manager?cmd=GetServiceList"; method = new GetMethod(url); try { statusCode = client.executeMethod(method); if (statusCode != 200) return false; InputStream serviceList; serviceList = method.getResponseBodyAsStream(); doc = util.inputStreamToDocument(serviceList); root = doc.getDocumentElement(); serviceTags = util.getChildren(root); serviceIterator = serviceTags.iterator(); while (serviceIterator.hasNext()) { ithServiceTag = (Element) serviceIterator.next(); if (ithServiceTag.getAttribute("name").equals(serviceName)) { operationTags = util.getChildren(ithServiceTag); operationIterator = operationTags.iterator(); while (operationIterator.hasNext()) { ithOperationTag = (Element) operationIterator.next(); if (ithOperationTag.getAttribute("name").equals(operationName)) return true; } } } return false; } catch (Exception e) { return false; } }
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 *///w w w.j a v a 2s .c om 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:edu.cmu.sphinx.speakerid.SpeakerIdentification.java
/** * @param features The feature vectors to be used for clustering * @return A cluster for each speaker detected based on the feature vectors provided *//*from w w w .j ava 2s . c om*/ public ArrayList<SpeakerCluster> cluster(ArrayList<float[]> features) { ArrayList<SpeakerCluster> ret = new ArrayList<SpeakerCluster>(); Array2DRowRealMatrix featuresMatrix = ArrayToRealMatrix(features, features.size()); LinkedList<Integer> l = getAllChangingPoints(featuresMatrix); Iterator<Integer> it = l.iterator(); int curent, previous = it.next(); while (it.hasNext()) { curent = it.next(); Segment s = new Segment(previous * Segment.FRAME_LENGTH, (curent - previous) * (Segment.FRAME_LENGTH)); Array2DRowRealMatrix featuresSubset = (Array2DRowRealMatrix) featuresMatrix.getSubMatrix(previous, curent - 1, 0, 12); ret.add(new SpeakerCluster(s, featuresSubset, getBICValue(featuresSubset))); previous = curent; } int clusterCount = ret.size(); Array2DRowRealMatrix distance; distance = new Array2DRowRealMatrix(clusterCount, clusterCount); distance = updateDistances(ret); while (true) { double distmin = 0; int imin = -1, jmin = -1; for (int i = 0; i < clusterCount; i++) for (int j = 0; j < clusterCount; j++) if (i != j) distmin += distance.getEntry(i, j); distmin /= (clusterCount * (clusterCount - 1) * 4); for (int i = 0; i < clusterCount; i++) { for (int j = 0; j < clusterCount; j++) { if (distance.getEntry(i, j) < distmin && i != j) { distmin = distance.getEntry(i, j); imin = i; jmin = j; } } } if (imin == -1) { break; } ret.get(imin).mergeWith(ret.get(jmin)); updateDistances(ret, imin, jmin, distance); ret.remove(jmin); clusterCount--; } return ret; }
From source file:WaitSemaphore.java
protected void logDeadlock() { System.err.println();//from w w w . jav a 2 s.c o m System.err.println("DEADLOCK ON SEMAPHORE " + this); if (m_debug) { for (Iterator i = m_logMap.values().iterator(); i.hasNext();) { LinkedList list = (LinkedList) i.next(); for (Iterator iter = list.iterator(); iter.hasNext();) { System.err.println(iter.next()); } } } System.err.println(); }
From source file:org.archive.crawler.framework.CheckpointService.java
/** * Returns a list of available, valid (contains 'valid' file) * checkpoint directories, as File instances, with the more * recently-written appearing first. /*from w ww .jav a 2s .c o m*/ * * @return List of valid checkpoint directory File instances */ @SuppressWarnings("unchecked") public List<File> findAvailableCheckpointDirectories() { File[] dirs = getCheckpointsDir().getFile().listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); if (dirs == null) { return Collections.EMPTY_LIST; } Arrays.sort(dirs, LastModifiedFileComparator.LASTMODIFIED_REVERSE); LinkedList<File> dirsList = new LinkedList<File>(Arrays.asList(dirs)); Iterator<File> iter = dirsList.iterator(); while (iter.hasNext()) { File cpDir = iter.next(); if (!Checkpoint.hasValidStamp(cpDir)) { LOGGER.warning("checkpoint '" + cpDir + "' missing validity stamp file; ignoring"); iter.remove(); } } return dirsList; }
From source file:com.asakusafw.runtime.stage.launcher.LauncherOptionsParser.java
private List<String> consumeLibraryNames(LinkedList<String> rest) { List<String> results = new ArrayList<>(); for (Iterator<String> iter = rest.iterator(); iter.hasNext();) { String token = iter.next(); if (token.equals(KEY_ARG_LIBRARIES)) { iter.remove();//from ww w. ja va2s . co m if (iter.hasNext()) { String libraries = iter.next(); iter.remove(); for (String library : libraries.split(",")) { //$NON-NLS-1$ String path = library.trim(); if (path.isEmpty() == false) { results.add(path); } } } } } return results; }
From source file:com.alta189.cyborg.api.plugin.CommonPluginManager.java
public synchronized Plugin[] loadPlugins(File paramFile) { if (!paramFile.isDirectory()) { throw new IllegalArgumentException("File parameter was not a Directory!"); }// w ww . j a va 2 s .c o m if (cyborg.getUpdateFolder() != null) { updateDir = cyborg.getUpdateFolder(); } List<Plugin> result = new ArrayList<Plugin>(); LinkedList<File> files = new LinkedList<File>(Arrays.asList(paramFile.listFiles())); boolean failed = false; boolean lastPass = false; while (!failed || lastPass) { failed = true; Iterator<File> iterator = files.iterator(); while (iterator.hasNext()) { File file = iterator.next(); Plugin plugin = null; if (file.isDirectory()) { iterator.remove(); continue; } try { plugin = loadPlugin(file, lastPass); iterator.remove(); } catch (UnknownDependencyException e) { if (lastPass) { CyborgLogger.getLogger().log(Level.SEVERE, new StringBuilder().append("Unable to load '").append(file.getName()) .append("' in directory '").append(paramFile.getPath()).append("': ") .append(e.getMessage()).toString(), e); iterator.remove(); } else { plugin = null; } } catch (InvalidDescriptionFileException e) { CyborgLogger.getLogger().log(Level.SEVERE, new StringBuilder().append("Unable to load '").append(file.getName()) .append("' in directory '").append(paramFile.getPath()).append("': ") .append(e.getMessage()).toString(), e); iterator.remove(); } catch (InvalidPluginException e) { CyborgLogger.getLogger().log(Level.SEVERE, new StringBuilder().append("Unable to load '").append(file.getName()) .append("' in directory '").append(paramFile.getPath()).append("': ") .append(e.getMessage()).toString(), e); iterator.remove(); } if (plugin != null) { result.add(plugin); failed = false; lastPass = false; } } if (lastPass) { break; } else if (failed) { lastPass = true; } } return result.toArray(new Plugin[result.size()]); }
From source file:com.alta189.chavabot.plugin.CommonPluginManager.java
public synchronized Plugin[] loadPlugins(File paramFile) { if (!paramFile.isDirectory()) throw new IllegalArgumentException("File parameter was not a Directory!"); if (chavamanager.getUpdateFolder() != null) { updateDir = chavamanager.getUpdateFolder(); }/*from w ww .j a v a 2 s .com*/ List<Plugin> result = new ArrayList<Plugin>(); LinkedList<File> files = new LinkedList<File>(Arrays.asList(paramFile.listFiles())); boolean failed = false; boolean lastPass = false; while (!failed || lastPass) { failed = true; Iterator<File> iterator = files.iterator(); while (iterator.hasNext()) { File file = iterator.next(); Plugin plugin = null; if (file.isDirectory()) { iterator.remove(); continue; } try { plugin = loadPlugin(file, lastPass); iterator.remove(); } catch (UnknownDependencyException e) { if (lastPass) { chavamanager.getLogger().log(Level.SEVERE, new StringBuilder().append("Unable to load '").append(file.getName()) .append("' in directory '").append(paramFile.getPath()).append("': ") .append(e.getMessage()).toString(), e); iterator.remove(); } else { plugin = null; } } catch (InvalidDescriptionFileException e) { chavamanager.getLogger().log(Level.SEVERE, new StringBuilder().append("Unable to load '").append(file.getName()) .append("' in directory '").append(paramFile.getPath()).append("': ") .append(e.getMessage()).toString(), e); iterator.remove(); } catch (InvalidPluginException e) { chavamanager.getLogger().log(Level.SEVERE, new StringBuilder().append("Unable to load '").append(file.getName()) .append("' in directory '").append(paramFile.getPath()).append("': ") .append(e.getMessage()).toString(), e); iterator.remove(); } if (plugin != null) { result.add(plugin); failed = false; lastPass = false; } } if (lastPass) { break; } else if (failed) { lastPass = true; } } return result.toArray(new Plugin[result.size()]); }