List of usage examples for java.util LinkedList isEmpty
boolean isEmpty();
From source file:com.rapidminer.operator.preprocessing.discretization.MinimalEntropyDiscretization.java
private ArrayList<Double> getSplitpoints(LinkedList<double[]> startPartition, Attribute label) { LinkedList<LinkedList<double[]>> border = new LinkedList<LinkedList<double[]>>(); ArrayList<Double> result = new ArrayList<Double>(); border.addLast(startPartition);//from w w w.j ava 2 s. c o m while (!border.isEmpty()) { LinkedList<double[]> currentPartition = border.removeFirst(); Double splitpoint = this.getMinEntropySplitpoint(currentPartition, label); if (splitpoint != null) { result.add(splitpoint); double splitValue = splitpoint.doubleValue(); LinkedList<double[]> newPartition1 = new LinkedList<double[]>(); LinkedList<double[]> newPartition2 = new LinkedList<double[]>(); Iterator<double[]> it = currentPartition.iterator(); while (it.hasNext()) { // Create new partitions. double[] attributeLabelPair = it.next(); if (attributeLabelPair[0] <= splitValue) { newPartition1.addLast(attributeLabelPair); } else { newPartition2.addLast(attributeLabelPair); } } border.addLast(newPartition1); border.addLast(newPartition2); } } return result; // Empty ArrayList if no Splitpoint could be found. }
From source file:org.mycard.net.network.Connection.java
/*** * After a send/receive failure, any pipelined requests must be * cleared back to the mRequest queue//from ww w. j av a2s . c o m * @return true if mRequests is empty after pipe cleared */ private boolean clearPipe(LinkedList<Request> pipe) { boolean empty = true; synchronized (mRequestFeeder) { Request tReq; while (!pipe.isEmpty()) { tReq = (Request) pipe.removeLast(); mRequestFeeder.requeueRequest(tReq); empty = false; } if (empty) empty = !mRequestFeeder.haveRequest(mHost); } return empty; }
From source file:gov.nih.nci.ncicb.cadsr.ocbrowser.struts.actions.ObjectClassRelationshipAction.java
/** * * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * * @return/*from w w w. ja v a2 s.c o m*/ * * @throws IOException * @throws ServletException */ public ActionForward navigateOCR(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { DynaActionForm dynaForm = (DynaActionForm) form; String obcIdSeq = (String) dynaForm.get(OC_IDSEQ); String ocrIndex = (String) dynaForm.get(OCR_INDEX); String direction = (String) dynaForm.get(OCR_DIRECTION); Integer crumbsIndex = (Integer) dynaForm.get(OCR_BR_CRUMBS_INDEX); if (log.isDebugEnabled()) { log.info("ocr for With object class " + obcIdSeq); log.info("ocr index " + ocrIndex); log.info("direction " + direction); } try { //Get ocr navigation crumbs LinkedList crumbs = (LinkedList) getSessionObject(request, OCR_NAVIGATION_BEAN); if (crumbs == null) { crumbs = new LinkedList(); setSessionObject(request, OCR_NAVIGATION_BEAN, crumbs, true); } if (crumbs.isEmpty()) { OCRNavigationBean bean = new OCRNavigationBean(); ObjectClass currObjectClass = (ObjectClass) getSessionObject(request, OBJECT_CLASS); bean.setObjectClass(currObjectClass); crumbs.add(bean); } else { //Set the OCR_NAVIGATION_BEAN to current navigation path int currSize = crumbs.size(); int currIndex = crumbsIndex.intValue(); boolean nodesRemoved = false; for (int i = currIndex; i < currSize - 1; ++i) { crumbs.removeLast(); nodesRemoved = true; } if (nodesRemoved) { OCRNavigationBean newLastNavBean = (OCRNavigationBean) crumbs.getLast(); newLastNavBean.setOcr(null); newLastNavBean.setShowDirection(false); } } OCRNavigationBean lastNavBean = (OCRNavigationBean) crumbs.getLast(); //Make sure same object is not navigated // need review if (lastNavBean.getObjectClass().getId() != obcIdSeq) { //get the list of ocrs depending on the direction clicked List oldList = (List) getSessionObject(request, direction); ObjectClassRelationship navigatedOCR = (ObjectClassRelationship) oldList .get(Integer.parseInt(ocrIndex)); OCBrowserService service = this.getApplicationServiceLocator().findOCBrowserService(); ObjectClass objClass = service.getObjectClass(obcIdSeq); List ocrs = service.getAssociationsForOC(obcIdSeq); //Set the current OCRID dynaForm.set(CURR_OCR_IDSEQ, navigatedOCR.getId()); Map ocrMap = OCUtils.sortByOCRTypes(ocrs, obcIdSeq); setSessionObject(request, OBJECT_CLASS, objClass, true); setSessionObject(request, OUT_GOING_OCRS, ocrMap.get(OUT_GOING_OCRS), true); setSessionObject(request, IN_COMMING_OCRS, ocrMap.get(IN_COMMING_OCRS), true); setSessionObject(request, BIDIRECTIONAL_OCRS, ocrMap.get(BIDIRECTIONAL_OCRS), true); //Update old bean lastNavBean.setOcr(navigatedOCR); lastNavBean.setDirection(direction); lastNavBean.setShowDirection(true); //Add new link OCRNavigationBean bean = new OCRNavigationBean(); bean.setObjectClass(objClass); crumbs.add(bean); //set the crumbs index dynaForm.set(OCR_BR_CRUMBS_INDEX, new Integer(crumbs.size() - 1)); } } catch (ServiceLocatorException exp) { if (log.isErrorEnabled()) { log.error("Exception on getObjectClassRelationships obid= " + obcIdSeq); } return mapping.findForward(FAILURE); } return mapping.findForward(SUCCESS); }
From source file:org.mycard.net.network.RequestQueue.java
/** helper */ private Request removeFirst(LinkedHashMap<HttpHost, LinkedList<Request>> requestQueue) { Request ret = null;/* w w w . ja va 2 s . co m*/ Iterator<Map.Entry<HttpHost, LinkedList<Request>>> iter = requestQueue.entrySet().iterator(); if (iter.hasNext()) { Map.Entry<HttpHost, LinkedList<Request>> entry = iter.next(); LinkedList<Request> reqList = entry.getValue(); ret = reqList.removeFirst(); if (reqList.isEmpty()) { requestQueue.remove(entry.getKey()); } } return ret; }
From source file:org.mycard.net.network.RequestQueue.java
/*** * @return a request for given host if possible *///from w w w . jav a2s . c o m public synchronized Request getRequest(HttpHost host) { Request ret = null; if (mPending.containsKey(host)) { LinkedList<Request> reqList = mPending.get(host); ret = reqList.removeFirst(); if (reqList.isEmpty()) { mPending.remove(host); } } //if (HttpLog.LOGV) HttpLog.v("RequestQueue.getRequest(" + host + ") => " + ret); return ret; }
From source file:org.apache.camel.impl.MainSupport.java
/** * Parses the command line arguments/*from w ww. jav a 2 s. c o m*/ */ public void parseArguments(String[] arguments) { LinkedList<String> args = new LinkedList<String>(Arrays.asList(arguments)); boolean valid = true; while (!args.isEmpty()) { String arg = args.removeFirst(); boolean handled = false; for (Option option : options) { if (option.processOption(arg, args)) { handled = true; break; } } if (!handled) { System.out.println("Unknown option: " + arg); System.out.println(); valid = false; break; } } if (!valid) { showOptions(); completed(); } }
From source file:ml.dmlc.xgboost4j.java.NativeLibraryLoaderChain.java
@Override public void loadNativeLibs() throws IOException { LinkedList<IOException> exs = new LinkedList<>(); for (NativeLibrary lib : nativeLibs) { try {/* w ww . ja va 2 s . com*/ // Try to load if (lib.load()) { // It was successful load, so remember it successfullyLoaded = lib; break; } } catch (IOException e) { logger.info("Cannot load library: " + lib.toString()); exs.add(e); } } if ((successfullyLoaded == null) && (!exs.isEmpty())) { throw new IOException(exs.getLast()); } }
From source file:org.nuxeo.ecm.platform.routing.core.impl.GraphRunner.java
protected void recursiveCancelInput(GraphRoute graph, GraphNode originalNode, LinkedList<GraphNode> pendingNodes) { LinkedList<GraphNode> todo = new LinkedList<GraphNode>(); todo.add(originalNode);/* w w w. ja v a 2 s. c o m*/ Set<String> done = new HashSet<String>(); while (!todo.isEmpty()) { GraphNode node = todo.pop(); done.add(node.getId()); for (Transition t : node.getInputTransitions()) { if (t.loop) { // don't recurse through loop transitions continue; } GraphNode source = t.source; if (done.contains(source.getId())) { // looping somewhere TODO check it's not happening continue; } source.setCanceled(); State state = source.getState(); source.setState(State.READY); pendingNodes.remove(node); if (state == State.SUSPENDED) { // we're suspended on a task, cancel it and stop recursion source.cancelTasks(); } else { // else recurse todo.add(source); } } } }
From source file:org.eclipse.scada.configuration.recipe.lib.internal.DefaultExecutableFactory.java
private Method gatherMethods(final Class<?> clazz, final String methodName) { final LinkedList<Method> methods = new LinkedList<>(); for (final Method m : clazz.getMethods()) { if (m.getName().equals(methodName)) { methods.add(m);//from w w w . j a v a 2 s. c o m } } if (methods.size() == 1) { return methods.peek(); } else if (methods.isEmpty()) { throw new IllegalStateException( String.format("Method '%s' not found on class '%s'", methodName, clazz.getName())); } else { throw new IllegalStateException(String.format( "Method '%s' of class '%s' is polymorphic. This is now allowed for the recipe target classes.", methodName, clazz.getName())); } }
From source file:com.tulskiy.musique.library.Library.java
public void rescan(Map<String, Object> progress) { List<String> folders = LibraryConfiguration.getFolders(); if (CollectionUtils.isEmpty(folders)) { return;/*w ww . ja v a 2 s. co m*/ } progress.put("processing.file", ""); data.removeDeadItems(); HashMap<TrackData, Track> trackDatas = new HashMap<TrackData, Track>(); for (Track track : data) { trackDatas.put(track.getTrackData(), track); } LinkedList<File> queue = new LinkedList<File>(); for (String path : folders) { File f = new File(path); if (f.exists()) queue.add(f); } HashSet<Track> processed = new HashSet<Track>(); final Set<String> formats = Codecs.getFormats(); ArrayList<Track> temp = new ArrayList<Track>(); while (!queue.isEmpty()) { try { File file = queue.pop(); if (progress != null) { if (progress.get("processing.stop") != null) { break; } progress.put("processing.file", file.getAbsolutePath()); } if (file.isDirectory()) { queue.addAll(0, Arrays.asList(file.listFiles(new FileFilter() { @Override public boolean accept(File file) { if (file.isHidden() || !file.canRead()) { return false; } if (file.isDirectory()) return true; String ext = Util.getFileExt(file).toLowerCase(); if (formats.contains(ext)) { String name = Util.removeExt(file.getAbsolutePath()) + ".cue"; return !new File(name).exists(); } return ext.equals("cue"); } }))); } else { TrackData trackData = new TrackData(file.toURI(), 0); Track track = trackDatas.get(trackData); if (track != null) { if (track.getTrackData().getLastModified() != file.lastModified()) { track.getTrackData().clearTags(); TrackIO.getAudioFileReader(file.getName()).reload(track); } processed.add(track); } else { temp.clear(); TrackIO.getAudioFileReader(file.getName()).read(file, temp); for (Track newTrack : temp) { trackData = newTrack.getTrackData(); if (trackDatas.containsKey(trackData)) { // it must be the cue file, so merge the track data trackData.merge(newTrack.getTrackData()); } processed.add(newTrack); } } } } catch (Exception e) { e.printStackTrace(); } } data.clear(); data.addAll(processed); processed.clear(); trackDatas.clear(); rebuildTree(); }